thanks everyone…
I’m using these functions:
<functions>
local MyDevice
function startup (lul_device)
luup.log("ThreeGee1: Bridge Plugin: Loading Library L_ThreeGee1...")
if (package.path:find ("/etc/cmh-ludl/?.lua;/etc/cmh-lu/?.lua", 1, true) == nil) then
package.path = package.path .. ";/etc/cmh-ludl/?.lua;/etc/cmh-lu/?.lua"
end
package.loaded.L_ThreeGee1 = nil
MyDevice = require("L_ThreeGee1")
if (package.loaded.L_ThreeGee1 == nil)
then
luup.log("ThreeGee1 plugin: plugin is not installed correctly. Library L_ThreeGee1 cannot be loaded.", 1)
luup.task("Plugin not correctly installed", 2, "ThreeGee1 plugin", -1)
return false
end
luup.set_failure(false, lul_device)
luup.log("ThreeGee1 plugin: library L_ThreeGee1 loaded")
luup.variable_set("urn:konektedplay-com:serviceId:ThreeGee1", "Received", "no message received", lul_device)
MyDevice.initializeVariables(lul_device)
luup.log("ThreeGee1: start pingGateway")
pingGateway(lul_device)
end
-- callback function to repeat ping to gateway
function pingGateway (lul_device)
luup.log("ThreeGee1: running pingGateway()")
luup.io.write("PING:-1", tonumber(lul_device))
luup.log("ThreeGee1: getting LastUpdate timestamp")
local value, timestamp = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "LastUpdate", tonumber(lul_device))
luup.log("ThreeGee1: getting current tripped state")
local currentTrippedState = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", tonumber(lul_device))
if not currentTrippedState then
luup.log("ThreeGee1: error currentTrippedState")
end
luup.log("ThreeGee1: getting current PingTimeout")
local pingTimeout = luup.variable_get("urn:konektedplay-com:serviceId:ThreeGee1", "PingTimeout", tonumber(lul_device))
luup.log("ThreeGee1: checking...")
luup.log("ThreeGee1: os.time:"..os.time())
luup.log("ThreeGee1: timestamp:"..tonumber(timestamp))
luup.log("ThreeGee1: pingTimeout:"..tonumber(pingTimeout))
if (os.time() - tonumber(timestamp) > tonumber(pingTimeout)) then
luup.log("Sensor Is Tripped")
if(currentTrippedState == "0") then
luup.log("Setting to Tripped")
luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 1, tonumber(lul_device))
end
else
luup.log("Sensor Is Not Tripped")
if(currentTrippedState == "1") then
luup.log("setting to not tripped")
luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 0, tonumber(lul_device))
end
end
local pingFrequency = luup.variable_get("urn:konektedplay-com:serviceId:ThreeGee1", "PingFrequency", tonumber(lul_device))
luup.call_timer("pingGateway", 1, tostring(pingFrequency), "", lul_device)
end
</functions>
with this in my lua module:
[code]
function initializeVariables(device)
assert(device ~= nil)
luup.log(“ThreeGee1: running initializeVariables”)
luup.log(“ThreeGee1: initializing…”)
if (luup.variable_get(SECURITY_SENSOR_SID, “Tripped”, device) == nil) then
luup.log(“ThreeGee1: initializing Tripped”)
luup.variable_set(SECURITY_SENSOR_SID, “Tripped”, 0, device)
end
if (luup.variable_get(SECURITY_SENSOR_SID, “Armed”, device) == nil) then
luup.log(“ThreeGee1: initializing Armed”)
luup.variable_set(SECURITY_SENSOR_SID, “Armed”, 0, device)
end
if (luup.variable_get(SECURITY_SENSOR_SID, “ArmedTripped”, device) == nil) then
luup.log(“ThreeGee1: initializing ArmedTripped”)
luup.variable_set(SECURITY_SENSOR_SID, “ArmedTripped”, 0, device)
end
if (luup.variable_get(THREEGEE_SID, “GatewayTimeout”, device) == nil) then
luup.log(“ThreeGee1: initializing GatewayTimeout”)
luup.variable_set(THREEGEE_SID, “GatewayTimeout”, GATEWAY_TIMEOUT, device)
end
if (luup.variable_get(THREEGEE_SID, “PingFrequency”, device) == nil) then
luup.log(“ThreeGee1: initializing PingFrequency”)
luup.variable_set(THREEGEE_SID, “PingFrequency”, PING_INTERVAL, device)
end
if (luup.variable_get(THREEGEE_SID, “PingTimeout”, device) == nil) then
luup.log(“ThreeGee1: initializing PingTimeout”)
luup.variable_set(THREEGEE_SID, “PingTimeout”, PING_TIMEOUT, device)
end
luup.log(“ThreeGee1: completed initializeVariables”)
return true
end[/code]
you can see from the output that the value isn’t being initialized properly… am I making some scope errors?
log:
50 09/06/17 8:40:23.521 luup_log:257: ThreeGee1: Bridge Plugin: Loading Library L_ThreeGee1... <0x2bd33680>
50 09/06/17 8:40:23.543 luup_log:257: ThreeGee1: running initializeVariables <0x2bd33680>
50 09/06/17 8:40:23.543 luup_log:257: ThreeGee1: initializing... <0x2bd33680>
50 09/06/17 8:40:23.556 luup_log:257: ThreeGee1: initializing Tripped <0x2bd33680>
50 09/06/17 8:40:23.557 luup_log:257: ThreeGee1: initializing Armed <0x2bd33680>
50 09/06/17 8:40:23.559 luup_log:257: ThreeGee1: initializing ArmedTripped <0x2bd33680>
50 09/06/17 8:40:23.561 luup_log:257: ThreeGee1: initializing GatewayTimeout <0x2bd33680>
50 09/06/17 8:40:23.562 luup_log:257: ThreeGee1: initializing PingFrequency <0x2bd33680>
50 09/06/17 8:40:23.564 luup_log:257: ThreeGee1: initializing PingTimeout <0x2bd33680>
50 09/06/17 8:40:23.575 luup_log:257: ThreeGee1: completed initializeVariables <0x2bd33680>
50 09/06/17 8:40:23.575 luup_log:257: ThreeGee1: start pingGateway <0x2bd33680>
50 09/06/17 8:40:23.576 luup_log:257: ThreeGee1: running pingGateway() <0x2bd33680>
50 09/06/17 8:40:23.580 luup_log:257: ThreeGee1: getting LastUpdate timestamp <0x2bd33680>
50 09/06/17 8:40:23.581 luup_log:257: ThreeGee1: getting current tripped state <0x2bd33680>
50 09/06/17 8:40:23.581 luup_log:257: ThreeGee1: error currentTrippedState <0x2bd33680> // <<<<<< look here!!
50 09/06/17 8:40:23.582 luup_log:257: ThreeGee1: getting current PingTimeout <0x2bd33680>
50 09/06/17 8:40:23.583 luup_log:257: ThreeGee1: checking... <0x2bd33680>
50 09/06/17 8:40:23.583 luup_log:257: ThreeGee1: os.time:1504701623 <0x2bd33680> // <<<<< crashes here