atc1441 / ATC_MiThermometer

Custom firmware for the Xiaomi Thermometer LYWSD03MMC and Telink Flasher via USB to Serial converter
2.81k stars 472 forks source link

Advertising interval on Mi-like format #145

Open eduperez opened 3 years ago

eduperez commented 3 years ago

When using the Mi-like format, the current model of alternating between temperature+humidity and battery does not make much sense, IMHO.

Battery info does not change that frequently, there is no need to send updates every two cycles. Also, once the device has been awake, it should send both messages at once, to avoid unnecessary wake ups.

atc1441 commented 3 years ago

Hey. On mi like advertising it will change the data at half the advertising interval to keep the timing right.

It will not meassure the battery voltage more often so it does not need more power.

In general it will always wake up at an 3 second interval and then always sends the BLE name and advertising data, the interval only changes how often it does change this data.

If it would not send the data every 3 seconds no device would be a ble to connect to it.

Hope that explains it well enough

pvvx commented 3 years ago

define ADVERTISING_INTERVAL 3000

https://github.com/atc1441/ATC_MiThermometer/blob/master/ATC_Thermometer/app_config.h#L9 *Advertising interval: 3000 0.625 = 1875 ms**

https://github.com/atc1441/ATC_MiThermometer/blob/master/ATC_Thermometer/app.c#L79 Battery measurement interval: 5 60000 CLOCK_SYS_CLOCK_1MS = 5 60000 24 * 1000 = 0x1AD274800 (overflow 32 bits) 0x1AD274800 -> 32 bit = 0xAD274800 = 2905032704 Step clock_time() 1/16 us -> 2905032704/16 = 181564544 us = 181.6 sec Battery measurement interval: 181.6 sec

https://github.com/atc1441/ATC_MiThermometer/blob/master/ATC_Thermometer/app.c#L79 5000 CLOCK_SYS_CLOCK_1MS = 5000 24 * 1000 = 120000000 120000000 / 16 = 7500000 us = 7.5 sec Main loop delay: 7.5 sec

https://github.com/atc1441/ATC_MiThermometer/blob/master/ATC_Thermometer/app.c#L85 *Measures interval: 7.5 measure_interval** (default: 75 sec)