Browse Source

Frickelt in a sensor status page.

klaute 2 years ago
parent
commit
9dd90841a5
2 changed files with 43 additions and 2 deletions
  1. 11
    2
      firmware/firmware.ino
  2. 32
    0
      firmware/webUpdater.ino

+ 11
- 2
firmware/firmware.ino View File

@@ -43,6 +43,8 @@ Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
43 43
 Adafruit_APDS9960 apds;
44 44
 Adafruit_BME280 bme;
45 45
 
46
+String localIP = "127.0.0.1";
47
+
46 48
 //*************************************************************************//
47 49
 
48 50
 void setup() {
@@ -89,6 +91,8 @@ void setup() {
89 91
 
90 92
   setupWebUpdater();
91 93
 
94
+  localIP = WiFi.localIP().toString();
95
+
92 96
   delay(100);
93 97
 
94 98
   digitalWrite(STATUS_LED_PIN, LOW);
@@ -115,7 +119,11 @@ void loop() {
115 119
     currentSensorData[SENSOR_WINDSPEED]   = fetchWindspeed();
116 120
     currentSensorData[SENSOR_PRESSURE]    = fetchPressure();
117 121
     currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
118
-  
122
+
123
+    if (currentSensorData[SENSOR_BAT_VOLTAGE] <= 3.7)
124
+    {
125
+      ESP.deepSleep(4294967295); // battery low, shutting down
126
+    }
119 127
 #ifdef DEBUG
120 128
     Serial.println("");
121 129
     //Serial.println("Current readings:");
@@ -128,9 +136,10 @@ void loop() {
128 136
 #endif
129 137
 
130 138
     pushToInfluxDB(DEVICE_NAME, currentSensorData);
139
+    setSensorData(DEVICE_NAME, localIP, currentSensorData);
131 140
   }
132 141
 
133
-  //ESP.deepSleep(UPDATE_INTERVAL * 1000000);
142
+  //ESP.deepSleep(DELAY_LOOP_MS * 1000); // the ESP.deepSleep requires microseconds as input, after the sleep the system will run into the setup routine
134 143
   //delay(100);
135 144
   delay(DELAY_LOOP_MS);
136 145
 

+ 32
- 0
firmware/webUpdater.ino View File

@@ -14,6 +14,10 @@
14 14
 ESP8266WebServer httpServer(8080);
15 15
 ESP8266HTTPUpdateServer httpUpdater;
16 16
 
17
+String ip = "127.0.0.1";
18
+String dev = "unknown";
19
+float sensValues[6];
20
+
17 21
 void setupWebUpdater(void)
18 22
 {
19 23
 #ifdef DEBUG
@@ -22,6 +26,9 @@ void setupWebUpdater(void)
22 26
 #endif
23 27
 
24 28
   httpUpdater.setup(&httpServer);
29
+
30
+  httpServer.on("/", showHTMLMain); // oko specific site
31
+
25 32
   httpServer.begin();
26 33
 
27 34
 #ifdef DEBUG
@@ -34,4 +41,29 @@ void doWebUpdater(void)
34 41
   digitalWrite(D0, HIGH);
35 42
   httpServer.handleClient();
36 43
 }
44
+
45
+void setSensorData(String device, String localip, float sensorValues[]) {
46
+  dev = device;
47
+  ip = localip;
48
+  for (uint8_t i = 0; i < 7; i++)
49
+  {
50
+    sensValues[i] = sensorValues[i];
51
+  }
52
+}
53
+
54
+void showHTMLMain(void) {
55
+  String message = "<html><head><title>OKO Weatherstation - " + String(dev) + "</title></head><body>"
56
+"<br><a href=\"http://" + ip + ":8080/update\">firmware update</a><br><br>"
57
+"<table>"
58
+"<tr><td>temperature</td><td>" + String(sensValues[SENSOR_TEMPERATURE]) + "</td></tr>"
59
+"<tr><td>humidity=" + String(sensValues[SENSOR_HUMIDITY]) + "</td></tr>"
60
+"<tr><td>light=" + String(sensValues[SENSOR_LIGHT]) + "</td></tr>"
61
+"<tr><td>windspeed=" + String(sensValues[SENSOR_WINDSPEED]) + "</td></tr>"
62
+"<tr><td>pressure=" + String(sensValues[SENSOR_PRESSURE]) + "</td></tr>"
63
+"<tr><td>batvoltage=" + String(sensValues[SENSOR_BAT_VOLTAGE]) + "</td></tr>";
64
+"</table>"
65
+"</body></html>";
66
+
67
+  httpServer.send(200, "text/html", message);
68
+}
37 69
 

Loading…
Cancel
Save