This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Counting pulses, showing last 1hr total
#1
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
Reply
#2
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
Reply
#3
You can use db:getone to get value of the first column of the first row.
Reply
#4
(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
Reply
#5
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
Reply
#6
(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
Reply


Forum Jump: