lua json opensensemap

Moderator: leecollings

Post Reply
grpfge
Posts: 4
Joined: Saturday 29 July 2017 8:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10164
Location: Germany NRW
Contact:

lua json opensensemap

Post by grpfge »

Hello
With the following script, I want to read data from this address https://api.opensensemap.org/boxes/5968 ... d1/sensors

Code: Select all

commandArray = {}

json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux
 
       local config=assert(io.popen('curl https://api.opensensemap.org/boxes/5968f05d1900bf0011ffb0d1/sensors' ))
       local location = config:read('*all')
       config:close()
       local jsonLocation = json:decode(location)
       t1 = jsonLocation.sensors[0].lastMeasurement.value
       lf = jsonLocation.sensors[1].lastMeasurement.value
       ld = jsonLocation.sensors[2].lastMeasurement.value
       lx = jsonLocation.sensors[3].lastMeasurement.value
       uv = jsonLocation.sensors[4].lastMeasurement.value
       
       print('Temperatur: '..t1)
       
The result is
Error: EventSystem: in sensebox1: [string "..."]:13: attempt to index field '?' (a nil value)

Can you look at my snytax for json, i think there is an mistake
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

Re: lua json opensensemap

Post by mivo »

Hi,

try this syntax for LUA table values:

Code: Select all

t1 = jsonLocation.sensors[1].lastMeasurement['value']
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
grpfge
Posts: 4
Joined: Saturday 29 July 2017 8:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10164
Location: Germany NRW
Contact:

Re: lua json opensensemap

Post by grpfge »

It works, thanks
grpfge
Posts: 4
Joined: Saturday 29 July 2017 8:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10164
Location: Germany NRW
Contact:

Re: lua json opensensemap

Post by grpfge »

It works, thanks
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

Re: lua json opensensemap

Post by mivo »

Great 8-)
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
Post Reply

Who is online

Users browsing this forum: hjzwiers and 1 guest