Skip to content

Instantly share code, notes, and snippets.

View tablatronix's full-sized avatar

Shawn A tablatronix

View GitHub Profile
@tablatronix
tablatronix / resetaction.ino
Last active July 8, 2023 13:54
example to use eeprom to store reset states to trigger an action on purposeful resets
/**
* detect mutiple resets in order to trigger events using resets or power cycles alone
* reset board within resettimeout(5000ms) after boot and do so resetcnt(4) times
* has led indicator of reset window and serial output for better clarity
*
* This is blocking using a delay for timeout, can easily be changed to use a timer
* This is not wear leveled, but you could replace with spiffs(slower), or use a ring counter to level it
* You could also add a smaller window for reset by adding a pre-delay, to prevent reduce flash writes during glitchy or fast power cycles
* either way USE WITH CAUTION as you are writing twice every time your reset or repower the board, soft resets and wdt should not trigger this however.
*
@tablatronix
tablatronix / scrolltext.cpp
Last active May 18, 2023 12:20
dirty scroll text for adafruit gfx
void scrollString(String str) {
int yoff = 1;
display.clearDisplay();
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
display.setTextSize(2);
display.setRotation(0);
int charWidth = 12; // textsize 2 @todo auto calculate charwidth from font
int pxwidth = (str.length()*charWidth)+32; // @todo get actual string pixel length, add support to gfx if needed
for (int32_t x=charWidth; x>=-pxwidth; x--) {
@tablatronix
tablatronix / wifiscan_debug.ino
Created April 8, 2016 18:08
arduino esp8266 wifiscanner with detail, rssi sorting and duplicate filtering
/*
* This sketch demonstrates how to scan WiFi networks.
* The API is almost the same as with the WiFi Shield library,
* the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"
void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
// lib A
Global Server;
void on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
server->on("/", std::bind(&myClass::handler, this, handlerArg));
void myClass::handler(bool arg){
Server->blargh();
}
@tablatronix
tablatronix / gist:1ff3262f8ab9f73af814fbd6a77fad98
Last active June 13, 2021 18:11
tasmota_restart_relay_ON
Jun 13 06:59:53 tasmota_C59B5E-7006 192.168.20.46 ESP-MQT: tele/tasmota_C59B5E/SENSOR = {"Time":"2021-06-13T06:59:52","ANALOG":{"CTEnergy":{"Energy":0.006,"Power":2068,"Voltage":230,"Current":8.992}},"DHT11":{"Temperature":23.0,"Humidity":37.0,"DewPoint":7.5},"TempUnit":"C"}
Jun 13 06:59:53 tasmota_C59B5E-7006 192.168.20.46 ESP-MQT: tele/tasmota_C59B5E/STATE = {"Time":"2021-06-13T06:59:52","Uptime":"0T00:00:11","UptimeSec":11,"Heap":28,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"leela","BSSId":"F4:92:BF:7F:35:4B","Channel":3,"RSSI":30,"Signal":-85,"LinkCount":1,"Downtime":"0T00:00:05"}}
Jun 13 06:59:51 tasmota_C59B5E-7006 192.168.20.46 ESP-APP: Boot Count 27
Jun 13 06:59:49 tasmota_C59B5E-7006 192.168.20.46 ESP-QPC: Reset
Jun 13 06:59:49 tasmota_C59B5E-7006 192.168.20.46 ESP-MQT: stat/tasmota_C59B5E/STATUS10 = {"StatusSNS":{"Time":"2021-06-13T06:59:49","ANALOG":{"CTEnergy":{"Energy":0.004,"Power":2088,"Voltage":230,"Current":9.078}},"DHT11":{"Temperature":
@tablatronix
tablatronix / esptelnetansi.ino
Created August 25, 2016 14:52
Arduino ESP8266 telnet server with some ansi experiments
/**
* Arduino ESP8266 telnet server with some ansi experiments
* @author: shawn_a
*/
#include <ESP8266WiFi.h>
#include <Arduino.h>
/* Set these to your desired AP credentials. */
const char *APssid = "ESPap";
@tablatronix
tablatronix / powerMon_VoltageOnly.ino
Created January 30, 2020 01:33 — forked from ItKindaWorks/powerMon_VoltageOnly.ino
A small Arduino program to measure AC voltage using a voltage transformer
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include "EmonLib.h" // Include Emon Library
#define VOLT_CAL 148.7
EnergyMonitor emon1; // Create an instance
void setup()
{
/*
* aw9523.c aw9523 martix key
*
* Version: v1.0.1
*
* Copyright (c) 2017 AWINIC Technology CO., LTD
*
* Author: Nick Li <liweilei@awinic.com.cn>
*
* This program is free software; you can redistribute it and/or modify it
@tablatronix
tablatronix / why.h
Last active May 4, 2019 18:30
linkerprobs
//COMPILES
#ifndef SOMEDEF
void initstuff(){
}
#endif
#ifdef SOMEDEF
void initstuff(){
}
#endif
@tablatronix
tablatronix / esp32_wifi_set_country.cpp
Last active July 2, 2018 14:42
esp32_wifi_set_country
// typedef enum {
// WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */
// WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */
// } WIFI_COUNTRY_POLICY;
// typedef struct {
// char cc[3]; /**< country code string */
// uint8_t schan; /**< start channel */
// uint8_t nchan; /**< total channel number */
// uint8_t policy; /**< country policy */