Airthings / waveplus-reader

MIT License
133 stars 61 forks source link

Battery status #11

Open mjs82 opened 5 years ago

mjs82 commented 5 years ago

It would be helpful to read the battery status/charge. But there does not appear to be a standard GATT battery service advertised.

The code reads characteristic b42e2a68-ade7-11e4-89d3-123b93f75cba and I see that bytes 2-3 and 16-19 are currently ignored.. could battery status be hidden in there perhaps?

fireether commented 4 years ago

I've been wanting this feature for the past 2-3 years. I brought 2 airthings CO sensors, and I loved that they had python code to get temp, humidity and co readings from the sensors. But the problem is that I have to poll my database readings to detect when a sensor falls offline. It would be very helpful if we could read the battery life, or at least get an alert when to replace the battery.

Its my fault for not implementing a server side polling of the database to detect when a sensor stops sending data, but if there is a way to read the battery status via bluetooth - please do that. It would save me running a process on my workstation.

fireether commented 4 years ago

Also I noticed that the app on the phone knows the battery life.

AndySchroder commented 3 years ago

yes, would like this, or a model that allows power to be hard wired.

AndySchroder commented 3 years ago

Also, does the SAMPLE-PERIOD impact battery life? This device seems to only update once every 5 minutes, but we don't know when that time period starts, so we need to sample at a rate greater than once every 5 minutes in order to get time accurate data, then throw out all duplicates from the 5 minute period.

dinoact commented 3 years ago

I would also love to know how to read the current battery percentage via bluetooth rather than having to rely on the app or to watch out for when the device stops reporting data.

awilliam commented 3 years ago

Me too please. These python scripts are the reason I chose to purchase an AirThings radon meter versus the alternatives. Battery status is the one thing missing. Please share how to decode it from the extra bits in the characteristic or update the firmware to support standard BLE battery reporting.

singlepane-io commented 2 years ago

I'm also interested in the battery status. As for polling frequency impacting battery, I haven't seen any significant difference between a sensor that is polled every few minutes and one polled every 30 seconds.

arnerek commented 2 years ago

I used the code from this page: https://sifter.org/~simon/journal/20191210.1.html

I added the following lines to the function query2_parse

    d = struct.unpack('<L12B6H', q2['raw'])

    q2['ambientlight'] = d[2]
    q2['measurement_periods'] =  d[5]
    q2['voltage'] = d[17] / 1000.0

    V_MAX=3.2
    V_MIN=2.2
    q2['battery']= max(0, min(100, round( (q2['voltage']-V_MIN)/(V_MAX-V_MIN)*100)))

The battery in percentage is available in q2['battery']. It is not identical to what is reported in the app, but quite close. Maybe someone has a better way of calculating battery capacity from voltage?

singlepane-io commented 2 years ago

@arnerek or @eddyg, were either of you able to find a way to get an exacting battery value and have it incorporated into the reader? I've been pulling my hair out how to incorporate that different struct into this reader so I can get the battery in the same output with the other metrics.