i want to read all devices value and write them in a sensor.txt file.
i write a script for read from one device and write to text file and its work, but when i want read more than one device i get several error.
First code : read from one device
Code: Select all
commandArray = {}
luxsensor = "ESP2_Lux"
if (devicechanged[luxsensor]) then
print( " ####lux debug: "..devicechanged[luxsensor])
file = io.open("sensor.txt", "w+")
file:write("Sensors Status \n")
file:write(luxsensor.." : "..devicechanged[luxsensor].."\n")
file:close()
end
return commandArray
second code: read from more than one device
Code: Select all
commandArray = {}
luxsensor = "ESP2_Lux"
smokesensor = "Smoke_Sensor"
if (devicechanged[luxsensor]) then
print( " ####lux debug: "..devicechanged[luxsensor])
file = io.open("sensorl.txt", "w+")
file:write("Sensors Status \n")
file:write(luxsensor.." : "..devicechanged[luxsensor].."\n")
file:write(smokesensor.." : "..devicechanged[smokesensor].."\n")
file:close()
end
return commandArray
i get this:
2017-07-01 15:26:29.442 Error: EventSystem: in Lua LUX: [string "commandArray = {} ..."]:13: attempt to concatenate field '?' (a nil value)
please help me
tnx