I nearly have this running – I could do with a little help though!
The latest LUA has more than one timer – so you can spare one for a clock.
Here’s the basic idea – you can run this as is if you want…
tmr.alarm(1,1000, 1, function()
if second>=60 then
if minute>=60 then
if hour>=24 then
if day>=7 then day=0
There you go – THAT was easy !!
It’s also quite easy to get the time from a server. I made my own PHP page and put it on any old hosting – I’ll not make that public or my server will get stoned to death but it doesn’t take much of an imagination to go get the time. In this example I’ve missed out month and year but you get the idea. What I would do it get the time every night maybe 2am from a real clock (and on power up of course)
In my case from my web code, I get a string back which contains….” lots of stuff ;timestr=22:04:02 10-12-2014; more stuff”
So – I want to extract at least 3 and more likely all 6 numbers out of there – so I can punch them into my variables above. I can do it one at a time but it would be NEAT if Lua could return 6 variables at once… like….
Except of course that the last bit of that is rubbish because I’m rubbish at regular expressions – I don’t suppose any of you Lua masters out there would know how to take that string above and convert it into the numbers I want? I promise if someone provides a working solution, I’llrepay by publishing the source of my PHP page – which actually returns a lot more in the string.
Why not figure out how to access an NTP server? I find them slow – this is instant and I get more useful info back.