Set Annex date and time from computer

All that relates to Javascript, CSS, HTML, ....
Post Reply
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Set Annex date and time from computer

Post by Electroguard »

I had a snippet from you a few years ago Francesco that set Annex date and time from the computers date and time using javascript.
It stopped working some years later, and was eventually lost a few dead hdd's ago, so I can't even try to bring it up to date.

My Sentry server with its RTC module has just died.
It acted as a local timeserver on my isolated Annex subnet, sending time and date to every device at bootup and nightly.

The standby Sentry server has taken over most of the Sentry functionalities, but doesn't have an RTC module so can't act as Time server, therefore the date and time of networked devices is becoming chaotic.

Unfortunately we have away appointments every day this week, so I will not be able to sort out Sentry RTC any time soon.
Would you happen to have a working javascript snippet still in your box of tricks for setting Annex date and time from browser date/time ?
If so, I could quickly turn the standby Sentry into a Time server synced to computers internet date/time.
.
User avatar
cicciocb
Site Admin
Posts: 1989
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 426 times
Been thanked: 1329 times
Contact:

Re: Set Annex date and time from computer

Post by cicciocb »

Hi Robin, I couldn't locate it, so I just rewrote it. 😄

Code: [Local Link Removed for Guests]

'Snippet to sync the date of the module using the date coming from the browser
'the Output Page must be open before running the script (otherwise there will be no effects)
A$ = |{|
A$ = A$ + |const d = new Date();|
A$ = A$ + |const year = d.getFullYear() % 100;|
A$ = A$ + |const month = d.getMonth() + 1;| ' Months are zero-based, so add 1|
A$ = A$ + |const day = d.getDate();|
A$ = A$ + |const hours = d.getHours();|
A$ = A$ + |const minutes = d.getMinutes();|
A$ = A$ + |const seconds = d.getSeconds();|
A$ = A$ + |const Settime = `SETTIME ${year},${month},${day},${hours},${minutes},${seconds}`;|
A$ = A$ + |connection.send("cmd:immediate" + Settime);|
A$ = A$ + |}|
jscall a$

User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Set Annex date and time from computer

Post by Electroguard »

Thank you very much Francesco, you just saved my bacon!
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Set Annex date and time from computer

Post by Electroguard »

Hi Francesco, your Annex Config Time Zone should be the same as mine near Bordeaux.
But although the javascript time/date snippet you gave me works fine, it is always an hour out (an hour early).
Wasn't important, cos just added 1 hour to the temporary standby time server so it could keep all devices synced to the correct time.
I actually include a remmed-out copy of the sentry time zone code at the top of all device programs, for easy copy and paste into their Configs.

But I've just replaced the failed Sentry with an identical device which can connect and interact ok. It uses the original RTC module, and the same time code as the original TimeServer for the isolated subnet, but again the time is 1 hour early.

Which makes me think that maybe the Sentry, and perhaps all the other networked devices, may have an incorrect Config Time Zone code.
Presumably your Config Time Zone code is correct, and would be same as mine near Bordeaux, so could you paste it for me please... it will let me definitely rule out another variable.
User avatar
cicciocb
Site Admin
Posts: 1989
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 426 times
Been thanked: 1329 times
Contact:

Re: Set Annex date and time from computer

Post by cicciocb »

This is for the whole central europe

Code: [Local Link Removed for Guests]

CET-1CEST,M3.5.0,M10.5.0/3
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Set Annex date and time from computer

Post by Electroguard »

Thanks ... yeah, that was exactly what I had, but at least it ruled out the possibility of a wrong character messing things up.
User avatar
cicciocb
Site Admin
Posts: 1989
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 426 times
Been thanked: 1329 times
Contact:

Re: Set Annex date and time from computer

Post by cicciocb »

Probably the time returned by the web browser already include the DST (winter/summer)
Post Reply