I’m rather new to the Vera3 and trying to parse a valid JSON from a external source.
I searched the forum and found allot of posts about including json libs etc. but i did not found a (for me) working solution.
This is what i tried;
[code]local http = require(“socket.http”)
result, status = http.request(“http://192.168.1.110/websolarlog/api.php/Live”)
luup.log(result)
local json = require(“json”)
local jsonResult = json:decode(result)
luup.log(jsonResult)
local jsonResult2 = json.decode(result)
luup.log(jsonResult2)[/code]
I uploaded a file “json.lua” from http://regex.info/blog/lua/json through Apps->Develop Apps->Luup Files.
I believe the log shows that the json.lua is found and used, but there it could not parse the json.
But i checked the json in JSONlint and its OK.
the logs of the vera3 show:
08 04/02/14 22:31:08.195 Scene::RunScene running 12 powerUsage <0x2e308680> 50 04/02/14 22:31:10.042 luup_log:0: {"0":{"type":"metering","id":"2","name":"Slimme Meter","data":{"id":"1","time":"1396470592","invtnum":"2","deviceId":"2","status":null,"name":null,"type":null,"highUsage":"1006978","lowUsage":"1521106","highReturn":"1739961","lowReturn":"712561","liveUsage":"0000390","liveReturn":"0000000","liveEnergy":390,"gasUsage":"1069464","liveGas":"0","pvoutput":null}},"1":{"type":"weather","id":"3","name":"Weather","data":{"id":"86276","deviceId":"3","time":"1396470000","temp":"15.87","temp_min":"13.33","temp_max":"17.78","pressure":"1004","humidity":"72","conditionId":"803","rain1h":null,"rain3h":null,"clouds":"68","wind_speed":"2.06","wind_direction":"49"}},"2":{"type":"production","id":"4","name":"PowerOne4.2","data":{"id":"763","INV":"4","deviceId":"4","I1V":"125.114975","I1A":"0.013695","I1P":"1.713475","I1Ratio":"54.764","I2V":"117.128502","I2A":"0.012084","I2P":"1.415381","I2Ratio":"45.236","I3V":null,"I3A":null,"I3P":null,"I3Ratio":"0","GV":"223.463928","GA":"0.588602","GP":"17.77169","GV2":null,"GA2":null,"GP2":null,"GV3":null,"GA3":null,"GP3":null,"SDTE":null,"time":"1396463995","FRQ":"50.009003","EFF":"567.993","INVT":"29.482861","BOOT":"27.044428","KWHT":"3422.368","IP":null,"ACP":null,"status":null,"name":null,"trendImage":null,"trend":null,"avgPower":null,"type":null}},"totals":{"production":{"devices":1,"GP":17.77169,"GP2":0,"GP3":0},"metering":{"devices":1,"liveEnergy":390}}} __LEAK__ this:12288 start:1048576 to 0xe7d000 <0x2e308680> 01 04/02/14 22:31:10.042 LuaInterface::CallFunction_Scene Scene 12 failed /usr/lib/lua/json.lua:373: unexpected termination of JSON while looking for object ({ or [ or ' or " or number or boolean or null expected) __LEAK__ this:4096 start:1052672 to 0xe7e000 <0x2e308680>
What is it that i’m doing wrong or could somebody point me to a working solution?