Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerdraw with this script 20 times higher than with official app #18

Closed
JsBergbau opened this issue Feb 24, 2020 · 10 comments
Closed

Powerdraw with this script 20 times higher than with official app #18

JsBergbau opened this issue Feb 24, 2020 · 10 comments
Labels

Comments

@JsBergbau
Copy link
Owner

I've done some measurements by putting a multimeter between the battery and the Aqara device.
When it is on advertising mode it consumes about 20µA. It is hard to get an exact value because it fluctuates heavily even with a 4000 µF capacitor on the Xiaomi device side. With about 20 µA and a battery capacity of about 210 mAh we get a calculated lifetime of 10500 hours or 437 days with is roughly about 1 year and 2 month.

When connected the values are quite stable and I get around 500 µA power draw and very stable. But I'm a bit confused because 500 µA with a 210 mAh battery gives a batterylifetime of 17,5 days. Either some batteries have more capacity or the multimeter is bad. However some devices failed after quite short time. So round about are the values ok.
There is no noticable difference in the 500 µA power draw whether the temp/humidity/voltage notification is activated or not. Solely the bluetooth connection uses that much amount of power.

Thats why I'll try to implement a connection intervall of 5 minutes, as described here #1 (comment)

Update: With this simple multimeter there can be seen no difference in power draw when doing an active scan with sudo hcitool lescan --duplicate. On active scanning mode the device replies to the scans with its device name.

And now the very interessting part: When you use the official Xiaomi Mi App the power draw goes to about 500-700 µA shortly and then it falls down to about 25 µA even is the sensor is still connected with the app. If you touch and hold it so that the temperature rises it is almost immediately shown on smartphone. If we could reach that small power draw we could stay connected because there is only a very small additional energy usage and establishing the connection uses most energy.

So the question is whats going on that with official app the power draw is that kind of small and with this script so insane high.

This was referenced Feb 24, 2020
@michaelnimbs
Copy link

Wasn't there some encrypted advertisement payload data only the official app could decrypt?

Could you check the power consumption with this unofficial app? https://play.google.com/store/apps/details?id=com.smrtprjcts.mijiabt
(Would be easier to reverse engineer / decompile I guess)

@JsBergbau
Copy link
Owner Author

Yeah, I've tested with that App. It only connects for a few seconds, gets the values and then disconnects. While that the powerdraw is between 500-700 µA like the official app. There is no longer period when the App stays connected and I couldn't find any option to let the App stay connected.

@JsBergbau
Copy link
Owner Author

I've also tried with this App https://play.google.com/store/apps/details?id=com.freetimeprojects.mijiareader but it also only shortly connects.

Then I connected with nrf connect https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp It had about 400 µA. Later I wanted to find out why 100 µA lower, but then it also had about 500 µA. Don't know why. Was there really a difference? Or is it a problem with the multimeter used?

@JsBergbau
Copy link
Owner Author

I've created a bluetooth hci log and the app wrote a lot of stuff to the sensor. I'll try to send and see whats happening to the power consumption.

@JsBergbau
Copy link
Owner Author

Ok I've found out how to safe power.
Official App writes
char-write-req 0x0046 f40100
and then connection parameter changes and power is saved. After setting this parameter commands like char-desc lead to a connection abort. Just don't set it when exploring the device, keep this in mind.

grafik
I've tried playing around with the value f40100 because bluetooth connection interval can go from 7.5ms to 4 seconds. However all values I've tried decreased connection intervall and thus increased power consumption. As we have a interval of 500 ms we could save a lot power by reducing to four seconds. If somebody is willing to play around, thanks. However this value is Xiaomi specific. So you put something in and the Aqara interprets it and based upton that it uses standard bluetooth commands to change connection parameters. So I doubt there is any way to increase beyond 500 ms without a firmware update. There would be no disadvantages in our use case with the longest connection interval of 4 seconds.

Power draw also depends on the connectin device. With a vernee thor power draw is only 275 µA on standard connection. I think it is because the Aqara requests a connect interval between 25 and 50 ms. If vernee uses 50 ms there is half of power used. If we use 500 ms we have 1/10 and about 27,5 µA.

Distance (and or RF interference) also plays an important role. When the distance is higher, I've measured more power draw. To get quite exact comparison values, I charged the 4000 µF capacitors, connected my script, waited for two measurements and then cut power to the capacitors.
Within the range of 1 meter between Raspberry PI and the Aqara sensor there were 28 or 29 measurements after the first 2 measurements printed, thats almost 3 minutes running on the capacitors! At the end you didn't even see anything on the display (or you had to look very close) but still the sensor transmitted its value via Bluetooth. On more distance there were only 22-23 measurements on the capacitor.

BTW: The battery voltage is only read in some intervals. My device is running for almost 2 minutes on the 4000 µF capacitors and voltage printed was always 2.985 even if you could barely read the display.

The script is now updated to support powersavings. We have now about 20 to 25 times longer battery life. So I expect to last good batteries now between one and two years. We'll see.

@michaelnimbs
Copy link

Thank you for your tremendous effort!

@jaggil
Copy link

jaggil commented Feb 25, 2020

@JsBergbau
Hi, I just wrote the value 0xF40100 in the following characteristic and the consumption drops tremendously.
set conn interval -> "ebe0ccd8-"
Please, can you try it on your devices?

I update, the value 0x0001f4 is curiously -> 500

@JsBergbau
Copy link
Owner Author

@jaggil
Thank you for all your support with the Aqara Bluetooth Thermometer. I think our answers have just overlapped. I'm now also writing char-write-req 0x0046 f40100 and the power consumption drops. It is now implemented in the official MiTemperature2 script.

@JsBergbau
Copy link
Owner Author

Since it is fixed for a while, I close now.

@eranl
Copy link

eranl commented Feb 1, 2021

I just had a first battery die after two weeks and another after one week. My RP4 is within 30cm of the sensor. Using stock firmware and a constant connection. Interestingly, the first battery in a second sensor which is located outside and has a spotty connection lasted three weeks.
As a workaround, I'll now try a wrapper script that will connect and take one measurement every 5 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants