Lua script to extract data from json
Posted: Sunday 10 December 2017 21:59
Hello everybody
i'm looking around on the forum and the rest of the internet but i can't seem to find the right anwser. At home we have Enphase solar panels& gateway. I can get the production and consumption from the gateway and into virtual kwh meters. Now am i trying to parse the data i got from the gateway about every individual panel into seperate meters so to check if they are working accordingly. I have attached a piece of the json. My question is how do i get the data from "lastReportWatts" into a variable?
commandArray = {}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "http://address/solar.json"')) -- json data off all solar panels
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
Current_watt = jsonData.lastReportWatts
This trows an error : attempt to index global 'devicechanged' (a nil value)
Attecht is the json converted to txt.
i'm looking around on the forum and the rest of the internet but i can't seem to find the right anwser. At home we have Enphase solar panels& gateway. I can get the production and consumption from the gateway and into virtual kwh meters. Now am i trying to parse the data i got from the gateway about every individual panel into seperate meters so to check if they are working accordingly. I have attached a piece of the json. My question is how do i get the data from "lastReportWatts" into a variable?
commandArray = {}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- API call
local config=assert(io.popen('curl "http://address/solar.json"')) -- json data off all solar panels
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
Current_watt = jsonData.lastReportWatts
This trows an error : attempt to index global 'devicechanged' (a nil value)
Attecht is the json converted to txt.