summaryrefslogtreecommitdiff
path: root/update_time.lua
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2019-12-17 13:01:41 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2019-12-17 13:01:41 -0500
commit3c4207c4aa55644c35600d7bdc2fcbba2b757824 (patch)
tree1f3e14d952bdb8c7bd51c7b2cfee46520bbcd820 /update_time.lua
downloadnodeMCU_rf_source_lmx2487-3c4207c4aa55644c35600d7bdc2fcbba2b757824.tar.gz
nodeMCU_rf_source_lmx2487-3c4207c4aa55644c35600d7bdc2fcbba2b757824.zip
init
Diffstat (limited to 'update_time.lua')
-rw-r--r--update_time.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/update_time.lua b/update_time.lua
new file mode 100644
index 0000000..247f9aa
--- /dev/null
+++ b/update_time.lua
@@ -0,0 +1,26 @@
+function update_time()
+ -- Update time
+ -- note that rtctime.get() provided updates only if time was set at least once
+ -- either with rtctime.set() or with sntp.sync() which sets it internally
+ sec, usec = rtctime.get()
+ sec = sec + uts_offset;
+ if ( sec > 0) then
+ tm = rtctime.epoch2cal(sec)
+ -- print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
+ dstr = string.format("%04d/%02d/%02d", tm["year"], tm["mon"], tm["day"])
+ tstr = string.format("%02d:%02d:%02d", tm["hour"], tm["min"], tm["sec"])
+ else
+ sec = 0;
+ dstr = "time is"
+ tstr = "unknown"
+ end
+
+ time_tmr:start()
+end
+
+-- set up timer for time update
+time_tmr=tmr.create()
+time_tmr:register(time_update_interval, tmr.ALARM_SEMI, function() update_time() end)
+
+print("--- Starting Time Updates ---")
+time_tmr:start()