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"
}
[SOLVED] - LUA JSON issue
Moderator: leecollings
[SOLVED] - LUA JSON issue
Last edited by bruch05 on Saturday 26 December 2020 17:09, edited 1 time in total.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA JSON issue
You need a statement to define the json object:
Code: Select all
json = require "JSON"
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: LUA JSON issue
Hello,
Thx for your help
Now i get error messages, I think JSON is not (correctly) installed on my Domorticz / Synology implementation.
Version: 2020.1 (build 11839)
Build Hash: 139d994e5-modified
Compile Date: 2020-03-27 06:53:01
dzVents Version: 3.0.1
Some advises ?
Thx by advance
Christophe
2020-12-26 16:29:10.201 Error: EventSystem: in Test: [string "commandArray = {}..."]:3: module 'JSON' not found:
2020-12-26 16:29:10.201 no field package.preload['JSON']
2020-12-26 16:29:10.201 no file '/usr/local/share/lua/5.3/JSON.lua'
2020-12-26 16:29:10.201 no file '/usr/local/share/lua/5.3/JSON/init.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON/init.lua'
2020-12-26 16:29:10.201 no file './JSON.lua'
2020-12-26 16:29:10.201 no file './JSON/init.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON.so'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-12-26 16:29:10.201 no file './JSON.so'
Thx for your help
Now i get error messages, I think JSON is not (correctly) installed on my Domorticz / Synology implementation.
Version: 2020.1 (build 11839)
Build Hash: 139d994e5-modified
Compile Date: 2020-03-27 06:53:01
dzVents Version: 3.0.1
Some advises ?
Thx by advance
Christophe
2020-12-26 16:29:10.201 Error: EventSystem: in Test: [string "commandArray = {}..."]:3: module 'JSON' not found:
2020-12-26 16:29:10.201 no field package.preload['JSON']
2020-12-26 16:29:10.201 no file '/usr/local/share/lua/5.3/JSON.lua'
2020-12-26 16:29:10.201 no file '/usr/local/share/lua/5.3/JSON/init.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON/init.lua'
2020-12-26 16:29:10.201 no file './JSON.lua'
2020-12-26 16:29:10.201 no file './JSON/init.lua'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/JSON.so'
2020-12-26 16:29:10.201 no file '/usr/local/lib/lua/5.3/loadall.so'
2020-12-26 16:29:10.201 no file './JSON.so'
Re: LUA JSON issue
In addition
in /volume1/@appstore/domoticz/var/scripts/lua
the file JSON.lua is present.
in /volume1/@appstore/domoticz/var/scripts/lua
the file JSON.lua is present.
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: LUA JSON issue
I thought that the domoticz lua path the default working directory would be.
You could also add the proper directory to the search path for lua modules.... something like:
Jos
You could also add the proper directory to the search path for lua modules.... something like:
Code: Select all
package.path = '/volume1/@appstore/domoticz/var/scripts/lua/?.lua;' .. package.path
json = require "JSON" -- use generic JSON.lua
Last edited by jvdz on Saturday 26 December 2020 17:20, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: LUA JSON issue
Thx
The @APPSTORE must be replace by the symbol link APPSTORE, the @ is refused by LUA interpreter
Thank you so much.
Best regards
Christophe
commandArray = {}
package.path = package.path .. ";/volume1/APPSTORE/domoticz/var/scripts/lua/?.lua"
json = require "JSON"
local rid = assert(io.popen('curl "http://192.168.0.252:8084/json.htm?type=devices&rid=201"'))
local blocjson = rid:read('*all')
print ('TRACE')
--print (blocjson)
rid:close()
local periph = json:decode(blocjson).result[1]
print ('TRACE : '..periph.Name)
print ('TRACE : '..periph.Data)
return commandArray
The @APPSTORE must be replace by the symbol link APPSTORE, the @ is refused by LUA interpreter
Thank you so much.
Best regards
Christophe
commandArray = {}
package.path = package.path .. ";/volume1/APPSTORE/domoticz/var/scripts/lua/?.lua"
json = require "JSON"
local rid = assert(io.popen('curl "http://192.168.0.252:8084/json.htm?type=devices&rid=201"'))
local blocjson = rid:read('*all')
print ('TRACE')
--print (blocjson)
rid:close()
local periph = json:decode(blocjson).result[1]
print ('TRACE : '..periph.Name)
print ('TRACE : '..periph.Data)
return commandArray
Who is online
Users browsing this forum: No registered users and 0 guests