Hello,
I'm trying out this influx integration. I get the following error in the error-log.
It managed to write about 20 adresses to influx, before failing.
It's a resident script with 0 deley.
And the code (a little bit copy paste here and there from this thread)
I'm trying out this influx integration. I get the following error in the error-log.
It managed to write about 20 adresses to influx, before failing.
It's a resident script with 0 deley.
Quote:Resident script:15: attempt to index local 'dt' (a nil value)
stack traceback:
Resident script:15: in function 'get_value'
Resident script:20: in function <Resident script:18>
Library localbus: in function ''
Library localbus: in function ''
Library localbus: in function 'step'
Resident script:66: in function 'run_loop'
And the code (a little bit copy paste here and there from this thread)
Code:
local socket = require('socket')
local http = require('socket.http')
http.TIMEOUT = 5
local dt_cache = {}
function get_value(addr, datahex)
local dt = dt_cache[addr]
if(not dt) then
dt = grp.find(addr)
dt_cache[addr] = dt
end
return knxdatatype.decode(datahex, dt.datatype), dt
end
function knx_callback(event)
local addr = event.dst
local value, dt = get_value(addr, event.datahex)
send_metric('rawdata', dt.name, addr, value)
end
function send_metric(table, name, addr, value)
if name == nil or name == '' then
return
end
name = string.gsub(name, ' ', '\\ ')
local url = 'http://192.168.1.200:8086/api/v2/write?bucket=XXX&org=XXX'
local body
if type(value) == 'boolean' then
body = string.format('%s,name=%s,addr=%s state=%s', table, name, addr, value)
else
-- most likely number
body = string.format('%s,name=%s,addr=%s value=%s', table, name, addr, value)
end
local res, code = http.request({
url = url,
method = 'POST',
body = body,
headers = {
Authorization = 'Token XXXXX'
}
})
if code ~= 204 then
log('error sending to influx', res, code, body)
end
end
function run_loop()
local bus = require('localbus').new(1)
bus:sethandler('groupwrite', knx_callback)
local busfd = socket.fdmaskset(bus:getfd(), 'r')
while(true) do
res, fbus = socket.selectfds(10, busfd)
if(fbus) then
bus:step()
end
end
end
run_loop()