Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:39 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Setting RTC From NTP

Author Message
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 03:30am 02 Jan 2024
Copy link to clipboard 
Print this post

Hi All and belated seasons greetings.

I'm fiddling with getting the Date/Time from NTP, having retrieved the Daylight Saving status from OpenWeather.
NTP automatically updates DATE$ & TIME$ but, as far as I can see, one must then update the RTC by say :
RTC SETTIME MID$(Date$,7,4)+","+ MID$(Date$,4,2)+","+MID$(Date$,1,2)+"," +MID$(Time$,1,2)+"," +MID$(Time$,4,2)+"," +MID$(Time$,7,2).

Is there sense in having a command like "RTC SETTIME NOW". It would be up to the user to only use this before the internal clock drifted (or have I lost the plot again?).

Cheers,

Andrew
Edited 2024-01-02 13:31 by Andrew_G
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 04:43am 02 Jan 2024
Copy link to clipboard 
Print this post

There is probably a better way , use Val(Mid$() to extract each value from DateTime$(now) and insert them in RTC SETTIME
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 05:20am 02 Jan 2024
Copy link to clipboard 
Print this post

I don't have a WEBmite with an external RTC to test but this should do it:
RTC SETTIME LEFT$(DATETIME$(NOW),6)+RIGHT$(DATETIME$(NOW),9)



Jim
VK7JH
MMedit   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 05:32am 02 Jan 2024
Copy link to clipboard 
Print this post

> RTC SETTIME LEFT$(DATETIME$(NOW),6)+RIGHT$(DATETIME$(NOW),9)
Error : Date/time format
>

This might do it.
sub RTCSet
 local integer y,m,d,h,min,s
 y = val(mid$(datetime$(now),7,4))
 m = val(mid$(datetime$(now),4,2))
 d = val(mid$(datetime$(now),1,2))
 h = val(mid$(datetime$(now),12,2))
 min = val(mid$(datetime$(now),15,2))
 s = val(mid$(datetime$(now),18,2))
 RTC SETTIME y,m,d,h,min,s
end sub


Edit
Repaired a dumb mistake, had "m" twice
Edited 2024-01-02 15:57 by phil99
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 06:33am 02 Jan 2024
Copy link to clipboard 
Print this post

I can't count!

try
rtc settime LEFT$(DATETIME$(NOW),6)+RIGHT$(DATETIME$(NOW),11)

VK7JH
MMedit   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 06:52am 02 Jan 2024
Copy link to clipboard 
Print this post

Yes, that is much easier.
When I searched the manual the RTC chapter made no mention of using a string, just coma separated values.
Though it is in the Command section, next revision perhaps?

Edit
This also works.
rtc settime date$+" "+time$

The above uses a 4 digit year without a problem, the Command description only shows 2 as in Jim's example.
Edited 2024-01-02 17:16 by phil99
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 07:41am 02 Jan 2024
Copy link to clipboard 
Print this post

If it is happy with the 4 digit year
RTC SETTIME DATETIME$(NOW)
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 07:10pm 02 Jan 2024
Copy link to clipboard 
Print this post

Thanks Jim and Phil.
(I too had assumed that it wouldn't accept a 4 digit year)
I'm thankful on two counts, one that MMBasic had the feature and two that you found it.

Cheers,

Andrew
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 02:49am 03 Jan 2024
Copy link to clipboard 
Print this post

Setting RTC From GPS
A little off topic but may be useful if a GPS module is configured.
> If gps(valid) then rtc settime gps(date)+" "+gps(time)
> ? time$, gps(time)
13:43:19        13:43:19
>


Edit
For better synchronization.
If gps(valid) then
 t$=gps(time)
 do while t$=gps(time)
 loop
 rtc settime gps(date)+" "+gps(time)
endif

Edited 2024-01-03 13:26 by phil99
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4235
Posted: 11:10am 03 Jan 2024
Copy link to clipboard 
Print this post

This should be in the user manual.
RTC SETTIME DATETIME$(NOW)

PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024