Posts: 411
Threads: 103
Joined: Oct 2016
Reputation:
9
01.07.2019, 12:52
(This post was last modified: 01.07.2019, 13:51 by Thomas.)
Hello
I've a water gauge which returns pulses.
I want to show water consumption for the last 1 hour.
Do you have any idea how to do it in LM way?
If no is this correct hack?
Code:
object=grp.find('1/1/1')
obj_addressraw = object.dstraw
query = "
select count() from FROM objectlog WHERE objectlog.address="..obj_addressraw.." AND logtime>=os.microtime()-3600"
count = db:getall(query)
No, it isn't.
Object doesn't have dstraw. How to convert address to dstraw integer?
Bingo! knxlib.encodega('1/1/1')
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Posts: 411
Threads: 103
Joined: Oct 2016
Reputation:
9
01.07.2019, 14:02
(This post was last modified: 01.07.2019, 14:08 by Thomas.)
Code:
function ecl_get_last_hour_counter(ls_address)
local obj_addressraw = knxlib.encodega(ls_address)
local query = "select count() as pulses_per_hour FROM objectlog WHERE datahex='01' AND objectlog.address="..obj_addressraw.." AND logtime>="..tostring(os.microtime()-3600)
local count = db:getall(query)
return count[1].pulses_per_hour
end
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
You can use db:getone to get value of the first column of the first row.
Posts: 411
Threads: 103
Joined: Oct 2016
Reputation:
9
(01.07.2019, 16:06)admin Wrote: You can use db:getone to get value of the first column of the first row.
Thank you. Are there descriptions of these libraries somewhere? Maybe I'm overlooking something but it's always hard to me to use your libraries because of lack of documentation.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Posts: 411
Threads: 103
Joined: Oct 2016
Reputation:
9
(02.07.2019, 12:41)admin Wrote: There's no public documentation for this since most users don't need to access database directly. You can find function description here: http://openrb.com/docs/db.htm
Thank you
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259