Added a data validation check. The webupdater will output the result of the check and also the hbWebstat json data contain the valid flag now. Also only valid data will logged into the influxDB.
This commit is contained in:
parent
66440f572e
commit
0366456b13
3 changed files with 35 additions and 2 deletions
|
@ -11,6 +11,7 @@
|
|||
#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
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
//*************************************************************************//
|
||||
// constant variables
|
||||
|
||||
const uint8_t VALUES = 8;
|
||||
const uint8_t VALUES = 8; // see constants.h file - count of number of SENSOR_ defines
|
||||
float currentSensorData[VALUES] = {nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value")};
|
||||
float (*sensors[VALUES])() = {};
|
||||
|
||||
|
@ -34,6 +34,8 @@ uint16_t update_sensor_cnt = 0;
|
|||
uint16_t update_webserver_cnt = 0;
|
||||
uint16_t update_windspeed_exceed_cnt = 0;
|
||||
|
||||
boolean validData = false;
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
//*************************************************************************//
|
||||
|
@ -317,7 +319,20 @@ void _loop()
|
|||
delay(100);
|
||||
|
||||
#ifdef INFLUXDB_FEATURE
|
||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||
|
||||
for (uint8_t i = 0; i < 5 and validData == false; i++)
|
||||
{
|
||||
if (currentSensorData[i] != 0)
|
||||
{
|
||||
validData = true; // at least one value is not zero, the data
|
||||
}
|
||||
}
|
||||
|
||||
if (validData == true)
|
||||
{
|
||||
// send data only if valid data is available
|
||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WEBUPDATER_FEATURE
|
||||
|
|
|
@ -30,8 +30,11 @@ String hb_ws_msg_light = "\"lightlevel\": ";
|
|||
String hb_ws_msg_windspeed = "\"windspeed\": ";
|
||||
String hb_ws_msg_pressure = "\"pressure\": ";
|
||||
String hb_ws_msg_timestamp = "\"timestamp\": ";
|
||||
String hb_ws_msg_valid = "\"valid\": ";
|
||||
String hb_ws_msg_end = "}";
|
||||
|
||||
boolean wuValidData = false;
|
||||
|
||||
void setupWebUpdater(String device, String ip)
|
||||
{
|
||||
debug("Starting WebUpdater... " + ip);
|
||||
|
@ -62,6 +65,15 @@ void doWebUpdater(void)
|
|||
|
||||
void setSensorData(float sensorValues[])
|
||||
{
|
||||
|
||||
for (uint8_t i = 0; i < 5 and wuValidData == false; i++)
|
||||
{
|
||||
if (_webUpdater_sensValues[i] != 0)
|
||||
{
|
||||
wuValidData = true; // at least one value is not zero, the data
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < VALUES; i++) {
|
||||
_webUpdater_sensValues[i] = sensorValues[i];
|
||||
}
|
||||
|
@ -69,6 +81,7 @@ void setSensorData(float sensorValues[])
|
|||
|
||||
void showHTMLMain(void)
|
||||
{
|
||||
|
||||
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
|
@ -81,6 +94,7 @@ void showHTMLMain(void)
|
|||
"<tr><td>pressure</td><td>" + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + "</td></tr>"
|
||||
"<tr><td>batvoltage</td><td>" + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + "</td></tr>"
|
||||
"<tr><td>millis</td><td>" + String(millis()) + "</td></tr>"
|
||||
"<tr><td>valid</td><td>" + String(wuValidData) + "</td></tr>"
|
||||
"</table>"
|
||||
"</body></html>";
|
||||
|
||||
|
@ -107,6 +121,9 @@ void hb_webstat_send(void)
|
|||
", " +
|
||||
hb_ws_msg_timestamp +
|
||||
String(millis()) +
|
||||
", " +
|
||||
hb_ws_msg_valid +
|
||||
String(wuValidData) +
|
||||
hb_ws_msg_end;
|
||||
|
||||
httpServer.send(200, "text/html", msg);
|
||||
|
|
Loading…
Reference in a new issue