Added dashboard
This commit is contained in:
parent
1d4e24fa0e
commit
205e8a1c49
@ -18,6 +18,7 @@ board_build.partitions = no_ota.csv
|
||||
lib_deps =
|
||||
ESPAsyncTCP
|
||||
ESP Async WebServer
|
||||
ESP-DASH
|
||||
ArduinoJson
|
||||
BH1750
|
||||
Adafruit Unified Sensor
|
||||
|
25
src/main.cpp
25
src/main.cpp
@ -5,6 +5,7 @@
|
||||
#include <DHT_U.h>
|
||||
#include <IotWebConf.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <ESPDash.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user