Changes in / [1:3]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • /I_FoscamPTZ.xml

    r1 r3  
    4949 
    5050        function lug_startup (lul_device) 
     51 
     52            -- Check if we have the correct category number. 
     53            if (luup.devices[lul_device].category_num ~= 6) then 
     54                luup.attr_set("category_num", "6", lul_device) 
     55            end 
     56 
    5157            lug_username = luup.devices[lul_device].user or luup.variable_get(CAM_SID, "Username", lul_device) or "" 
    5258            lug_password = luup.devices[lul_device].pass or luup.variable_get(CAM_SID, "Password", lul_device) or "" 
     
    7884            local ver = luup.version_branch * 10000 + luup.version_major * 1000 + luup.version_minor 
    7985            if (ver < 15390) then 
     86                luup.log("(".. luup.devices[lul_device].description ..") Version ".. luup.version .." is too old.") 
    8087                return 
    8188            end 
    8289 
    83             -- The camera was already configured for motion detection. 
     90            -- Check if the camera was configured for motion detection. 
    8491            local configuredMd = luup.variable_get(CMD_SID, "ConfiguredMD", lul_device) or "0" 
    8592            if (configuredMd == "0") then 
    8693 
     94                luup.log("(".. luup.devices[lul_device].description ..") ComfiguredMD = ".. configuredMd) 
     95 
    8796                -- We can't configure the camera for motion detection if we don't know its URL/IP address. 
    8897                if (lug_ip == "") then 
    89                     return 
     98                    luup.log("(".. luup.devices[lul_device].description .."::ComfiguredMD/".. configuredMd ..") Missing camera IP.") 
     99                    return false, "Missing camera IP address.", luup.devices[lul_device].description 
    90100                end 
    91101 
     
    118128                end 
    119129 
    120                 -- Set the configured flag now because the Luup engine is restarted after 'sync'. 
     130                -- Set the ConfiguredMD variable here, because no value can be saved in the user_data after luup.chdev.sync has run. 
    121131                luup.variable_set(CMD_SID, "ConfiguredMD", "1", lul_device) 
    122132 
     
    128138            elseif (configuredMd == "1") then 
    129139 
     140                luup.log("(".. luup.devices[lul_device].description ..") ComfiguredMD = ".. configuredMd) 
     141 
    130142                -- We can't configure the camera if we don't know Vera's URL / IP address. 
    131                 local veraAddress = luup.variable_get(CMD_SID, "VeraAddress", lul_device) 
     143                local veraAddress = luup.variable_get(CMD_SID, "VeraAddress", lul_device) or "" 
    132144                if (veraAddress == "") then 
    133                     return 
     145                    luup.log("(".. luup.devices[lul_device].description .."::ComfiguredMD/".. configuredMd ..") VeraAddress is empty.") 
     146                    return false, "Missing Vera IP address.", luup.devices[lul_device].description 
    134147                end 
    135148 
     
    144157                end 
    145158 
     159                -- We haven't created the motion sensor. Reset the ConfiguredMD variable. 
     160                if (sensorId == 0) then 
     161                    luup.log("(".. luup.devices[lul_device].description .."::ComfiguredMD/".. configuredMd ..") Motion sensor doesn't exist.") 
     162                    luup.variable_set(CMD_SID, "ConfiguredMD", "0", lul_device) 
     163                    return 
     164                end 
     165 
    146166                -- Configure the camera: 
    147167                -- 1. Enable motion detection. 
     
    151171                luup.inet.wget("http://".. lug_ip .."/set_alarm.cgi?motion_armed=1&http=1&http_url=".. urlEncode(url) .."&user=".. lug_username .."&pwd=".. lug_password, 5) 
    152172 
    153                 if (sensorId ~= 0) then 
    154                     -- Get and set the time until the sensor is considered untripped. 
    155                     local onTime = luup.variable_get(SES_SID, "OnTime", sensorId) or "" 
    156                     if (onTime:find("^%d+$") ~= nil) then 
    157                         ON_TIME = tonumber(onTime, 10) or ON_TIME 
    158                     else 
    159                         luup.variable_set(SES_SID, "OnTime", tostring(ON_TIME), sensorId) 
    160                     end 
     173                -- Get and set the time until the sensor is considered untripped. 
     174                local onTime = luup.variable_get(SES_SID, "OnTime", sensorId) or "" 
     175                if (onTime:find("^%d+$") ~= nil) then 
     176                    ON_TIME = tonumber(onTime, 10) or ON_TIME 
     177                else 
     178                    luup.variable_set(SES_SID, "OnTime", tostring(ON_TIME), sensorId) 
    161179                end 
    162180 
    163181                luup.variable_set(CMD_SID, "ConfiguredMD", "2", lul_device) 
    164182            else 
     183                luup.log("(".. luup.devices[lul_device].description ..") ComfiguredMD = ".. configuredMd) 
    165184                -- Run the 'trip' function when notified. 
    166185                luup.register_handler("trip", "foscam_tripped") 
Note: See TracChangeset for help on using the changeset viewer.