I try to get some data from a http:request in a LUA scene.
I have the following code:
local strLonoID = fibaro:getGlobalValue ("LonoID");
print ("LonoID = ", strLonoID)
local Temp1 = fibaro:getGlobalValue ("LonoTemp1");
print ("LonoTemp1 = ", Temp1)
local http = net.HTTPClient()
http:request('http://lonobox.com/api/index.php?id=100003523', {
success = function(current)
--fibaro:debug(json.encode(current)) --werkt
if current.status == 200 then
print('Data Receiving: ', current.status) -- werkt
print('CurrentData: ', current.data) -- werkt
local result = json.decode(current.data)
print ('Result :', result)
--Local temp2 = result.(["CurrentData"]["200003523"]["temperature"])
--local temp2 = result.200003523.temperature
--print ('Temp2 :', temp2)
--
else
fibaro:debug(current.status)
end
end
})
and i have as output:
[DEBUG] 17:13:32: LonoID = 100003523 [DEBUG] 17:13:32: LonoTemp1 = 2 [DEBUG] 17:13:32: Data Receiving: 200 [DEBUG] 17:13:32: CurrentData: [[],{"200003523":{"temperature":"23.2","humidity":"46"}},{"400004105":{"wind-speed":"0.2","wind-gust":"1.5","wind-direction":"SE"}},{"100003523":{"barometer":"1014"}}] [DEBUG] 17:13:32: Result : table: 0x9c98200
I want to store the values in global variables. I do not know how to proceed from here.
Thx in advance.
Fons