Hi everyone.
I have hit a stumbling block getting data from Home Center 3 into InfluxDB v2. I have setup InfluxDB correctly as testing using curl from a Ubuntu server works a treat, data manually imports fine.
curl --request POST "http://172.16.3.101:8086/api/v2/write?org=HomeLAB&bucket=HC3&precision=ns" --header "Authorization: Token 019gWkLe2DJ8jsOvav0TvPjJyILiYjO3UctuHpgrNfGIWmgXrgPmenQj8UXAuaCfdmUa-CUA00gSid4Vh0VPkw==" --header "Content-Type: text/plain; charset=utf-8" --header "Accept: application/json" --data-binary 'temperature,sensor_id=28 temperature=24.3'
When I convert this into LUA for HC3 I get a status 404 error and a message relating to bucket not found. The URL formed by the LUA code is correct as the output shows it is the same as the URL used when testing with curl.
Are there any Home Center 3 gurus on the forum? The LUA code for HC3 is slightly different to LUA, I have posted the function I use to send data to InfluxDB, if anyone can take a look and see if there are any glaring errors that would be great.
function sendDataToInflux(body)
-- local url = "http://" .. host .. ":" .. port .. "/api/v2/write?org=" .. dbOrg .. "&bucket=" .. dbName .. "&precision=ns"
local url = "http://172.16.3.101:8086/api/v2/write?org=HomeLAB&bucket=HC3&precision=ns"
local headers = {
["Authorization"] = "Token 019gWkLe2DJ8jsOvav0TvPjJyILiYjO3UctuHpgrNfGIWmgXrgPmenQj8UXAuaCfdmUa-CUA00gSid4Vh0VPkw==",
["content-type"] = "application/binary; charset=utf-8",
["Accept"] = "application/json"
}
fibaro.debug("Scene55", "url: " .. url)
fibaro.debug("Scene55", "headers: " .. json.encode(headers))
fibaro.debug("Scene55", "body: " .. body)
local http = net.HTTPClient()
http:request(
url,
{
options = {
method = "POST",
data = body,
headers = headers
},
success = function(response)
if (response.status < 200 or response.status >= 300) then
-- print(json.encode(response))
fibaro.debug("Scene55", "Response Status: " .. response.status)
fibaro.debug("Scene55", "Response Data: " .. response.data)
fibaro.debug("Scene55", "Headers: " .. json.encode(response.headers))
print("Wrong status '" .. response.status .. "' in response!")
else
fibaro.debug("Scene55", "Success: " .. response.data)
end
end,
error = function(response)
-- print("Connection error: " .. message)
fibaro.debug("Scene55", "Connection error: " .. response)
end
}
)
end
The various debug outputs are detailed below.
Response Status: 404
Response Data: {"code":"not found","message":"bucket not found"}
Headers: {"X-Platform-Error-Code":"not found","Content-Length":"49","Date":"Sat, 01 Jun 2024 23:58:39 GMT","X-Influxdb-Version":"v2.7.6","Content-Type":"application/json; charset=utf-8","X-Influxdb-Build":"OSS"}
Thanks in advance for any advise that can be offered