General area when it fits no where else

Moderator: Mmiscool

User avatar
By PhilTilson
#66388 Well, it certainly doesn't NEED to go to the web to get the time info each time. I have set my time by connecting to the web, then disconnected. Multiple calls to the TIME() function return the correct time, so there is obviously some kind of internal RTC. How long this would stay accurate I can't say!

Phil
User avatar
By heckler
#66401 Phil,

WOW!! That is great news!! I have previously jumped through hoops to implement my own clock routine to keep track of time... But then I was trying to prevent having to access the internet unnecessarily just to check if a certain hour had arrived (for example)

Code: Select alltimer 60000, [NextMin]

bla = time()
shh = mid(bla,12,2)         'hour  this statment extracts the hours value
smm = mid(bla,15,2)         'min   this statment extracts the minutes
hh = val(shh)               ' this converts the hours from string to numeric
mm = val(smm)               ' this converts the minutes from string to numeric


Code: Select all[NextMin] 
let  mm = mm + 1
if mm = 60 then
  mm = 0
  hh = hh + 1
  if hh = 24 then hh = 0
end if


But then that begs the question... If the internet is available does it access the internet IF it is available??

So if I have a routine that checks for a given time to turn on/off a relay (or whatever) and the module is connected is it going to access the internet every time I do a time() function??

Now I am more confused than before :?

IF there really is an internal clock that keeps running, it would be nice to be able to tell the module how often to actually go get an accurate time value from NTP.

With the above routine being called every second I have seen that the clock keeps pretty good time (+/- 60 seconds) by only doing a time() every 12 or 24 hours.

confused
dwight
User avatar
By heckler
#66405 Ok so I have been thinking more on this...

Ideally (hopefully) there is an internal "system" variable or register that contains the time value that was retrieved from NTP ,or what ever time server, if you specified one in the time.setup(Zone,DST,{server}).

This way one could just do a time() as often as you wanted to make sure your clock was up to date and then get the current "esp module" time by reading the given time register.

For example there is a "system" register that one can read and write to that represents the "wifi" name and "password" such that one can save these values in your program (not just from the SETUP page.

regards
dwight
In fact I would love to have a list of all "system" registers that we can use in our programs.
User avatar
By heckler
#66428 I have confirmed what Phil found.

My test:
load this bit of code onto a nodeMCU module.
Code: Select allmemclear
time.setup(-7,0)
delay 3000
'
[Main]
bla = time()
serialprintln bla
delay 2000
[Wait]
btn = io(pi,d3)
if btn = 0 then
  goto [Main]
else
  goto [Wait]
endif

note: this code uses the FLASH button on the nodemcu module to cause the esp to serial print the time.

Watch your serial monitor program to make sure that the module has gotten the correct time from NTP.
Each time you press the FLASH button it will print the time.

Go turn off your internet (I just unplugged my DSL router, which also provides my local wifi)
Each time you press the FLASH button the module still prints the correct time and you can clearly see the seconds updating and, if you wait long enough, also the min, hours, etc.

So again the question for me is what causes the module to actually go to NTP for time??
Does it try and if the internet is unavailable then it continues on with the previous time?

What system vars are keeping track of the time values??

help us mister wizard!! :mrgreen:

dwight