Frickelt in a sensor status page.

This commit is contained in:
klaute 2018-07-11 11:49:58 +02:00
parent c16d431c89
commit 9dd90841a5
2 changed files with 43 additions and 2 deletions

View file

@ -43,6 +43,8 @@ Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
Adafruit_APDS9960 apds;
Adafruit_BME280 bme;
String localIP = "127.0.0.1";
//*************************************************************************//
void setup() {
@ -89,6 +91,8 @@ void setup() {
setupWebUpdater();
localIP = WiFi.localIP().toString();
delay(100);
digitalWrite(STATUS_LED_PIN, LOW);
@ -116,6 +120,10 @@ void loop() {
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
if (currentSensorData[SENSOR_BAT_VOLTAGE] <= 3.7)
{
ESP.deepSleep(4294967295); // battery low, shutting down
}
#ifdef DEBUG
Serial.println("");
//Serial.println("Current readings:");
@ -128,9 +136,10 @@ void loop() {
#endif
pushToInfluxDB(DEVICE_NAME, currentSensorData);
setSensorData(DEVICE_NAME, localIP, currentSensorData);
}
//ESP.deepSleep(UPDATE_INTERVAL * 1000000);
//ESP.deepSleep(DELAY_LOOP_MS * 1000); // the ESP.deepSleep requires microseconds as input, after the sleep the system will run into the setup routine
//delay(100);
delay(DELAY_LOOP_MS);

View file

@ -14,6 +14,10 @@
ESP8266WebServer httpServer(8080);
ESP8266HTTPUpdateServer httpUpdater;
String ip = "127.0.0.1";
String dev = "unknown";
float sensValues[6];
void setupWebUpdater(void)
{
#ifdef DEBUG
@ -22,6 +26,9 @@ void setupWebUpdater(void)
#endif
httpUpdater.setup(&httpServer);
httpServer.on("/", showHTMLMain); // oko specific site
httpServer.begin();
#ifdef DEBUG
@ -35,3 +42,28 @@ void doWebUpdater(void)
httpServer.handleClient();
}
void setSensorData(String device, String localip, float sensorValues[]) {
dev = device;
ip = localip;
for (uint8_t i = 0; i < 7; i++)
{
sensValues[i] = sensorValues[i];
}
}
void showHTMLMain(void) {
String message = "<html><head><title>OKO Weatherstation - " + String(dev) + "</title></head><body>"
"<br><a href=\"http://" + ip + ":8080/update\">firmware update</a><br><br>"
"<table>"
"<tr><td>temperature</td><td>" + String(sensValues[SENSOR_TEMPERATURE]) + "</td></tr>"
"<tr><td>humidity=" + String(sensValues[SENSOR_HUMIDITY]) + "</td></tr>"
"<tr><td>light=" + String(sensValues[SENSOR_LIGHT]) + "</td></tr>"
"<tr><td>windspeed=" + String(sensValues[SENSOR_WINDSPEED]) + "</td></tr>"
"<tr><td>pressure=" + String(sensValues[SENSOR_PRESSURE]) + "</td></tr>"
"<tr><td>batvoltage=" + String(sensValues[SENSOR_BAT_VOLTAGE]) + "</td></tr>";
"</table>"
"</body></html>";
httpServer.send(200, "text/html", message);
}