UPDATE: AccessPoint on Arduino implemented with captive portal for Wifi Configuration
Got my Waveshare Epaper Cloud running on ESPHome
This is a Epaper display with a 2000mAh Lipo and a passive buzzer. Running parts of my Smoker monitor.
Below a little movie clip with RTTTL sound notification. (Send from Home Assistant) B.t.w. RTTTL are those ringtones we used to have. (Ring Tone Text Transfer Language)
Sending from HA
Parts of the ESPHOME Yaml NOTE: For the time, you need the time integration to get hours:minutes as a sensor!
This is part of a test where my friends and me can have notifications LEDs over the internet.
Using certificate parts from: Controlling the led will be done using Mattermost webhooks, or slashcommand with custom scripting. (Mattermost is my own hosted chat server)
I flashed a Wemos with below code: (Rotary/display/button part removed.)
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
#define encoderCLK 5 //D1
#define encoderDT 4 //D2
#define rgbled D4 //D4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, rgbled, NEO_RGB + NEO_KHZ400);
int servoAngle = 0;
int crntCLK;
int prvsCLK;
String myString;
char ang[50];
#ifndef SECRET
const char ssid[] = "MYSSID";
const char pass[] = "MYPASS";
#define HOSTNAME "henrimqtt"
const char MQTT_HOST[] = "www.henriaanstoot.nl";
const int MQTT_PORT = 9883;
const char MQTT_USER[] = "xxxxxx"; // leave blank if no credentials used
const char MQTT_PASS[] = "xxxxxx"; // leave blank if no credentials used
const char MQTT_SUB_TOPIC[] = "notification/" HOSTNAME "/in";
const char MQTT_PUB_TOPIC[] = "notification/" HOSTNAME "/out";
const char MQTT_PUB_TOPIC_angle[] = "notification/" HOSTNAME "/send";
#ifdef CHECK_CA_ROOT
static const char digicert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIFtTCCA52gAwIBAgIUXEEQRLHhYox8a95YiAYX/wQ/XeMwDQYJKoZIhvcNAQEN
//--------------- SNIP SNIP ... generated cert here
vht8GyCCgCH55Syvy9ls6gCyLjTT2rtllw==
-----END CERTIFICATE-----
)EOF";
#endif
#ifdef CHECK_PUB_KEY
// Extracted by: openssl x509 -pubkey -noout -in ca.crt
static const char pubkey[] PROGMEM = R"KEY(
-----BEGIN PUBLIC KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx
-----END PUBLIC KEY-----
)KEY";
#endif
#ifdef CHECK_FINGERPRINT
// Extracted by: openssl x509 -fingerprint -in ca.crt
static const char fp[] PROGMEM = "AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD";
#endif
#endif
//////////////////////////////////////////////////////
#if (defined(CHECK_PUB_KEY) and defined(CHECK_CA_ROOT)) or (defined(CHECK_PUB_KEY) and defined(CHECK_FINGERPRINT)) or (defined(CHECK_FINGERPRINT) and defined(CHECK_CA_ROOT)) or (defined(CHECK_PUB_KEY) and defined(CHECK_CA_ROOT) and defined(CHECK_FINGERPRINT))
#error "cant have both CHECK_CA_ROOT and CHECK_PUB_KEY enabled"
#endif
BearSSL::WiFiClientSecure net;
PubSubClient client(net);
time_t now;
unsigned long lastMillis = 0;
void mqtt_connect()
{
while (!client.connected()) {
Serial.print("Time: ");
Serial.print(ctime(&now));
Serial.print("MQTT connecting ... ");
if (client.connect(HOSTNAME, MQTT_USER, MQTT_PASS)) {
Serial.println("connected.");
client.subscribe(MQTT_SUB_TOPIC);
} else {
Serial.print("failed, status code =");
Serial.print(client.state());
Serial.println(". Try again in 5 seconds.");
/* Wait 5 seconds before retrying */
delay(5000);
}
}
}
void receivedCallback(char* topic, byte* payload, unsigned int length) {
// pixels.clear(); // Set all pixel colors to 'off'
Serial.print("Received [");
Serial.print(topic);
Serial.print("]: ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
if (!strncmp((char *)payload, "0", length)) {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
if (!strncmp((char *)payload, "1", length)) {
pixels.setPixelColor(0, pixels.Color(150, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
if (!strncmp((char *)payload, "2", length)) {
pixels.setPixelColor(0, pixels.Color(0, 0, 150));
pixels.show(); // Send the updated pixel colors to the hardware.
}
if (!strncmp((char *)payload, "3", length)) {
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
}
void setup()
{
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pinMode (encoderCLK,INPUT_PULLUP);
pinMode (encoderDT,INPUT_PULLUP);
prvsCLK = digitalRead(encoderCLK);
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.print("Attempting to connect to SSID: ");
Serial.print(ssid);
WiFi.hostname(HOSTNAME);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
}
Serial.println("connected!");
Serial.print("Setting time using SNTP");
configTime(1 * 3600, 0, "pool.ntp.org", "time.nist.gov");
now = time(nullptr);
while (now < 1510592825) {
delay(500);
Serial.print(".");
now = time(nullptr);
}
Serial.println("done!");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
#ifdef CHECK_CA_ROOT
BearSSL::X509List cert(digicert);
net.setTrustAnchors(&cert);
#endif
#ifdef CHECK_PUB_KEY
BearSSL::PublicKey key(pubkey);
net.setKnownKey(&key);
#endif
#ifdef CHECK_FINGERPRINT
net.setFingerprint(fp);
#endif
#if (!defined(CHECK_PUB_KEY) and !defined(CHECK_CA_ROOT) and !defined(CHECK_FINGERPRINT))
net.setInsecure();
#endif
client.setServer(MQTT_HOST, MQTT_PORT);
client.setCallback(receivedCallback);
mqtt_connect();
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
void loop()
{
crntCLK = digitalRead(encoderCLK);
if (crntCLK != prvsCLK){
// If the encoderDT state is different than the encoderCLK state then the rotary encoder is rotating counterclockwise
if (digitalRead(encoderDT) != crntCLK) {
servoAngle ++;
}
else {
servoAngle --;
}
Serial.println(servoAngle);
String myString = String(servoAngle);
myString.toCharArray(ang, myString.length() + 1);
client.publish(MQTT_PUB_TOPIC_angle, ang, false);
}
prvsCLK = crntCLK;
now = time(nullptr);
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Checking wifi");
while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
Serial.print(".");
delay(10);
}
Serial.println("connected");
}
else
{
if (!client.connected())
{
mqtt_connect();
}
else
{
client.loop();
}
}
if (millis() - lastMillis > 5000) {
lastMillis = millis();
client.publish(MQTT_PUB_TOPIC, ctime(&now), false);
}
}
Not posted in the past, new version using ESPHOME and a m5stickc
Previous version using a ESP12
A “watch” with core and environment temperature of my smoker with a alarm, and button for timers.
ESP32 dac’s drawing on oscilloscope ( no additional components)
ESP32 in front of scope, two clips for x and y
For above i used sin/cos functions 2:3, which creates Lissajous figures. See: https://www.henriaanstoot.nl/1992/01/01/oscilloscope-graphics-using-a-amiga-bonus-vectrex/
3 battery operated buttons (no wires needed) to control my shelly dimmer at the dinner table.
left button on, middle steps per 20% and 3rd button off. (This cheapass button only sends ON commands)
I made my own Mqtt to speech thingy in the past. Sending a text to a mqtt topic would be picked up by my domoticz raspberry and using a bash script the topic payload was converted to speech and being played on a connected speaker.
Posted because I could not find a good example on the interwebs.
Below creates a virtual HA button which toggles a blinking led. (button and variables are called eprint for another function, change to something meaningful. )
Home Assistant virtual mqtt switch (configuration.yml)
Example uses a shelly sensor, which has a offset mode in its new firmware. So below is not needed any more. But the example can be used for any calibration/adjustments.
I’ve put two examples in the NodeRed function
First the solution
var temperature=msg.payload.tC;
var humidity=msg.payload.tF;
// calc new offset example
// simple offset + 2.3 off real measurement
msg.payload.tC=temperature + 2.3;
// more complex example
// take two measurements (with a big difference)
msg.payload.tF=1.11 * (humidity - 1);
return msg;
First adjustment is plus or minus a value. Second is more precise when the temperature needs more adjusting
Dots on the red line are measured values Blue is how it should be
So measured was 2.8 but should be 2 And measured 14.5 but needs to be 15
slope = (14.5-2.8)/(15-2) = 0.9
To get the multiplication factor = 1/0.9 = 1.1111
=(2.8-heightadjust)*1,1111 should give us 2
2/1.1111 = 2.8 – heightadjust
1.8 = 2.8 – heightadjust = 1
So the formula is realhumid = 1,1111 * ( measuredhumid – adjust )