Added battery charging states.

This commit is contained in:
klaute 2019-02-02 10:09:00 +01:00
parent 1f1bd3d19b
commit 87fe6c6e7a
4 changed files with 38 additions and 8 deletions

7
firmware/config.h Executable file → Normal file
View file

@ -8,6 +8,12 @@
#define SENSOR_WINDSPEED 3
#define SENSOR_PRESSURE 4
#define SENSOR_BAT_VOLTAGE 5
#define SENSOR_ESAVEMODE 6
#define SENSOR_BATCHARGESTATE 7
#define BAT_CHARGE_STATE_CHARGED 2.0
#define BAT_CHARGE_STATE_CHARGING 1.0
#define BAT_CHARGE_STATE_NOTCHARGING 0.0
#define WIFI_AUTOCONNECT_TIMEOUT_S 60
#define WIFI_CONFIG_PORTAL_TIMEOUT_S 60
@ -35,4 +41,3 @@
#define INITIAL_WEBSERVER_TIME 20
#endif

View file

@ -33,7 +33,7 @@
//*************************************************************************//
float currentSensorData[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
float currentSensorData[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
uint16_t update_sensor_cnt = 0;
uint16_t update_webserver_cnt = 0;
@ -179,6 +179,7 @@ void loop() {
}
#endif
_loop();
//Needed to give WIFI time to function properly
@ -203,14 +204,18 @@ void _loop() {
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
#ifdef BATTERY_POWERED
currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
currentSensorData[SENSOR_BATCHARGESTATE] = isBatCharging();
#else
currentSensorData[SENSOR_BAT_VOLTAGE] = 0xFFFFFFFF;
currentSensorData[SENSOR_BATCHARGESTATE] = 0xFFFFFFFF;
#endif
// Disable expensive tasks
if (energySavingMode() == 0) {
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
currentSensorData[SENSOR_ESAVEMODE] = 1.0;
} else {
currentSensorData[SENSOR_WINDSPEED] = 0xFFFFFFFF;
currentSensorData[SENSOR_ESAVEMODE] = 0.0;
}
#ifdef DEBUG
@ -222,6 +227,8 @@ void _loop() {
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " km/h");
Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
Serial.println("Bat Voltage: " + String(currentSensorData[SENSOR_BAT_VOLTAGE]) + " V");
Serial.println("Bat charge state: " + String(currentSensorData[SENSOR_BATCHARGESTATE]));
Serial.println("Energy saving: " + String(currentSensorData[SENSOR_ESAVEMODE]));
#endif
delay(100);

View file

@ -7,7 +7,9 @@ void pushToInfluxDB(String device, float sensorValues[]) {
+ ",light=" + String(sensorValues[SENSOR_LIGHT])
+ ",windspeed=" + String(sensorValues[SENSOR_WINDSPEED])
+ ",pressure=" + String(sensorValues[SENSOR_PRESSURE])
+ ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]);
+ ",batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE])
+ ",esavemode=" + String(sensorValues[SENSOR_ESAVEMODE])
+ ",batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]);
Serial.println(msg);
#endif
@ -27,6 +29,9 @@ void pushToInfluxDB(String device, float sensorValues[]) {
influxdb.write("weather,device=" + device + " pressure=" + String(sensorValues[SENSOR_PRESSURE]));
if (!(isnan(sensorValues[SENSOR_BAT_VOLTAGE])))
influxdb.write("weather,device=" + device + " batvoltage=" + String(sensorValues[SENSOR_BAT_VOLTAGE]));
if (!(isnan(sensorValues[SENSOR_ESAVEMODE])))
influxdb.write("weather,device=" + device + " esavemode=" + String(sensorValues[SENSOR_ESAVEMODE]));
if (!(isnan(sensorValues[SENSOR_BATCHARGESTATE])))
influxdb.write("weather,device=" + device + " batchargestate=" + String(sensorValues[SENSOR_BATCHARGESTATE]));
} while (influxdb.response() != DB_SUCCESS and tries < 5);
}

13
firmware/sensors.ino Executable file → Normal file
View file

@ -61,4 +61,17 @@ float getBatteryVoltage() {
float volt = raw / 1023.0;
return volt * 4.2;
}
float isBatCompletelyCharged() {
if (HIGH == digitalRead(BAT_CHARGED_PIN))
{
return BAT_CHARGE_STATE_CHARGED;
} else if (HIGH == digitalRead(BAT_CHARGING_PIN))
{
return BAT_CHARGE_STATE_CHARGING;
}
return BAT_CHARGE_STATE_NOTCHARGING;
}
#endif