Foscam configuration reading

One thing that’d be nice to have for the Foscam support would be the ability to poll the device to find states set for different things (primarily: is the alarm on?).

The camera allows you to poll against it to get a full output of params: /get_params.cgi

Within here, you’ll find an output like this (cleaned up to remove stuff I would rather not share, such as my password):

var alias='';
var ntp_enable=1;
var ntp_svr='';
var user1_pri=2;
var user2_name='';
var user2_pwd='';
var user2_pri=0;
var user3_name='';
var user3_pwd='';
var user3_pri=0;
var user4_name='';
var user4_pwd='';
var user4_pri=0;
var user5_name='';
var user5_pwd='';
var user5_pri=0;
var user6_name='';
var user6_pwd='';
var user6_pri=0;
var user7_name='';
var user7_pwd='';
var user7_pri=0;
var user8_name='';
var user8_pwd='';
var user8_pri=0;
var dev2_alias='';
var dev2_host='';
var dev2_port=0;
var dev2_user='';
var dev2_pwd='';
var dev3_alias='';
var dev3_host='';
var dev3_port=0;
var dev3_user='';
var dev3_pwd='';
var dev4_alias='';
var dev4_host='';
var dev4_port=0;
var dev4_user='';
var dev4_pwd='';
var dev5_alias='';
var dev5_host='';
var dev5_port=0;
var dev5_user='';
var dev5_pwd='';
var dev6_alias='';
var dev6_host='';
var dev6_port=0;
var dev6_user='';
var dev6_pwd='';
var dev7_alias='';
var dev7_host='';
var dev7_port=0;
var dev7_user='';
var dev7_pwd='';
var dev8_alias='';
var dev8_host='';
var dev8_port=0;
var dev8_user='';
var dev8_pwd='';
var dev9_alias='';
var dev9_host='';
var dev9_port=0;
var dev9_user='';
var dev9_pwd='';
var ip='';
var mask='';
var gateway='';
var dns='';
var wifi_enable=1;
var wifi_encrypt=4;
var wifi_defkey=0;
var wifi_key1='';
var wifi_key2='';
var wifi_key3='';
var wifi_key4='';
var wifi_authtype=0;
var wifi_keyformat=0;
var wifi_key1_bits=0;
var wifi_key2_bits=0;
var wifi_key3_bits=0;
var wifi_key4_bits=0;
var wifi_mode=0;
var wifi_country=1;
var pppoe_enable=0;
var pppoe_user='';
var pppoe_pwd='';
var upnp_enable=0;
var ddns_service=0;
var ddns_user='';
var ddns_pwd='';
var ddns_host='';
var ddns_proxy_svr='';
var ddns_proxy_port=0;
var mail_svr='';
var mail_port=0;
var mail_tls=0;
var mail_user='';
var mail_pwd='';
var mail_sender='';
var mail_receiver1='';
var mail_receiver2='';
var mail_receiver3='';
var mail_receiver4='';
var mail_inet_ip=0;
var ftp_mode=0;
var ftp_retain=0;
var ftp_upload_interval=0;
var ftp_filename='';
var ftp_numberoffiles=0;
var ftp_schedule_enable=0;
var ftp_schedule_sun_0=0;
var ftp_schedule_sun_1=0;
var ftp_schedule_sun_2=0;
var ftp_schedule_mon_0=0;
var ftp_schedule_mon_1=0;
var ftp_schedule_mon_2=0;
var ftp_schedule_tue_0=0;
var ftp_schedule_tue_1=0;
var ftp_schedule_tue_2=0;
var ftp_schedule_wed_0=0;
var ftp_schedule_wed_1=0;
var ftp_schedule_wed_2=0;
var ftp_schedule_thu_0=0;
var ftp_schedule_thu_1=0;
var ftp_schedule_thu_2=0;
var ftp_schedule_fri_0=0;
var ftp_schedule_fri_1=0;
var ftp_schedule_fri_2=0;
var ftp_schedule_sat_0=0;
var ftp_schedule_sat_1=0;
var ftp_schedule_sat_2=0;
var alarm_motion_armed=0;
var alarm_motion_sensitivity=7;
var alarm_motion_compensation=1;
var alarm_input_armed=1;
var alarm_ioin_level=1;
var alarm_sounddetect_armed=0;
var alarm_sounddetect_sensitivity=0;
var alarm_iolinkage=0;
var alarm_preset=0;
var alarm_ioout_level=1;
var alarm_mail=0;
var alarm_upload_interval=5;
var alarm_http=0;
var alarm_msn=0;
var alarm_http_url='';
var alarm_schedule_enable=0;
var alarm_schedule_sun_0=0;
var alarm_schedule_sun_1=0;
var alarm_schedule_sun_2=0;
var alarm_schedule_mon_0=0;
var alarm_schedule_mon_1=0;
var alarm_schedule_mon_2=0;
var alarm_schedule_tue_0=0;
var alarm_schedule_tue_1=0;
var alarm_schedule_tue_2=0;
var alarm_schedule_wed_0=0;
var alarm_schedule_wed_1=0;
var alarm_schedule_wed_2=0;
var alarm_schedule_thu_0=0;
var alarm_schedule_thu_1=0;
var alarm_schedule_thu_2=0;
var alarm_schedule_fri_0=0;
var alarm_schedule_fri_1=0;
var alarm_schedule_fri_2=0;
var alarm_schedule_sat_0=0;
var alarm_schedule_sat_1=0;
var alarm_schedule_sat_2=0;
var decoder_baud=12;
var msn_user='';
var msn_pwd='';
var msn_friend1='';
var msn_friend2='';
var msn_friend3='';
var msn_friend4='';
var msn_friend5='';
var msn_friend6='';
var msn_friend7='';
var msn_friend8='';
var msn_friend9='';
var msn_friend10='';

