This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # > pip install uvicorn fastapi tinydb | |
| # > python -m uvicorn main:app --port 8000 | |
| from fastapi import FastAPI, Request, Query, HTTPException | |
| from tinydb import TinyDB, Query | |
| items = TinyDB('db.json').table('items') | |
| app = FastAPI() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import uniform | |
| from threading import Timer | |
| import paho.mqtt.client as mqtt | |
| def on_connect(client, userdata, flags, rc): | |
| print("on_connect rc: [%d]" % (rc)) | |
| def on_disconnect(client, userdata, rc): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EVENT_PACKET = 1; | |
| const EVENT_ALARM = 2; | |
| /** | |
| * Check if n-th bit set for number | |
| * @param value {number} number value | |
| * @param bit {number} bit position | |
| */ | |
| function bit(value, bit) { | |
| return (value & (1 << bit)) !== 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * from: https://github.com/marvinroger/async-mqtt-client/blob/v0.9.0/examples/FullyFeatured-ESP8266/FullyFeatured-ESP8266.ino | |
| */ | |
| /* | |
| platform = espressif8266 | |
| lib_deps = marvinroger/AsyncMqttClient@^0.9.0 | |
| */ | |
| #include <ESP8266WiFi.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const DAY_START = [0, 0, 0, 0]; | |
| const DAY_END = [23, 59, 59, 999]; | |
| const TZ_OFFSET = 3 * 60 * 60 * 1000; | |
| const INIT_WITH = 230; | |
| const TICK_VALUE = 10; | |
| function startOfMinute(date) { | |
| date = new Date(date || Date.now()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| !!! Should only be used in local trusted network | |
| !!! Do not go outside without WiFiClientSecure and TLS | |
| Based on: | |
| https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino | |
| */ | |
| #include <ESP8266WiFi.h> | |
| #include <ESP8266mDNS.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log("init"); | |
| const WIFI_SSID = "..."; | |
| const WIFI_PASS = "..."; | |
| const MQTT_CLIENT_ID = "..."; | |
| const MQTT_HOST = "dev.rightech.io"; | |
| let mqtt; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare var ric: { | |
| events: { | |
| gen<T>(event: string, payload?: T): void; | |
| }; | |
| base64: { | |
| decode(payload: string): DataView; | |
| }; | |
| localStore: { | |
| forObject: RicLocalStore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| mqtt "github.com/eclipse/paho.mqtt.golang" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // original HTTP over TLS (HTTPS) example sketch from: | |
| // https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino | |
| /*** platformio.ini | |
| [env:nodemcuv2] | |
| platform = espressif8266 | |
| board = nodemcuv2 | |
| framework = arduino | |
| lib_deps = knolleary/PubSubClient@^2.8.0 |
NewerOlder