[SOLVED] - LUA JSON issue
Posted: Saturday 26 December 2020 15:50
Hello,
I've an issue to use json to retrieve Domoticz Data.
Thx for your help
Merry Christmas.
Christophe
The LUA Code
commandArray = {}
local rid = assert(io.popen('curl "http://192.168.0.252:8084/json.htm?type=devices&rid=201"'))
local list = rid:read('*all')
print ('TRACE')
print (list)
rid:close()
local periph = json:decode(list).result[1] << Line 9
print ('TRACE : '..periph.Name)
print ('TRACE : '..periph.Data)
return commandArray
The error message
2020-12-26 15:48:00.272 Error: EventSystem: in Test: [string "commandArray = {}..."]:9: attempt to index a nil value (global 'json')
Result of "http://192.168.0.252:8084/json.htm?type=devices&rid=201"
{
"ActTime" : 1608993866,
"AstrTwilightEnd" : "18:56",
"AstrTwilightStart" : "06:47",
"CivTwilightEnd" : "17:37",
"CivTwilightStart" : "08:06",
"DayLength" : "08:18",
"NautTwilightEnd" : "18:18",
"NautTwilightStart" : "07:25",
"ServerTime" : "2020-12-26 15:44:26",
"SunAtSouth" : "12:52",
"Sunrise" : "08:42",
"Sunset" : "17:01",
"app_version" : "2020.1 (build 11839)",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"Counter" : "40.390 m3",
"CounterToday" : "8.420 m3",
"CustomImage" : 0,
"Data" : "40.390 m3",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 5,
"HardwareName" : "VIRTUAL HARDWARE ",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveTimeout" : false,
"ID" : "82201",
"LastUpdate" : "2020-12-26 15:44:15",
"Name" : "Gaz",
"Notifications" : "false",
"PlanID" : "8",
"PlanIDs" :
[
8,
6
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "Counter Incremental",
"SwitchTypeVal" : 1,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "counter",
"Unit" : 1,
"Used" : 1,
"ValueQuantity" : "",
"ValueUnits" : "",
"XOffset" : "0",
"YOffset" : "0",
"idx" : "201"
}
],
"status" : "OK",
"title" : "Devices"
}
I've an issue to use json to retrieve Domoticz Data.
Thx for your help
Merry Christmas.
Christophe
The LUA Code
commandArray = {}
local rid = assert(io.popen('curl "http://192.168.0.252:8084/json.htm?type=devices&rid=201"'))
local list = rid:read('*all')
print ('TRACE')
print (list)
rid:close()
local periph = json:decode(list).result[1] << Line 9
print ('TRACE : '..periph.Name)
print ('TRACE : '..periph.Data)
return commandArray
The error message
2020-12-26 15:48:00.272 Error: EventSystem: in Test: [string "commandArray = {}..."]:9: attempt to index a nil value (global 'json')
Result of "http://192.168.0.252:8084/json.htm?type=devices&rid=201"
{
"ActTime" : 1608993866,
"AstrTwilightEnd" : "18:56",
"AstrTwilightStart" : "06:47",
"CivTwilightEnd" : "17:37",
"CivTwilightStart" : "08:06",
"DayLength" : "08:18",
"NautTwilightEnd" : "18:18",
"NautTwilightStart" : "07:25",
"ServerTime" : "2020-12-26 15:44:26",
"SunAtSouth" : "12:52",
"Sunrise" : "08:42",
"Sunset" : "17:01",
"app_version" : "2020.1 (build 11839)",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"Counter" : "40.390 m3",
"CounterToday" : "8.420 m3",
"CustomImage" : 0,
"Data" : "40.390 m3",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 5,
"HardwareName" : "VIRTUAL HARDWARE ",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveTimeout" : false,
"ID" : "82201",
"LastUpdate" : "2020-12-26 15:44:15",
"Name" : "Gaz",
"Notifications" : "false",
"PlanID" : "8",
"PlanIDs" :
[
8,
6
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "Counter Incremental",
"SwitchTypeVal" : 1,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "counter",
"Unit" : 1,
"Used" : 1,
"ValueQuantity" : "",
"ValueUnits" : "",
"XOffset" : "0",
"YOffset" : "0",
"idx" : "201"
}
],
"status" : "OK",
"title" : "Devices"
}