Browse Source

Added battery charging states.

klaute 1 year ago
parent
commit
87fe6c6e7a
4 changed files with 38 additions and 8 deletions
  1. 6
    1
      firmware/config.h
  2. 12
    5
      firmware/firmware.ino
  3. 7
    2
      firmware/influxdb.ino
  4. 13
    0
      firmware/sensors.ino

+ 6
- 1
firmware/config.h View File

@@ -8,6 +8,12 @@
8 8
 #define SENSOR_WINDSPEED      3
9 9
 #define SENSOR_PRESSURE       4
10 10
 #define SENSOR_BAT_VOLTAGE    5
11
+#define SENSOR_ESAVEMODE      6
12
+#define SENSOR_BATCHARGESTATE 7
13
+
14
+#define BAT_CHARGE_STATE_CHARGED     2.0
15
+#define BAT_CHARGE_STATE_CHARGING    1.0
16
+#define BAT_CHARGE_STATE_NOTCHARGING 0.0
11 17
 
12 18
 #define WIFI_AUTOCONNECT_TIMEOUT_S    60
13 19
 #define WIFI_CONFIG_PORTAL_TIMEOUT_S  60
@@ -35,4 +41,3 @@
35 41
 #define INITIAL_WEBSERVER_TIME 20
36 42
 
37 43
 #endif
38
-

+ 12
- 5
firmware/firmware.ino View File

@@ -33,10 +33,10 @@
33 33
 
34 34
 //*************************************************************************//
35 35
 
36
-float currentSensorData[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
36
+float currentSensorData[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
37 37
 
38
-uint16_t update_sensor_cnt    = 0;
39
-uint16_t update_webserver_cnt = 0;
38
+uint16_t update_sensor_cnt      = 0;
39
+uint16_t update_webserver_cnt   = 0;
40 40
 uint16_t energySavingIterations = 0;
41 41
 
42 42
 WiFiManager wifiManager;
@@ -179,6 +179,7 @@ void loop() {
179 179
   }
180 180
 #endif
181 181
 
182
+
182 183
   _loop();
183 184
 
184 185
   //Needed to give WIFI time to function properly
@@ -202,15 +203,19 @@ void _loop() {
202 203
     currentSensorData[SENSOR_LIGHT]       = fetchLight();
203 204
     currentSensorData[SENSOR_PRESSURE]    = fetchPressure();
204 205
 #ifdef BATTERY_POWERED
205
-    currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
206
+    currentSensorData[SENSOR_BAT_VOLTAGE]    = getBatteryVoltage();
207
+    currentSensorData[SENSOR_BATCHARGESTATE] = isBatCharging();
206 208
 #else
207
-    currentSensorData[SENSOR_BAT_VOLTAGE] = 0xFFFFFFFF;
209
+    currentSensorData[SENSOR_BAT_VOLTAGE]    = 0xFFFFFFFF;
210
+    currentSensorData[SENSOR_BATCHARGESTATE] = 0xFFFFFFFF;
208 211
 #endif
209 212
     // Disable expensive tasks
210 213
     if (energySavingMode() == 0) {
211 214
       currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
215
+      currentSensorData[SENSOR_ESAVEMODE] = 1.0;
212 216
     } else {
213 217
       currentSensorData[SENSOR_WINDSPEED] = 0xFFFFFFFF;
218
+      currentSensorData[SENSOR_ESAVEMODE] = 0.0;
214 219
     }
215 220
 
216 221
 #ifdef DEBUG
@@ -222,6 +227,8 @@ void _loop() {
222 227
     Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
223 228
     Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
224 229
     Serial.println("Bat Voltage: " + String(currentSensorData[SENSOR_BAT_VOLTAGE]) + " V");
230
+    Serial.println("Bat charge state: " + String(currentSensorData[SENSOR_BATCHARGESTATE]));
231
+    Serial.println("Energy saving: " + String(currentSensorData[SENSOR_ESAVEMODE]));
225 232
 #endif
226 233
 
227 234
     delay(100);

+ 7
- 2
firmware/influxdb.ino View File

@@ -7,7 +7,9 @@ void pushToInfluxDB(String device, float sensorValues[]) {
7 7
                + ",light=" + String(sensorValues[SENSOR_LIGHT])
8 8
                + ",windspeed=" + String(sensorValues[SENSOR_WINDSPEED])
9 9
                + ",pressure=" + String(sensorValues[SENSOR_PRESSURE])
10
-               + ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]);
10
+               + ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE])
11
+               + ",esavemode=" + String(sensorValues[SENSOR_ESAVEMODE])
12
+               + ",batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]);
11 13
 
12 14
   Serial.println(msg);
13 15
   #endif
@@ -27,6 +29,9 @@ void pushToInfluxDB(String device, float sensorValues[]) {
27 29
       influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
28 30
     if (!(isnan(sensorValues[SENSOR_BAT_VOLTAGE])))
29 31
       influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));
32
+    if (!(isnan(sensorValues[SENSOR_ESAVEMODE])))
33
+      influxdb.write("weather,device=" + device + " esavemode=" + String(sensorValues[SENSOR_ESAVEMODE]));
34
+    if (!(isnan(sensorValues[SENSOR_BATCHARGESTATE])))
35
+      influxdb.write("weather,device=" + device + " batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]));
30 36
   } while (influxdb.response() != DB_SUCCESS and tries < 5);
31 37
 }
32
-

+ 13
- 0
firmware/sensors.ino View File

@@ -61,4 +61,17 @@ float getBatteryVoltage() {
61 61
   float volt = raw / 1023.0;
62 62
   return volt * 4.2;
63 63
 }
64
+
65
+float isBatCompletelyCharged() {
66
+  if (HIGH == digitalRead(BAT_CHARGED_PIN))
67
+  {
68
+    return BAT_CHARGE_STATE_CHARGED;
69
+  } else if (HIGH == digitalRead(BAT_CHARGING_PIN))
70
+  {
71
+    return BAT_CHARGE_STATE_CHARGING;
72
+  }
73
+
74
+  return BAT_CHARGE_STATE_NOTCHARGING;
75
+}
76
+
64 77
 #endif

Loading…
Cancel
Save