Yes, I have alot of GA that is beeing used outside om LM.
Tried your code but it gives me following error
Also wonder how the string would like like if I want to transmit a modified Timestamp, and where should it be placed?
For example (strTime = os.time() + 3600)
Tried your code but it gives me following error
Also wonder how the string would like like if I want to transmit a modified Timestamp, and where should it be placed?
For example (strTime = os.time() + 3600)
Code:
* arg: 1
* string: error sending to influx
* arg: 2
* string: {"code":"invalid","message":"unable to parse 'rawdata,name=Heru\\ -\\ Max\\ exhaust\\ fan\\ speed,\\ EC,addr=2/3/5 value=72': missing tag value"}
* arg: 3
* number: 400
* arg: 4
*
Code:
local socket = require('socket')
local http = require('socket.http')
http.TIMEOUT = 5
local dt_cache = {}
function get_value(addr, datahex)
local obj = dt_cache[addr]
if obj == nil then
obj = grp.find(addr)
dt_cache[ addr ] = obj or false
end
if obj then
return knxdatatype.decode(datahex, obj.datatype), obj
end
end
function knx_callback(event)
local addr = event.dst
local value, obj = get_value(addr, event.datahex)
if value ~= nil then
send_metric('rawdata', obj.name, addr, value)
end
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 XXXX'
}
})
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()