bakerkj / weewx-purpleair

WeeWx Extension to pull data from the local interface of a Purple Air air quality sensor
GNU General Public License v2.0
17 stars 11 forks source link

Sensors occasionally drop temperature, humidity, and pressure reports from JSON #4

Closed ke6jjj closed 5 years ago

ke6jjj commented 5 years ago

On 2019-01-14T00:00 UTC, a new firmware update which removes temperature and pressure measurements appears to have been pushed to all sensors. This causes problems in weewx-purpleair because it seems to require that these fields be present in the JSON reports.

I have a commit to my local branch which fixes this:

https://github.com/ke6jjj/weewx-purpleair/commit/c2bbad6b2368bbff9f177ab40249dcf678252fa7

But this branch has other changes which you may not want (yet). If you can pull this one commit it, please feel free to do so.

ke6jjj commented 5 years ago

Of course, just as I post this I see that my sensor is now reporting these "missing" fields again. Perhaps there is a period of time where a recently rebooted sensor doesn't report temperature, pressure and humidity, and this change is still a good idea.

bakerkj commented 5 years ago

@ke6jjj I am reluctant to silently ignore a state where these values are missing from the JSON as it may be evidence of an ongoing error state.

Let's think more on how to best proceed.

ke6jjj commented 5 years ago

I understand the reluctance to ignore the missing data. But as the code is currently written, if there is good air quality data but missing temperature/humidity/pressure data, it will crash and not save the air quality data. This is indeed happening with some regularity on my sensor, and I would argue that, at the very least, the code should not crash and loose the otherwise good and intended data for the sensor. It is, after all, primarily an air quality monitor and not a temperature sensor.

Here are the most recent ten records where my sensor had good air quality data but missing temperature (and other) data. This is, of course, after my applied patch, which at least allows the air quality data to be saved. The top record is from about three hours ago:

sqlite> select * from archive where purple_temperature is null order by dateTime desc limit 10; dateTime|usUnits|interval|purple_temperature|purple_humidity|purple_dewpoint|purple_pressure|pm1_0_cf_1|pm1_0_atm|pm2_5_cf_1|pm2_5_atm|pm10_0_cf_1|pm10_0_atm 1547578100|1|1|||||1.05|1.05|1.71|1.71|2.745|2.745 1547578036|1|1|||||0.99|0.99|1.86|1.86|2.18|2.18 1547577980|1|1|||||0.99|0.99|1.86|1.86|2.18|2.18 1547577917|1|1|||||0.83|0.83|1.635|1.635|1.965|1.965 1547577860|1|1|||||1.23|1.23|1.895|1.895|2.21|2.21 1547577800|1|1|||||1.16|1.16|2.0|2.0|2.515|2.515 1547577740|1|1|||||1.16|1.16|2.0|2.0|2.515|2.515 1547577680|1|1|||||1.225|1.225|2.025|2.025|2.55|2.55 1547577620|1|1|||||1.3|1.3|2.445|2.445|2.88|2.88 1547577560|1|1|||||1.005|1.005|1.76|1.76|2.58|2.58

ke6jjj commented 5 years ago

Perhaps we can keep this patch, but also add a warning statement to the log that the sensor isn't returning the weather data? That way the error isn't completely invisible, yet it also doesn't cause unnecessary data loss.

bakerkj commented 5 years ago

I think that would be a reasonable solution. Would you be willing to modify your patch to include the logging and test it?

ke6jjj commented 5 years ago

Ok, I've added code to log the error now and issued pull request #5.

ke6jjj commented 5 years ago

Oh, I am also running the code now. So far it has collected about 5 archive records without incident. However, my sensor is also reporting all data items at the moment. The real test is to see what happens if one goes missing.

bakerkj commented 5 years ago

I merged your pull request.