Foscam IO Input and Output

Hi Guys

Here in Australia we dont have any contact closure devices that I’m aware of, which makes it hard to control anything other than lights, power IR etc. I have a garage door that that I want to operate and I have managed to write the following luup code that changes the state of the foscam hardware IO output.

[code]
– Operate Garage Door
– loads the HTTP module and any libraries it requires
local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

– Close the contacts
result = http.request(“http://192.168.0.192/decoder_control.cgi?command=94&user=xxxxx&pwd=xxxxxxx”)

– Wait 0.5 Seconds
luup.sleep(500)

– Open the contacts
result = http.request(“http://192.168.0.192/decoder_control.cgi?command=95&user=xxxxxx&pwd=xxxxxx”)[/code]

I want to take advantage of the foscam input to use as a door sensor input. Using the get_params.cgi? in a browser

http://192.168.0.192/get_params.cgi?user=xxxxx&pwd=xxxxxx

returns ALL of the parameters in a list (the one i’m interested in is alarm_ioin_level

I’m unsure of how to get it to return just the alarm io level or handle this with luup code so that I can have the value in a variable cameraIoInput = …
If someone could help me with this that would be great.

It would be nice if the foscam plugin created IO devices for the hardware Input and Output similar to the ones it creates for Motion Sensor. Looking at the new foscam cameras though they dont seem to have hardware IO which is such a great added feature.

I’m not sure what format the data comes back in, but assuming the data is coming in “lines” and each is of the form =, then you can use something like the following to extract it

[code]local result = [[
user1_name=foo
alarm_ioin_level=13453453b
alarm_http_url=2345345345345
test_foo=434
]]

local alarm_ioin_level = result:match(“alarm_ioin_level=(.-)\n”)
print(alarm_ioin_level)
[/code]

This is a free-standing example, that you can test on the command line of Vera (or anywhere with a Lua interpretor). In your case, you don’t need the “[tt]result[/tt]” declaration, since it will be populated with data from the HTTP call that you’re making.

You also won’t need the [tt]print(…)[/tt] command, but I left it in just in case you wanted to test it end-to-end on the command line (with different string formats etc, depending upon what’s actually coming back from the URL call…