SOnOff NSPanel
Table of Contents
Links
Overview Page for Sonoff NSPanel and Tasmota installation.
Starter Code Still in Progress
–
Overview Page for Sonoff NSPanel and Tasmota installation.
–
Just some Links I don’t want to forget!
–
Some testing for Savable Settings via a WebServer
// _ ___ __ _ _
// | || \ \ / / | | (_)
// | || |\ \ /\ / /__ | |__ _
// |__ _\ \/ \/ / _ \| '_ \| |
// | | \ /\ / (_) | |_) | |
// |_| \/ \/ \___/|_.__/|_|.com
//
// Import required libraries
#include
#include
#include
#include "EEPROM.h"
#include "html.h"
const char* PARAM_INPUT_1 = "output";
const char* PARAM_INPUT_2 = "state";
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
// Replaces placeholder with button section in your web page
String processor(const String& var) {
//Serial.println(var);
if (var == "BUTTONPLACEHOLDER") {
String buttons = "";
buttons += "Output - GPIO 2
";
buttons += "Output - GPIO 0
";
buttons += "Output - GPIO 4
";
return buttons;
}
return String();
}
String outputState(int output) {
if (digitalRead(output)) {
return "checked";
}
else {
return "";
}
}
void EEPROMSetup() {
// STARTING EEPROM
if (!EEPROM.begin(1000)) {
Serial.println("Failed to initialise EEPROM");
Serial.println("Restarting...");
delay(1000);
ESP.restart();
}
int address = 0;
EEPROM.writeFloat(address, 421321.134123);
address += sizeof(float);
String sentence = "I love ESP32.";
EEPROM.writeInt(address, sentence.length());
address += sizeof(int);
EEPROM.writeString(address, sentence);
address += sentence.length() + 1;
EEPROM.writeDouble(address, -123456789.123456789);
address += sizeof(double);
EEPROM.commit();
address = 0;
Serial.println(EEPROM.readFloat(address), 4);
address += sizeof(float);
int i = EEPROM.readInt(address);
Serial.println(i);
address += sizeof(int);
Serial.println(EEPROM.readString(address));
address += i + 1;
Serial.println(EEPROM.readDouble(address), 8);
address += sizeof(double);
}
void setup() {
// Serial port for debugging purposes
Serial.begin(115200);
while (!Serial) continue;
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
pinMode(4 , OUTPUT);
digitalWrite(4, LOW);
EEPROMSetup();
// Connect to Wi-Fi
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
WiFiManager wm;
//wm.resetSettings();
bool res; // WifiManager
res = wm.autoConnect("AutoConnectAP", "password"); // password protected ap
if (!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
// Print ESP Local IP Address
// Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send_P(200, "text/html", index_html, processor);
});
// Send a GET request to /update?output=&state=
server.on("/update", HTTP_GET, [] (AsyncWebServerRequest * request) {
String inputMessage1;
String inputMessage2;
// GET input1 value on /update?output=&state=
if (request->hasParam(PARAM_INPUT_1) && request->hasParam(PARAM_INPUT_2)) {
inputMessage1 = request->getParam(PARAM_INPUT_1)->value();
inputMessage2 = request->getParam(PARAM_INPUT_2)->value();
digitalWrite(inputMessage1.toInt(), inputMessage2.toInt());
}
else {
inputMessage1 = "No message sent";
inputMessage2 = "No message sent";
}
Serial.print("GPIO: ");
Serial.print(inputMessage1);
Serial.print(" - Set to: ");
Serial.println(inputMessage2);
request->send(200, "text/plain", "OK");
});
// Start server
server.begin();
}
void loop() {
}
#ifndef HTML_H
#define HTML_H
const char index_html[] PROGMEM = R"rawliteral(
ESP Web Server
ESP Wobi Web Server
%BUTTONPLACEHOLDER%
)rawliteral";
#endif
–
Some demo form Adafruit_AHTx0.h
/*
I used this code with a ESP32c3
*/
#include
Adafruit_AHTX0 aht;
// change in pins_arduino.h if you want other i2c Pins! PATH: C:\Users\:userName:\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\variants\esp32c3
// static const uint8_t SDA = 7;
// static const uint8_t SCL = 8;
Adafruit_Sensor *aht_humidity, *aht_temp;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit AHT10/AHT20 test!");
if (!aht.begin()) {
Serial.println("Failed to find AHT10/AHT20 chip");
while (1) {
delay(10);
}
}
Serial.println("AHT10/AHT20 Found!");
aht_temp = aht.getTemperatureSensor();
aht_temp->printSensorDetails();
aht_humidity = aht.getHumiditySensor();
aht_humidity->printSensorDetails();
}
void loop() {
// /* Get a new normalized sensor event */
sensors_event_t humidity;
sensors_event_t temp;
aht_humidity->getEvent(&humidity);
aht_temp->getEvent(&temp);
Serial.print("\tHumidity: \t");
Serial.print(humidity.relative_humidity);
Serial.println(" % rH");
Serial.print("\tTemperature: \t");
Serial.print(temp.temperature);
Serial.println(" degrees C");
Serial.println();
delay(1000);
}
–