I figured it wouldn’t be too unreasonable to have the device type poll against the camera to update it’s settings on some interval. However, when saving that big output as a string and trying to go through it, the ST IDE seems to just kind of…stop.

Here is my simple snippet:

settings.splitEachLine('=') { items ->
    items[0] = items[0].replaceFirst("var ", "")
    items[1] = items[1].replaceFirst(";", "")[0] + " is " + items[1])

I can see the request being made and returning “OK”, but the console doesn’t update. Full disclosure: Java/Groovy aren’t languages I’m especially familiar with, so I could be doing something basic wrong.

@megapixel I think I have this working. Not really tested yet, but it’s a start:

Hello imbrian,
I’m new to the SmartThings world and successfully loaded your “Foscam-Remote” device and it works great, but I have one question. On the “Foscam Universal Device” created by skp19, there is a AUTO button/tile to turn the IR on and off. How hard would it be to replace the blank button/tile (the one to the left of your DOWN button) with the AUTO feature? FYI, I’m using an iPhone and the current version of the ST app. I got this far with the help of a ST technical support person by exchanging multiple emails today, but had to figure out the rest on my own. I have no idea where to edit your code or what to copy and paste from the other? Would really like to see the AUTO feature included with your device. Sorry for replying to this archived post, still learning my way around all of this ST stuff. Thank you for your time, enjoy your Labor Day weekend!

The Foscam IR should already be able to be automatic. You’re looking for the ability to explicitly set that on/off/auto ?

As with most things on the Foscam, it’s fairly easy to query it’s params and set them via REST. With the device controller I have pending, polling for the device is not reliable, so finding the current state (alarm, IR, etc) isn’t possible. If you’re happy with the non-local IP control, it’s certainly doable. The code to this device can be found here:

Once you copy that code, you can edit it if it makes sense to you, then paste it into a new device type you can define here:

Unfortunately, I haven’t had a ton of time to dedicate to that device controller lately, especially with my main focus shifting to the more secure Local IP version.