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.

influxdb
#39
(12.08.2024, 07:38)admin Wrote: Post your script.

Code:
local http = require('socket.http')
http.TIMEOUT = 5

local url = 'http://192.168.100.20:8086/api/v2/write?bucket=ets&org=Matrix'
local token = 'deleted'
local influxtable = 'rawdata'
local tagobjs = grp.tag('influxdb')

local function escape(value)
  return tostring(value):gsub('[\\ ,=]', '\\%1')
end

local objects = {}

for _, obj in ipairs(tagobjs) do
  objects[ obj.id ] = {
    name = escape(obj.name),
    datatype = obj.datatype,
  }
end

local function send(name, addr, value)
  local body

  if type(value) == 'boolean' then
    body = string.format('%s,name=%s,addr=%s state=%s', table, name, addr, value)
  elseif type(value) == 'number' then
    body = string.format('%s,name=%s,addr=%s value=%s', table, name, addr, value)
  elseif type(value) == 'string' then
    body = string.format('%s,name=%s,addr=%s string=%q', table, name, addr, value)
  else
    log('invalid data type', addr, type(value))
    return
  end

  local res, code = http.request({
    url = url,
    method = 'POST',
    body = body,
    headers = {
      Authorization = 'Token ' .. token
    }
  })

  if code ~= 204 then
    log('error sending to influx', res, code, body)
  end
end

local busclient = require('localbus').new(60)
busclient:sethandler('groupwrite', function(event)
  local obj = objects[ event.dstraw ]

  if obj then
    local value = busdatatype.decode(event.datahex, obj.datatype)

    if value ~= nil then
      send(obj.name, event.dst, value)
    end
  end
end)

while true do
  busclient:loop(60)
end
Reply


Messages In This Thread
influxdb - by mischa - 12.08.2018, 07:03
RE: influxdb - by admin - 13.08.2018, 11:25
RE: influxdb - by mischa - 13.08.2018, 12:44
RE: influxdb - by eirik - 19.11.2019, 18:49
RE: influxdb - by myg - 28.05.2020, 16:47
RE: influxdb - by thomasoppida - 14.12.2021, 09:07
RE: influxdb - by admin - 14.12.2021, 10:00
RE: influxdb - by thomasoppida - 14.12.2021, 13:07
RE: influxdb - by admin - 14.12.2021, 14:02
RE: influxdb - by jensmagnar - 23.12.2021, 14:56
RE: influxdb - by admin - 23.12.2021, 14:59
RE: influxdb - by jensmagnar - 06.01.2022, 22:12
RE: influxdb - by Re-G - 07.01.2022, 11:34
RE: influxdb - by admin - 07.01.2022, 12:12
RE: influxdb - by Re-G - 07.01.2022, 13:38
RE: influxdb - by sx3 - 06.10.2022, 16:14
RE: influxdb - by admin - 07.10.2022, 05:33
RE: influxdb - by sx3 - 07.10.2022, 14:31
RE: influxdb - by sx3 - 12.10.2022, 06:05
RE: influxdb - by admin - 12.10.2022, 06:13
RE: influxdb - by sx3 - 17.10.2022, 16:41
RE: influxdb - by admin - 18.10.2022, 06:36
RE: influxdb - by tigi - 27.10.2022, 14:16
RE: influxdb - by admin - 28.10.2022, 06:06
RE: influxdb - by tigi - 28.10.2022, 07:25
RE: influxdb - by sx3 - 23.12.2022, 10:06
RE: influxdb - by admin - 23.12.2022, 10:13
RE: influxdb - by DGrandes - 04.01.2024, 09:56
RE: influxdb - by admin - 04.01.2024, 12:01
RE: influxdb - by DGrandes - 04.01.2024, 13:11
RE: influxdb - by DGrandes - 12.01.2024, 12:08
RE: influxdb - by admin - 12.01.2024, 15:08
RE: influxdb - by DGrandes - 13.01.2024, 10:52
RE: influxdb - by admin - 13.01.2024, 11:02
RE: influxdb - by sck - 09.08.2024, 22:40
RE: influxdb - by admin - 12.08.2024, 07:10
RE: influxdb - by sck - 12.08.2024, 07:28
RE: influxdb - by admin - 12.08.2024, 07:38
RE: influxdb - by sck - 12.08.2024, 07:42
RE: influxdb - by admin - 12.08.2024, 08:26
RE: influxdb - by sck - 12.08.2024, 08:31
RE: influxdb - by admin - 12.08.2024, 08:49

Forum Jump: