Skip to content

Instantly share code, notes, and snippets.

View ma2shita's full-sized avatar

Kohei MATSUSHITA ma2shita

View GitHub Profile
@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 / 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 / m5stack_informater_weather.ino
Last active July 1, 2019 01:49
Weather informater for M5Stack + 3G Ext. board
#include <M5Stack.h>
#include <string.h>
#define TINY_GSM_MODEM_UBLOX
#include <TinyGsmClient.h>
TinyGsm modem(Serial2); /* Serial2 is Modem of 3G Module */
TinyGsmClient ctx(modem);
void modem_enabler();
void print_bottom_menu();
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MQTT console for AWS IoT Core with MQTT over WebSocket</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.404.0/aws-sdk.min.js" integrity="sha256-5j5NcghceMlKBa2qXSGw6l24mOkiXOsdi9sB21pBips=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.2/mqttws31.min.js" integrity="sha256-UplsBBNj5zR16Nyo1bVLLVd0ndtLYs0A5c4WrbK/etU=" crossorigin="anonymous"></script>
<script>/* from https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/protocols.html */
/**
@ma2shita
ma2shita / awsiotcore-deviceshadow_via_soracom-beam.ino
Last active October 29, 2019 04:50
Using Device shadow of AWS IoT Core via SORACOM Beam
/*
* Copyright (c) 2019 Kohei "Max" MATSUSHITA ([email protected])
* Released under the MIT license
* https://opensource.org/licenses/mit-license.php
*/
#include <string.h>
#include <stdio.h>
#include <WioLTEforArduino.h>
WioLTE Wio;
#include <WioLTEClient.h>
@ma2shita
ma2shita / call_monitor.html
Last active February 20, 2019 18:22
See: https://qiita.com/ma2shita/items/8f1b4b12faa99dd17063 | Monitoring ThingShadow in AWS IoT Core using Websocket
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Call monitor</title>
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/vue-i18n/dist/vue-i18n.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.404.0/aws-sdk.min.js"></script>
@ma2shita
ma2shita / max1click-demo_JF2018_call.py
Last active November 7, 2018 14:25
See: https://qiita.com/ma2shita/items/8f1b4b12faa99dd17063 | SORACOM LTE-M Button (AWS IoT 1-Click) -> this function)
"""
required ENVs;
- INCOMING_WEBHOOK: Slack's Incoming Webhook URL
- PARSON_(SINGLE|DOUBLE|LONG): JSONfy String
{"name": <Display name and Thing name:String>,
"slack_id": <Slack member ID (see profile):String>}
e.g.) {"name":"max","slack_id":"UC0RVEWBZ"}
"""
import json
"""
`event` is;
{
"transition_wating_sec": <sec:Integer>,
"thing_name": <thingName:String>
}
"""
import json
import logging
"""
INPUT: API Gateway
required ENVs;
- OUTGOING_TOKEN: Slack's Outgoing Webhook Token
"""
import json
import logging
logger = logging.getLogger()
/* TemperatureAndHumidity Class for DHT11 ==== */
class TemperatureAndHumidity
{
public:
TemperatureAndHumidity(int pin);
bool Read(float* temperature, float* humidity);
private:
int _pin;
void DHT11Init(int pin);
void DHT11Start(int pin);