Example: Change time/date from LUA script on LM2

Task

How to set internal time/date from LUA script, which would give the possibility to keep it updated with internet (with a wget for example; or allowing NTP protocol on Ethernet)?

 

Note! NTP is enabled on LM2 by default and once connected to Internet, LM2 time is being updated automatically.

 

Function

Add the following function in User Function Library and call it with specific parameters whenever you want to change time and date parameters.

Source code    
  1. function setdate(year, mon, day, hour, min, sec)
  2. os.execute(string.format("date -s '%d-%d-%d %d:%d:%d'", year, mon, day, hour, min, sec))
  3. os.execute('hwclock -u -w')
  4. end

 

Update LogicMachine system time from KNX telegram

You will need two objects – date and time.

Source code    
  1. date = grp.getvalue('date_object')
  2. time = grp.getvalue('time_object')
  3.  
  4. setdate(date.year, date.month, date.day, time.hour, time.minute, time.second)