This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

dynamic variable name
#5
yeah.. thanks

i need the value 'attributes.soilHumidity.value'

how to do this in a nested table?



Code:
["type"]
  * string: SENSOR
["attributes"]
  * table:
   ["soilTemperature"]
    * table:
     ["timestamp"]
      * string: 2020-10-31T14:49:03.034+0000
     ["value"]
      * number: 13
   ["lightIntensity"]
    * table:
     ["timestamp"]
      * string: 2020-10-31T14:49:16.260+0000
     ["value"]
      * number: 7
   ["soilHumidity"]
    * table:
     ["timestamp"]
      * string: 2020-10-31T14:49:03.004+0000
     ["value"]
      * number: 100
   ["ambientTemperature"]
    * table:
     ["timestamp"]
      * string: 2020-10-31T14:49:17.023+0000
     ["value"]
      * number: 16
["relationships"]
  * table:
   ["device"]
    * table:
     ["data"]
      * table:
       ["type"]
        * string: DEVICE
       ["id"]
        * string: 40940964969046840
["id"]
  * string: 5647657567567567567

here my new example code
Code:
-- devices
devices = {
  {'9d', 'SENSOR', '8/4/5', 'attributes.soilHumidity.value'},
  {'9e', 'COMMON', '8/4/6', 'attributes.batteryLevel.value'}
}

-- data get from webservice
v = { attributes= { soilHumidity={value=1},batteryLevel={value=100} } }
log(v)
log(v.attributes.soilHumidity.value)
log(v.attributes.batteryLevel.value)

-- print some data from v, based on data in devices (dynamic)
for k,k_items in pairs(devices) do
  key = k_items[4]
  val = v[ key ]
  log(key, val)
end
Reply


Messages In This Thread
dynamic variable name - by gjniewenhuijse - 15.03.2021, 13:00
RE: dynamic variable name - by admin - 15.03.2021, 13:02
RE: dynamic variable name - by gjniewenhuijse - 15.03.2021, 13:04
RE: dynamic variable name - by admin - 15.03.2021, 13:05
RE: dynamic variable name - by gjniewenhuijse - 15.03.2021, 13:09

Forum Jump: