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.

http post request issues
#1
I'm trying to send energy data through an API by using http.request:

Code:
local dateTime=os.date("%Y-%m-%dT%H:%M")

local http = require("socket.http")
local ltn12 = require("ltn12")

local data = grp.getvalue('360_001_OE001 - Heat energy E1')

body = [[{
"meterID": "0501e479-2a12-45b4-8cb6-505ced85428f",
"values": ["]]..dateTime..[[,]]..data..[[]
}]]

local response_body = {}

res, code, headers, status = http.request{
url = "https://www.energinet.net/apiImport/data",
method = "POST",
headers ={
["Authorization"] = "Bearer xxxxx",
["Content-Type"] = "application/json",
["Accept"] = "application/json"
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response_body)
}

log(response_body)
log(body)
log(res,code,headers,status)

log(res,code,headers, status) returns: 
* arg: 1 * nil * arg: 2 * string: Try again * arg: 3 * nil * arg: 4 * nil
response_body is empty.

Headers are as specified by the API-provider. 

Any ideas what might be wrong? Hiow should I understand the "Try again" from log(code)?
Reply
#2
Check that gateway and DNS settings are valid in System config > Network > Interfaces > eth0.
Reply
#3
They should be. The LM5 is online.
Reply
#4
I think your body is not a valid json format, you are missing a " in the values property
Reply
#5
Thanks for the replies. You are right, I saw that one, but had to add another DNS to be able to communicate. Also I had to add content-length even if it was not specified by the API-provider. Thanks for notifying me about DNS-settings, which was part of the problem.
Reply


Forum Jump: