Skip to content

Instantly share code, notes, and snippets.

View prohazko2's full-sized avatar

prohazko prohazko2

View GitHub Profile
@prohazko2
prohazko2 / main.py
Last active September 13, 2022 15:26
otus-2021-10-lab27: fastapi example
# > 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()
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):
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;
/*
* 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>
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());
@prohazko2
prohazko2 / main.cpp
Last active June 25, 2021 17:56
ESP8266 Local HTTP Arduino OTA Update
/**
!!! 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>
console.log("init");
const WIFI_SSID = "...";
const WIFI_PASS = "...";
const MQTT_CLIENT_ID = "...";
const MQTT_HOST = "dev.rightech.io";
let mqtt;
@prohazko2
prohazko2 / ric-handler-global.d.ts
Last active March 3, 2021 19:27
Rightech IoT handler global var
declare var ric: {
events: {
gen<T>(event: string, payload?: T): void;
};
base64: {
decode(payload: string): DataView;
};
localStore: {
forObject: RicLocalStore;
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
// 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