diff --git a/platformio.ini b/platformio.ini index b53f8a0..8c0c2de 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,6 +18,7 @@ board_build.partitions = no_ota.csv lib_deps = ESPAsyncTCP ESP Async WebServer + ESP-DASH ArduinoJson BH1750 Adafruit Unified Sensor diff --git a/src/main.cpp b/src/main.cpp index 69413e5..7d1ef7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #define I2C_SDA 25 #define I2C_SCL 26 @@ -116,16 +117,26 @@ void setup() Serial.println(); Serial.println("Starting up..."); + // Init IotWebConf iotWebConf.setWifiConnectionCallback(&wifiConnected); iotWebConf.init(); iotWebConf.doLoop(); - server.on("/", HTTP_GET, handleRoot); + // Init WebServer server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request) { iotWebConf.handleConfig(request); }); server.on("/values", HTTP_GET, handleValues); server.onNotFound([](AsyncWebServerRequest *request) { iotWebConf.handleNotFound(request); }); server.begin(); + // Init Dashboard + ESPDash.init(server); + ESPDash.addTemperatureCard("temp", "Temperature/C", 0, 0); + ESPDash.addHumidityCard("hum", "Humidity/%", 0); + ESPDash.addNumberCard("lux", "BH1750/lx", 0); + ESPDash.addHumidityCard("soil", "Soil", 0); + ESPDash.addNumberCard("salt", "Salt", 0); + ESPDash.addNumberCard("batt", "Battery/mV", 0); + Wire.begin(I2C_SDA, I2C_SCL); dht.begin(); @@ -175,6 +186,18 @@ void loop() // Read battery bat = readBattery(); + // Update Dashboard + if (!isnan(temperature)) { + ESPDash.updateTemperatureCard("temp", (int)temperature); + } + if (!isnan(humidity)) { + ESPDash.updateHumidityCard("hum", (int)humidity); + } + ESPDash.updateNumberCard("lux", (int)lux); + ESPDash.updateHumidityCard("soil", (int)soil); + ESPDash.updateNumberCard("salt", (int)salt); + ESPDash.updateNumberCard("batt", (int)bat); + Serial.printf("DHTT:%.2f H:%.2f Lux:%.2f Soil:%u Salt:%u Bat:%.2f\n", temperature, humidity, lux, soil, salt, bat); }