Logic Machine Forum
Counting pulses, showing last 1hr total - 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: Counting pulses, showing last 1hr total (/showthread.php?tid=2138)



Counting pulses, showing last 1hr total - Thomas - 01.07.2019

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')


RE: Counting pulses, showing last 1hr total - Thomas - 01.07.2019

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



RE: Counting pulses, showing last 1hr total - admin - 01.07.2019

You can use db:getone to get value of the first column of the first row.


RE: Counting pulses, showing last 1hr total - Thomas - 02.07.2019

(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.


RE: Counting pulses, showing last 1hr total - admin - 02.07.2019

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


RE: Counting pulses, showing last 1hr total - Thomas - 02.07.2019

(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