Skip to content

Instantly share code, notes, and snippets.

View ma2shita's full-sized avatar

Kohei MATSUSHITA ma2shita

View GitHub Profile
@ma2shita
ma2shita / generate_jwt_for_gcp_iot_core.py
Created July 25, 2019 04:56
Generate JWT for Google IoT Core's Client
#!/usr/bin/env python
# fork from https://github.com/Nilhcem/esp32-cloud-iot-core-k8s/blob/master/04-generate-jwt/main.py
from optparse import OptionParser
import datetime
import jwt
import sys
def create_jwt(project_id, private_key_file, algorithm):
@ma2shita
ma2shita / switchbot.py
Last active August 12, 2019 01:18
Operation for SwitchBot (using Pyhton3)
#!/usr/bin/env python3
import binascii
from bluepy.btle import Peripheral
class SwitchBot:
def __init__(self, mac_address):
self.p = Peripheral(mac_address, "random")
hand_service = self.p.getServiceByUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b")
self.hand = hand_service.getCharacteristics("cba20002-224d-11e6-9fb8-0002a5d5c51b")[0]
@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>
@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_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 / 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)
"""
[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}
"""
[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}
@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"
@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]