Added dashboard
This commit is contained in:
parent
1d4e24fa0e
commit
205e8a1c49
@ -18,6 +18,7 @@ board_build.partitions = no_ota.csv
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
|
ESP-DASH
|
||||||
ArduinoJson
|
ArduinoJson
|
||||||
BH1750
|
BH1750
|
||||||
Adafruit Unified Sensor
|
Adafruit Unified Sensor
|
||||||
|
25
src/main.cpp
25
src/main.cpp
@ -5,6 +5,7 @@
|
|||||||
#include <DHT_U.h>
|
#include <DHT_U.h>
|
||||||
#include <IotWebConf.h>
|
#include <IotWebConf.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <ESPDash.h>
|
||||||
|
|
||||||
#define I2C_SDA 25
|
#define I2C_SDA 25
|
||||||
#define I2C_SCL 26
|
#define I2C_SCL 26
|
||||||
@ -116,16 +117,26 @@ void setup()
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("Starting up...");
|
Serial.println("Starting up...");
|
||||||
|
|
||||||
|
// Init IotWebConf
|
||||||
iotWebConf.setWifiConnectionCallback(&wifiConnected);
|
iotWebConf.setWifiConnectionCallback(&wifiConnected);
|
||||||
iotWebConf.init();
|
iotWebConf.init();
|
||||||
iotWebConf.doLoop();
|
iotWebConf.doLoop();
|
||||||
|
|
||||||
server.on("/", HTTP_GET, handleRoot);
|
// Init WebServer
|
||||||
server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request) { iotWebConf.handleConfig(request); });
|
server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request) { iotWebConf.handleConfig(request); });
|
||||||
server.on("/values", HTTP_GET, handleValues);
|
server.on("/values", HTTP_GET, handleValues);
|
||||||
server.onNotFound([](AsyncWebServerRequest *request) { iotWebConf.handleNotFound(request); });
|
server.onNotFound([](AsyncWebServerRequest *request) { iotWebConf.handleNotFound(request); });
|
||||||
server.begin();
|
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);
|
Wire.begin(I2C_SDA, I2C_SCL);
|
||||||
dht.begin();
|
dht.begin();
|
||||||
|
|
||||||
@ -175,6 +186,18 @@ void loop()
|
|||||||
// Read battery
|
// Read battery
|
||||||
bat = readBattery();
|
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",
|
Serial.printf("DHTT:%.2f H:%.2f Lux:%.2f Soil:%u Salt:%u Bat:%.2f\n",
|
||||||
temperature, humidity, lux, soil, salt, bat);
|
temperature, humidity, lux, soil, salt, bat);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user