EliasKotlyar / Xiaomi-Dafang-Hacks

4.17k stars 1k forks source link

Time resets to epoch after reboot if cam blocked from internet #1750

Closed bverkron closed 2 years ago

bverkron commented 3 years ago

Description

If the cam is rebooted while blocked from the internet the time gets reset to the epoch date. I would expect it to retain the time internally and sync with the ntp server periodically to correct drift. I would not expect it to lose it's time setting entirely on a reboot (or any other time) if it cannot reach the ntp server

What did you do to debug the issue

As soon as I unblock the cam from the internet and re-save the Time settings it updates to the correct time from the ntp server. If I reboot with the unblocked from the internet the time is held as expected. If I block the cam from the internet and reboot the time gets reset to the epoc

c--- commented 3 years ago

hwclock is installed but reports can't open '/dev/misc/rtc': No such file or directory so I assume it has no real time clock that could survive a reboot.

I have an internal NTP server that the cameras use without needing access to the Internet.

Since you like hacking cameras do you happen to run OpenWRT/DD-WRT on your router? Easy to set up a NTP server there. Speaking of which, most routers lose their time when they reboot too, along with cable modems and other such devices. Even the ubiquitous Raspberry Pi doesn't have a RTC.

bverkron commented 3 years ago

Interesting. I am using an EdgeRouter X and it seems it may be possible to set it up as an ntp server, but not sure if Dafang will pick it up from that. https://bneijt.nl/blog/add-ntp-server-address-in-dhcp-response-of-edgerouter/

Edit: Re-reading that article I see it might not be doing what I expected. i.e. not using the router as an ntp server. I used to use DD-WRT but had a bunch of upgrade and functionality problems with it on my particular model of router so moved to the EdgeRouter.

Edit 2: On a hunch I just tried using my router IP for the ntp server address and it seems to work. Time does not reset to epoch after reboot (or rather it probably resets to epoch and then immediately picks up the time from the router).

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.