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

Clock information not reliable #56

Open
ercoleg opened this issue Feb 24, 2021 · 21 comments
Open

Clock information not reliable #56

ercoleg opened this issue Feb 24, 2021 · 21 comments
Labels
wontfix This will not be worked on

Comments

@ercoleg
Copy link

ercoleg commented Feb 24, 2021

Hello,
first of all I wish to thank you for what you are doing on this project.
I noticed that the clock information is not reliable, time calculated by the device runs faster than conventional time.
One week ago I set the clock
11:32:42: Device Date: 2021-02-17 11:32:38.000
and today I checked the clock
10:09:23: Device Date: 2021-02-24 10:17:17.000
The device clock is about 8 minutes in advance, more da 1 minute/day.
Is the issue related to a not reliable internal clock frequency of the device?
can we foresee a parameter to fine tune the alghorithm you are using to calculate the time?

Thank you
Gabriele

@pvvx
Copy link
Owner

pvvx commented Feb 24, 2021

I noticed that the clock information is not reliable, time calculated by the device runs faster than conventional time.

The SDK uses binary libraries associated with restoring the time counter after sleep mode. Source codes are missing.

image

Clock_time() is used. This is a 32-bit hardware counter reading at 16 MHz (1/16 μs). It is powered by a crystal oscillator that turns off in sleep mode, and the time is counted from a 32 kHz RC oscillator. In sleep mode, the counter is reset by a timer on the RC oscillator. There is no clock crystal at 32768 Hz on the board.

@ercoleg
Copy link
Author

ercoleg commented Feb 24, 2021

Just a further question, this means that the reliability of the Time depends on the sleep mode duration?
to you think it is possible to handle a SW correction over the hw counter readings?
Is this an issue observed by somebody else or it depends on my settings?

Sorry is the question sounds stupid, I'm just a mechanical engineer with a very poor HW background.

@pvvx
Copy link
Owner

pvvx commented Feb 24, 2021

RC oscillator is unstable. Its course is highly temperature dependent. Calibrating the built-in RC oscillator takes time and increases power consumption. Moreover, calibration must be done often, and this is unprofitable.

The device is cheap and has no quartz for watches.
The clock can be adjusted every day.

The original firmware counts the time by 1 hour so that leaving is invisible.

@ercoleg
Copy link
Author

ercoleg commented Feb 24, 2021

Thank you for the explanation, I fully agree.
I have to understand how to automatically adjust time once a day and it will work fine.
Do you have any suggestions on how to do this task?

@pvvx
Copy link
Owner

pvvx commented Feb 25, 2021

In version 2.4:
image

11:58:28: Send delta time ok
11:58:29: Device StepTimeSec: 1000000.813 us

pvvx added a commit that referenced this issue Feb 25, 2021
@ercoleg
Copy link
Author

ercoleg commented Feb 27, 2021

I have tuned the parameter and now it works perfectly! Thank you!
How does it work the modification you have done? I would like to understand just the principle.

GE

@pvvx
Copy link
Owner

pvvx commented Mar 13, 2021

Please write what kind of correction "clock delta" you got.

@pvvx pvvx reopened this Mar 13, 2021
@ercoleg
Copy link
Author

ercoleg commented Mar 13, 2021

I have set: Device StepTimeSec: 1000845.125 us
Since I have uploaded new sw 2.6 it started to be a little bit in advance, I have to recalibrate.

G

@leehadassin
Copy link

I'd love to see an automatic clock calibration function added to the website where the last calibration time (stored in the device?) is compared to the current time and the clock delta is calculated based on the drift.

@hpirila
Copy link

hpirila commented Sep 3, 2021

It would be nice also for Esphome to synchronize the Xiaomi clock every 6 hours or so.

@mateuszdrab
Copy link

It would be nice also for Esphome to synchronize the Xiaomi clock every 6 hours or so.

Or to have a python script automatically connect to all ATC sensors and re-sync their time, could run this as cron.

@TimDowker
Copy link

Can anybody tell me how I should set the "delta time"?

TIA

@jenshenk
Copy link

I was wondering whether I can pointed towards any command line option to adjust the clock. The delta time adjustment helps a bit, yet after a few days it shows that this isn't enough. Perfect would be if I could just setup a cronjob setting the clock once a day. Tasmota actually has a command for setting the time, but I'm getting an error and I guess this is just for the stock firmware.

@pvvx
Copy link
Owner

pvvx commented Feb 12, 2022

It would be nice also for Esphome to synchronize the Xiaomi clock every 6 hours or so.

Esphome is not supported until the large number of receive gaps in BLE is fixed. Has unstable operation and does not support progressive options in Wi-Fi 6.
Or solved in a different way - with an alternative BLE chip.

@Protoncek
Copy link

I have 3 esp32 modules as BLE receivers for my 8 xiaomi’s. Now i’m testing esp32 with tasmota FW and first results are better than with esphome - in tasmota all seen xiaomi’s are shown seconds after power-on, while in esphome it can take up to a minute. I have some minor issues with wifi disconnecting, but thatks another story and can be solved. And here i can immediately see which modules are in a range of esp module.
So, i can confirm that tasmota is better than esphome in this case, eventhough i’m a bigger fan of esphome, because i can program module exactly the way i want, while tasmota is preprogrammed.

@benep
Copy link

benep commented Feb 17, 2022

I'd love to see an automatic clock calibration function added to the website where the last calibration time (stored in the device?) is compared to the current time and the clock delta is calculated based on the drift.

I use 7 devices with your software and I love it. Thank you! All the clocks on my devices running different. So I'd also like an automatic calculation button for the delta in TelelinkMiFlasher.

Maybe it is possible to store the last update datetime of the clock on the device. Then the calculation with the tree times (update, global and device) and the actual delta is easy. If this is not possible you can maybe store the update datetime as cookie on the browser with the mac of the device. That'd only work if you always use the same browser, but it's way better than manual calculation.

@pvvx
Copy link
Owner

pvvx commented Feb 18, 2022

Receiving and transmitting data in javascript has a jitter of 2.5 seconds (BLE connection interval).
Requires a large counter of seconds since the clock was last set.
The minimum period for the next delta calculation is more than 3 hours.
image
Included in version 3.6b.

@migreg
Copy link

migreg commented Nov 28, 2022

It would be nice also for Esphome to synchronize the Xiaomi clock every 6 hours or so.

Or to have a python script automatically connect to all ATC sensors and re-sync their time, could run this as cron.

I'm using the delta time option but if someone has a python script for time syncing via cron, please share it. Thanks

@jd1
Copy link

jd1 commented Nov 2, 2023

You can also synchronize the time via ESPHome: https://esphome.io/components/display/pvvx_mithermometer.html?highlight=lywsd03mmc#only-synchronize-the-time-once-a-day

@mateuszdrab
Copy link

You can also synchronize the time via ESPHome: https://esphome.io/components/display/pvvx_mithermometer.html?highlight=lywsd03mmc#only-synchronize-the-time-once-a-day

This actually doesn't work for me, I had it set up like that but the time still drifted away really bad.

@pvvx pvvx added the wontfix This will not be worked on label Dec 23, 2023
@akoivist
Copy link

akoivist commented Sep 1, 2024

Wrote (using ChatGPT to be honest) a little python app to set the clock without ESPHome. I scheduled it to be run once a week on a desktop pc. Sharing it in case someone wants to use it instead of the official python interface.
https://gist.github.com/akoivist/61420a0d22276dadfc4de79fb7e4c776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests