Vera - Smarter Home Control Forum

Advanced => Programming => General => Topic started by: therealdb on October 11, 2018, 02:43:28 am

Title: How to set a local time server?
Post by: therealdb on October 11, 2018, 02:43:28 am
Hi. I have a very flaky internet connection: sometimes it's now working good and if the Vera reboots, I have problems with time.

I found a couple of very old posts about changing to a local NTP server, but I'm not sure if that's the right direction. I have a synology NAS, so I think I'm covered. I can also install it on my local ubuntu server.

I'd prefer a way to automatically re-install after a firmware upgrade.

Any help is appreciated. Thanks.
Title: Re: How to set a local time server?
Post by: reneboer on October 11, 2018, 06:02:35 am
Hi,

I used these instructions to set one of my Vera's to a local PI running a NTP server.

http://forum.micasaverde.com/index.php/topic,33038.0.html

Cheers Rene
Title: Re: How to set a local time server?
Post by: therealdb on October 11, 2018, 06:16:22 am
Thanks Rene, I think I made it.
Title: Re: How to set a local time server?
Post by: rafale77 on October 29, 2018, 10:38:34 pm
Sorry, might be a bit off topic but I have been digging pretty deep into the OpenWrt OS of my vera plus over the past few days and have discovered a number of forgotten scripts.
As I found out, during boot up, the vera intervenes on its time with 5 different scripts!!!!!

First openWRT has an internal script which checks your entire file system and determines the latest updated file date and sets the time to that date. It is actually very well designed by openWRT developers.
"/etc/init.d/sysfixtime". It is actually the first script the init.d runs.
Second, this script is from Mios, is run a little later in the boot sequence "/etc/init.d/mios_fix_time" which checks whether the unit has a battery and then updates the system time to a time saved in a file when the vera shut down. The problem is that file may not be saved if you brutally unplugged it or in case of power outage. If it was saved it will take the previous time and just add 1 minute as the supposed time it takes to reboot. It also updates to that time only if it determined that it got its time from the internet through a temporary file ("/tmp/.time_synced") created by a script which seem to no longer exists on my machine, otherwise by default it will reset the time to midnight Jan 1st 2000 if none of the conditions above occur. This is a little convoluted script which is overkill and does not work very well.
The third one is from the OS through the ntpclient which is run as a service and loads just before the cmh Luup engine starts.
The fourth one is through another OS service: ntpd, so there are actually 2 ntp services running and updating the time.
The fifth one is within the cmh Luup engine itself which calls an obsolete ntp sync program: "rdate" still residing on the vera through the "/usr/bin/sync_time.sh" script. On my Vera Plus, this script fails because it requires a "function.sh" file which is not where it thinks it is. The file is in /lib instead of /etc.

Overall this is a mess... When I reboot the vera I get a reboot time in my logs of 2min after Jan 1 2000 because my temp file never has the flag to indicate it got its time through an ntp server. I suspect it is because it is should be coming from rdate which is probably not working. I then get a Luup reload time which is accurate since it has been synced with ntp.

I have now killed 2 of the 5 scripts calling for the system time update... essentially the 2 mios ones and I am getting better time accuracy upon reboot.
Title: Re: How to set a local time server?
Post by: therealdb on October 30, 2018, 11:24:12 am
Have you opened a ticket? I think they can try to improve this particular piece of their architecture and, we hope, to just let us specify a time server in the UI.
Title: Re: How to set a local time server?
Post by: rafale77 on October 30, 2018, 12:04:38 pm
Have you opened a ticket? I think they can try to improve this particular piece of their architecture and, we hope, to just let us specify a time server in the UI.

No, I haven't. I have been frustrated with opening tickets and seeing no change in the OS related to my tickets so I kind of took upon myself to now modify the vera myself. One other thing I have done is preventing the vera from rebooting when it loses internet connection or even network connections and have been testing that...
Title: Re: How to set a local time server?
Post by: therealdb on October 30, 2018, 01:29:12 pm
I can relate to your frustration, but maybe now they're more open to feedback than in the past.

I'm curious about your solution to prevent reboot with no internet. If you don't mind sharing, it could be helpful to me, since my internet connection is very unstable (it's a wifi bridge - long story, they forgot to cover my house, so fiber will come later in 2019 - I hope)-
Title: Re: How to set a local time server?
Post by: rafale77 on October 30, 2018, 02:06:49 pm
Sure, I will share that once I confirm that it works. I've been peeling the onion and I wish the box was not so convoluted and buggy. It is carrying a lot of legacy code, some of which is conflicting with newer code or is buggy.
Title: Re: How to set a local time server?
Post by: tomtcom on October 30, 2018, 03:19:20 pm
I watch your threads a lot like taking Vera off the grid. Good luck. Maybe you could be a 300/hour contractor for them.  :)

Sent from my VS995 using Tapatalk