- Files:
-
- 3 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
/tags/2.6/I_FoscamPTZ.xml
r20 r30 21 21 local lastTrip = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip", sensorId) or 0 22 22 local now = os.time() 23 if (os.difftime(now, lastTrip) >= ON_TIME)then -- 20 minutes23 if os.difftime(now, lastTrip) >= ON_TIME then -- 20 minutes 24 24 luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", sensorId) 25 25 end … … 30 30 31 31 local sensorId = tonumber(parameters.sensor_id, 10) or 0 32 if (sensorId == 0)then32 if sensorId == 0 then 33 33 return "failed" 34 34 end … … 44 44 45 45 local function urlEncode (s) 46 if (s ~= nil)then46 if s ~= nil then 47 47 s = s:gsub("\n", "\r\n") 48 48 s = s:gsub("([^%w ])", function (c) … … 64 64 65 65 local sensorId = tonumber(luup.variable_get(CMD_SID, "MotionSensorID", lug_device) , 10) or 0 66 if (sensorId > 0)then66 if sensorId > 0 then 67 67 return sensorId 68 68 end … … 71 71 local altid = "foscam_".. lug_device .."_sensor" 72 72 for dev, attr in pairs(luup.devices) do 73 if (attr.id == altid)then73 if attr.id == altid then 74 74 sensorId = dev 75 75 break … … 77 77 end 78 78 79 if (sensorId == 0)then79 if sensorId == 0 then 80 80 -- We haven't created the motion sensor. Set State to STATE_CREATE_MS. 81 81 luup.log("(".. luup.devices[lug_device].description .."::State=".. state ..") Motion sensor doesn't exist. Set State to STATE_CREATE_MS(".. STATE_CREATE_MS ..").") … … 96 96 97 97 -- Check if we have the correct category number. 98 if (luup.devices[lul_device].category_num ~= 6)then98 if luup.devices[lul_device].category_num ~= 6 then 99 99 luup.attr_set("category_num", "6", lul_device) 100 100 end … … 105 105 lug_ip = luup.devices[lul_device].ip or "" 106 106 107 l ug_path= luup.variable_get(CAM_SID, "URL", lul_device) or ""108 if (lug_path == "")then107 local snapshotUrl = luup.variable_get(CAM_SID, "URL", lul_device) or "" 108 if snapshotUrl == "" then 109 109 luup.variable_set(CAM_SID, "URL", "/snapshot.cgi", lul_device) 110 110 end 111 111 112 112 lug_stepSize = luup.variable_get(CAM_SID, "StepSize", lul_device) or "" 113 if (lug_stepSize == "")then113 if lug_stepSize == "" then 114 114 lug_stepSize = "1" 115 115 luup.variable_set(CAM_SID, "StepSize", lug_stepSize, lul_device) … … 117 117 118 118 lug_reversePan = luup.variable_get(CAM_SID, "ReversePan", lul_device) or "" 119 if (lug_reversePan == "")then119 if lug_reversePan == "" then 120 120 lug_reversePan = "0" 121 121 luup.variable_set(CAM_SID, "ReversePan", lug_reversePan, lul_device) … … 123 123 124 124 lug_reverseTilt = luup.variable_get(CAM_SID, "ReverseTilt", lul_device) or "" 125 if (lug_reverseTilt == "")then125 if lug_reverseTilt == "" then 126 126 lug_reverseTilt = "0" 127 127 luup.variable_set(CAM_SID, "ReverseTilt", lug_reverseTilt, lul_device) … … 130 130 -- Disable zoom buttons by default. 131 131 local commands = luup.variable_get(HAD_SID, "Commands", lul_device) 132 if (not commands)then132 if not commands then 133 133 commands = "camera_up,camera_down,camera_left,camera_right,camera_full_screen,camera_preset,camera_archive_snapshot" 134 134 luup.variable_set(HAD_SID, "Commands", commands, lul_device) … … 143 143 luup.log("(".. luup.devices[lul_device].description ..") State=".. state) 144 144 145 if (state == "")then145 if state == "" then 146 146 -- If it's an upgrade from an older plugin version, State is ConfiguredMD. 147 147 state = luup.variable_get(CMD_SID, "ConfiguredMD", lul_device) or "" 148 if (state == "")then148 if state == "" then 149 149 -- Not an upgrade, the plugin is freshly installed. 150 150 state = STATE_MD_DISABLED … … 162 162 -- Motion detection disabled 163 163 ---------------------------------------------------------------------------------------- 164 if (state == STATE_MD_DISABLED)then -- Disable the motion detection.164 if state == STATE_MD_DISABLED then -- Disable the motion detection. 165 165 return 166 166 ---------------------------------------------------------------------------------------- 167 167 -- Motion sensor not created. Create the motion sensor. 168 168 ---------------------------------------------------------------------------------------- 169 elseif (state == STATE_CREATE_MS)then169 elseif state == STATE_CREATE_MS then 170 170 171 171 -- We can't configure the camera for motion detection if we don't know its URL/IP address. 172 if (lug_ip == "")then172 if lug_ip == "" then 173 173 luup.log("(".. luup.devices[lul_device].description .."::State=".. state ..") Missing camera IP.") 174 174 return false, "Missing camera IP address", luup.devices[lul_device].description … … 176 176 177 177 local gatewayAddress = luup.variable_get(CMD_SID, "GatewayAddress", lul_device) or "" 178 if (gatewayAddress == "")then178 if gatewayAddress == "" then 179 179 -- Vera's IP address hasn't been specified. Try to get it based on the camera's IP address. 180 180 -- Get the camera subnet. 181 181 local camSubnet = lug_ip:match("%d+%.%d+%.%d+") 182 if (camSubnet ~= nil)then182 if camSubnet ~= nil then 183 183 -- Try the WAN IP. 184 184 local stdout = io.popen("GetNetworkState.sh ip_wan") … … 186 186 stdout:close() 187 187 188 if (not gatewayAddress:find(camSubnet, 1, true)) then188 if not gatewayAddress:find(camSubnet, 1, true) then 189 189 -- Try the LAN IP. 190 190 stdout = io.popen("GetNetworkState.sh ip_lan") … … 192 192 stdout:close() 193 193 194 if (not gatewayAddress:find(camSubnet, 1, true)) then194 if not gatewayAddress:find(camSubnet, 1, true) then 195 195 -- The camera is in a different network than Vera. 196 196 gatewayAddress = "" … … 200 200 end 201 201 202 if (gatewayAddress == "")then202 if gatewayAddress == "" then 203 203 -- Vera's IP address isn't specified and we couldn't get it based on the camera's IP address. 204 204 -- Create the variable so that it can be set up by the user. … … 212 212 213 213 -- Create the motion sensor. 214 luup.log("(".. luup.devices[lul_device].description .."::State=".. state ..") Create the motion sensor.") 214 215 local ptr = luup.chdev.start(lul_device) 215 luup.chdev.append(lul_device, ptr, "foscam_".. lul_device .."_sensor", "Foscam #".. lul_device .." Motion Sensor", "urn:schemas-micasaverde-com:device:MotionSensor:1", "D_MotionSensor1.xml", "", SES_SID ..",Armed=1\n".. SES_SID ..",Tripped=0", true, false) 216 luup.chdev.append(lul_device, ptr, "foscam_".. lul_device .."_sensor", luup.devices[lul_device].description .." Motion Sensor", 217 "urn:schemas-micasaverde-com:device:MotionSensor:1", "D_MotionSensor1.xml", "", SES_SID ..",Armed=1\n".. SES_SID ..",Tripped=0", true, false) 216 218 luup.chdev.sync(lul_device, ptr) 219 217 220 ---------------------------------------------------------------------------------------- 218 221 -- Motion sensor created. Configure the camera for motion detection reporting. 219 222 ---------------------------------------------------------------------------------------- 220 elseif (state == STATE_CONFIGURE_CAM)then223 elseif state == STATE_CONFIGURE_CAM then 221 224 222 225 -- We can't configure the camera if we don't know Vera's URL / IP address. 223 226 local gatewayAddress = luup.variable_get(CMD_SID, "GatewayAddress", lul_device) or "" 224 if (gatewayAddress == "")then227 if gatewayAddress == "" then 225 228 luup.log("(".. luup.devices[lul_device].description .."::State=".. state ..") GatewayAddress is empty.") 226 229 return false, "Missing Gateway IP address", luup.devices[lul_device].description … … 229 232 -- Get the motion sensor's device ID. 230 233 local sensorId = getMotionSensorId(state) 231 if (not sensorId)then234 if not sensorId then 232 235 luup.call_delay("showSysMessage", 2, "Reload Luup to create motion sensor") 233 236 return … … 240 243 local url = "http://".. gatewayAddress ..":3480/data_request?id=lr_foscam_tripped&sensor_id=".. sensorId 241 244 local status = luup.inet.wget("http://".. lug_ip .."/set_alarm.cgi?motion_armed=1&http=1&http_url=".. urlEncode(url) .."&user=".. lug_username .."&pwd=".. urlEncode(lug_password), 5) 242 if (status ~= 0)then245 if status ~= 0 then 243 246 luup.log("(".. luup.devices[lul_device].description .."::State=".. state ..") Failed to configure camera, status = ".. status ..".") 244 247 return false, "Failed to configure camera", luup.devices[lul_device].description … … 254 257 -- The configuration was successful. 255 258 luup.variable_set(CMD_SID, "State", STATE_CONFIGURED_OK, lul_device) 259 256 260 ---------------------------------------------------------------------------------------- 257 261 -- Camera configured … … 261 265 -- Get the motion sensor's device ID. 262 266 local sensorId = getMotionSensorId(state) 263 if (not sensorId) then 264 return false, "Reload Luup to create motion sensor", luup.devices[lul_device].description 267 if not sensorId then 268 luup.call_delay("showSysMessage", 2, "Reload Luup to create motion sensor") 269 return 265 270 end 266 271 267 272 -- Get and update the time until the sensor is considered untripped. 268 273 local onTime = luup.variable_get(SES_SID, "OnTime", sensorId) or "" 269 if (onTime:find("^%d+$") ~= nil)then274 if onTime:find("^%d+$") ~= nil then 270 275 ON_TIME = tonumber(onTime, 10) or ON_TIME 271 276 else … … 275 280 -- Untrip the sensor if the OnTime has passed. 276 281 local lastTrip = luup.variable_get(SES_SID, "LastTrip", sensorId) or 0 277 if (os.difftime(os.time(), lastTrip) >= ON_TIME)then282 if os.difftime(os.time(), lastTrip) >= ON_TIME then 278 283 luup.variable_set(SES_SID, "Tripped", "0", sensorId) 279 284 end
Note: See TracChangeset
for help on using the changeset viewer.