Skip to content

Instantly share code, notes, and snippets.

View ma2shita's full-sized avatar

Kohei MATSUSHITA ma2shita

View GitHub Profile
@ma2shita
ma2shita / gpio6_shooting.bash
Last active December 29, 2021 03:32
Let's try IoT Prototyping / Fixed point camera with RPi (gpio6 / implementation)
#!/bin/bash
BCM_PIN=6
trap 'exit 0' 1 2 3 15
function _gpio_read() {
# $1 = reading GPIO pin (number of BMC pin)
raspi-gpio get $1 | awk -v RS=" " -F "=" -v k="level" '$1==k {print $2}'
}
@ma2shita
ma2shita / camera_shooting.socket
Last active November 8, 2019 05:04
Let's try IoT Prototyping / Fixed point camera with RPi (camera_shooting / socket of systemd)
[Unit]
Description = Shooting camera server (listener)
[Socket]
ListenStream = 127.0.0.1:19000
Accept = yes
[Install]
WantedBy = sockets.target
@ma2shita
ma2shita / camera_shooting@.service
Last active November 8, 2019 05:04
Let's try IoT Prototyping / Fixed point camera with RPi (camera_shooting / service of systemd)
[Unit]
Description = Shooting camera server (implementation)
[Service]
ExecStart = /bin/bash /home/pi/camera_shooting.bash
StandardInput = socket
StandardOutput = journal
StandardError = journal
[Install]
@ma2shita
ma2shita / camera_shooting.bash
Last active November 7, 2019 12:58
Let's try IoT Prototyping / Fixed point camera with RPi (camera_shooting / implementation)
#!/bin/bash
echo "$0"
read LINE
if [ "$LINE" = "shooting!" ]; then
echo "Taking a Photo!"
fswebcam -q --device /dev/video0 - \
| curl -X POST -H 'Content-Type: image/jpeg' --data-binary '@-' --connect-timeout 15 harvest-files.soracom.io
fi
echo "$0 END"
"""
[Unit]
Description=Garage reporter using HTTP with SORACOM Unified Endpoint
After=network-online.target
[Service]
Type=simple
WorkingDirectory=/home/pi/switchbot
ExecStart=/home/pi/switchbot/bin/python3 -B garage_reporter_with_soracom_unified.py
ExecStop=/bin/kill -INT ${MAINPID}
"""
[Unit]
Description=SwitchBot worker using MQTT with SORACOM Beam
After=network-online.target
[Service]
Type=simple
WorkingDirectory=/home/pi/switchbot
ExecStart=/home/pi/switchbot/bin/python3 -B switchbot_worker_with_soracom_beam.py
ExecStop=/bin/kill -INT ${MAINPID}
@ma2shita
ma2shita / VL53L0X_example.py
Created November 4, 2019 03:01
VL53L0X(I2C ToF distance sensor) using on Raspberry Pi
import time
import VL53L0X
# Create a VL53L0X object
tof = VL53L0X.VL53L0X(i2c_bus=1, i2c_address=0x29)
# I2C Address can change before tof.open()
# tof.change_address(0x32)
tof.open()
# Start ranging
tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER)
@ma2shita
ma2shita / m5stack_rainradar_with_soracom_beam.ino
Last active August 23, 2019 00:01
RainRadar by YOLP for M5Stack with SORACOM Beam
/*
* Copyright (c) 2019 Kohei "Max" MATSUSHITA
* Released under the MIT license
* https://opensource.org/licenses/mit-license.php
*/
#include <M5Stack.h>
#define CONSOLE Serial
#define MODEM Serial2 /* Serial2 is Modem of 3G Module */
#include <string.h>
@ma2shita
ma2shita / m5stack_rainradar.ino
Last active March 15, 2024 09:59
RainRadar by YOLP for M5Stack
/*
* Copyright (c) 2019 Kohei "Max" MATSUSHITA
* Released under the MIT license
* https://opensource.org/licenses/mit-license.php
*/
#include <M5Stack.h>
#define CONSOLE Serial
#define MODEM Serial2 /* Serial2 is Modem of 3G Module */
#include <string.h>
@ma2shita
ma2shita / m5stack_3gextboard_worldclock.ino
Last active August 20, 2019 09:12
World Clock for M5Stack with 3G Ext. board
/*
* Copyright (c) 2019 Kohei "Max" MATSUSHITA
* Released under the MIT license
* https://opensource.org/licenses/mit-license.php
*/
#include <M5Stack.h>
#define TINY_GSM_MODEM_UBLOX
#include <TinyGsmClient.h>