Write LM2 data/time to KNX group addresses
Example: Write LM2 data/time to KNX group addresses
Task
Send date and time from Logic Machine 2 to KNX group addresses 1/1/1 and 1/1/2 respectively
Resident program
Add the following code in the resident script with specific time interval after which you want to update date and time values on the bus.
- -- get current data as table
- now = os.date('*t')
-
- -- system week day starts from sunday, convert it to knx format
- wday = now.wday == 1 and 7 or now.wday - 1
-
- -- time table
- time = {
- day = wday,
- hour = now.hour,
- minute = now.min,
- second = now.sec,
- }
-
- -- date table
- date = {
- day = now.day,
- month = now.month,
- year = now.year,
- }
-
- -- write to bus
- grp.write('1/1/2', time, dt.time)
- grp.write('1/1/1', date, dt.date)
Updated script to handle KNX 19.001 datatype
- -- get current data as table
- now = os.date('*t')
-
- -- system week day starts from sunday, convert it to knx format
- wday = now.wday == 1 and 7 or now.wday - 1
-
- -- time table
- time = {
- day = wday,
- hour = now.hour,
- minute = now.min,
- second = now.sec,
- }
-
- -- date table
- date = {
- day = now.day,
- month = now.month,
- year = now.year,
- }
-
- -- write to bus
- --grp.write('1/1/2', time, dt.time)
- --grp.write('1/1/1', date, dt.date)
-
- myyear = (now.year-1900)
- -- source http://www.knx.org/fileadmin/template/documents/downloads_support_menu/KNX_tutor_seminar_page/Advanced_documentation/05_Interworking_E1209.pdf
-
- -- byte 6
- --F (msb) -- fault
- --WD -- workday (requires a calendar..)
- --NWD - workday not valid
- --NY --no year
- --ND -- no day
- --NDoW -- no dayof week
- --NT - notime
- --SUTI (lsb)-- summertime
- byte7 = bit.lshift(1,5)
-
- if now.isdst then
- byte7 = byte7 + 1
- end
-
- -- byte 7
- --CLQ (msb)-- 1 = clock with extern sync
- byte8 = bit.lshift(1,7)
-
- -- year (1900 = 0, 2155 = 255), month, dayofmonths, dayofweek