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.

massive data logging
#7
(14.09.2022, 11:33)admin Wrote: You only need to create a bucket once. It will store your data for a certain amount of time. There are examples of sending data to influx v2 in the topic I've linked to.
The setup part is a bit complicated but you only have to do it once Smile

I accepted the challenge! Smile
But right now I get error messages:


* arg: 1
  * string: error sending to influx
* arg: 2
  * string: {"code":"invalid","message":"at line 1:36: cannot parse value for field key \"value\": invalid float value syntax (check rejected_points in your _monitoring bucket for further information)"}
* arg: 3
  * number: 400
* arg: 4
  * string: rawdata,name=ora,addr=33/1/9 value=10:57


and


* arg: 1
  * string: error sending to influx
* arg: 2
  * string: {"code":"invalid","message":"at line 1:47: cannot parse value for field key \"value\": invalid bool value \"Thu\" (check rejected_points in your _monitoring bucket for further information)"}
* arg: 3
  * number: 400
* arg: 4
  * string: rawdata,name=giornomeseanno,addr=33/1/8 value=Thu 15-09-2022


the script I used is the following, can you help me?

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 = 'https://europe-west1-1.gcp.cloud2.influxdata.com/api/v2/write?bucket=XX&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 XXXXXXXXXXXXXXXXXXX'
    }
  })

  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()
Reply


Messages In This Thread
massive data logging - by gdimaria - 05.09.2022, 16:22
RE: massive data logging - by admin - 06.09.2022, 10:08
RE: massive data logging - by gdimaria - 07.09.2022, 07:42
RE: massive data logging - by admin - 07.09.2022, 07:47
RE: massive data logging - by gdimaria - 14.09.2022, 11:14
RE: massive data logging - by admin - 14.09.2022, 11:33
RE: massive data logging - by gdimaria - 15.09.2022, 09:05
RE: massive data logging - by admin - 15.09.2022, 09:23
RE: massive data logging - by gdimaria - 15.09.2022, 10:04
RE: massive data logging - by admin - 15.09.2022, 12:55
RE: massive data logging - by gdimaria - 16.09.2022, 10:26
RE: massive data logging - by admin - 19.09.2022, 06:10

Forum Jump: