Logic Machine Forum
Saving a date - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Saving a date (/showthread.php?tid=73)



Saving a date - RSV4 - 03.09.2015

Hi all,

what is the best way of saving a date within the LM? Saving it in a group address?

I could check this myself tonight, but will ask this now anyway: Is the required data type 11.001 and/or 19.001 (date with time) available in the LM3?

Best regards,
Robin


RE: Saving a date - admin - 03.09.2015

Depends on your task, you can use group address (both date and time types are supported) or save to storage (you can save either a formatted string or Lua table).

This example might be useful:
http://openrb.com/example-write-lm2-datatime-to-knx-group-addresses/


RE: Saving a date - RSV4 - 03.09.2015

Perfect, thank you. Will use group address as in your example.


RE: Saving a date - gtsamis - 11.06.2018

(03.09.2015, 09:11)admin Wrote: Depends on your task, you can use group address (both date and time types are supported) or save to storage (you can save either a formatted string or Lua table).

This example might be useful:
http://openrb.com/example-write-lm2-datatime-to-knx-group-addresses/

Can you please provide the grp.write function for DPT 19.001 to use with the above script


RE: Saving a date - Erwin van der Zwart - 11.06.2018

Hi,

DPT 19 is not available in the controller, only way to do it is to use the 250 byte object (raw dpt) and build the telegram yourself.

You can try this sample, it's not 100% filled according the standard but for time and date it should work, if you want it 100% correct you need to complete OCT2 and OCT1
Code:
now = os.date('*t')
wday = now.wday == 1 and 7 or now.wday - 1
OCT08 = now.year - 1900 
OCT07 = now.month
OCT06 = now.day
OCT05 = bit.bor(bit.lshift(wday, 5), now.hour)
OCT04 = now.min
OCT03 = now.sec
OCT02 = 0 -- subfields like working day and dst not specified in this sample
OCT01 = 0 -- subfields like quality of clock not specified in this sample

knx_raw_dpt = string.char(OCT08) .. string.char(OCT07) .. string.char(OCT06) .. string.char(OCT05) .. string.char(OCT04) .. string.char(OCT03)  .. string.char(OCT02)  .. string.char(OCT01)
grp.write('1/1/1', knx_raw_dpt)
BR,

Erwin


RE: Saving a date - admin - 12.06.2018

You should use bit operations Smile
Code:
OCT05 = bit.bor(bit.lshift(now.wday, 5), now.hour)



RE: Saving a date - Erwin van der Zwart - 12.06.2018

(12.06.2018, 07:08)admin Wrote: You should use bit operations Smile
Code:
OCT05 = bit.bor(bit.lshift(now.wday, 5), now.hour)

I was looking for this but could not figure it out so soon, the solution with functions works but your solution is cleaner (:

I updated the sample

Thanks!

BR,

Erwin