Android and Linux

Thursday, February 17, 2011

More Foscam

As I started looking into the commands to control the Foscam, I found that the SDK was released by the Foscam company. It was easy to go through it and whip up a quick script to control most of the camera functions, and I added some functions that weren't documented as well thanks to finding them in various forums. This particular one is for use on Android phones, just change "/system/bin/sh" to "/bin/sh" to run on Linux. It doesn't cover everything, just the functions I wanted to test, but it covers most of them.

#! /system/bin/sh

# Foscam control script
# fubaya @ a-more-common-hades.blogspot.com

## set these options##
user="yourname"
pass="yourpass"
ip="your cams ip or ip:port"
######################

addy="http://${user}:${pass}@${ip}"

case "$1" in

h|-h|help|--help)
echo "snap- save snapshot to /sdcard/cam.jpg
ir- turns IR on or off, must specify on or off
up/down/left/right/stop/center- starts movement, must use stop to stop movement
contrast (0-6)- must specify number
brightness (??)- must specify number, SDK says 0-255. untested
vert/horiz- start vert or horiz patrol
50/60/out- set 50hz, 60hz outdoor mode
flip/mirror- flip or mirror the image
alarm- specify on or off
mail- specify on or off to send email on motion detect
interval- image upload interval in seconds, 0 for off, 1 to 65535 for on
sense- motion sensitivity 0-4, 0 being most sensitive
reboot- reboots cam
set- set preset 1-16
go- go to preset 1-16

examples: ./ThisScript snap
./ThisScript ir off
./ThisScript alarm off
./ThisScript sense 3
./ThisScript go 12

current user/pass/ip setup for this script:
${addy}"
;;

snap)
wget -q -O /sdcard/cam.jpg "${addy}/snapshot.cgi?"
;;

ir)
[ $2 = on ] && wget -q -O - "${addy}/decoder_control.cgi?command=95"
[ $2 = off ] && wget -q -O - "${addy}/decoder_control.cgi?command=94"
;;

up)
wget -q -O - "${addy}/decoder_control.cgi?command=0"
;;

down)
wget -q -O - "${addy}/decoder_control.cgi?command=2"
;;

left)
wget -q -O - "${addy}/decoder_control.cgi?command=6"
;;

right)
wget -q -O - "${addy}/decoder_control.cgi?command=4"
;;

stop)
wget -q -O - "${addy}/decoder_control.cgi?command=3"
;;

center)
wget -q -O - "${addy}/decoder_control.cgi?command=25"
;;

contrast)
wget -q -O - "${addy}/camera_control.cgi?param=2&value=$2"
;;

brightness)
wget -q -O - "${addy}/camera_control.cgi?param=1&value=$2"
;;

vert)
wget -q -O - "${addy}/decoder_control.cgi?command=26"
;;

horiz)
wget -q -O - "${addy}/decoder_control.cgi?command=28"
;;

50)
wget -q -O - "${addy}/camera_control.cgi?param=3&value=0"
;;

60)
wget -q -O - "${addy}/camera_control.cgi?param=3&value=1"
;;

out)
wget -q -O - "${addy}/camera_control.cgi?param=3&value=2"
;;

flip)
wget -q -O - "${addy}/camera_control.cgi?param=5&value=1"
;;

mirror)
wget -q -O - "${addy}/camera_control.cgi?param=5&value=2"
;;

reboot)
wget -q -O - "${addy}/reboot.cgi"
;;

alarm)
[ $2 = off ] && wget -q -O - "${addy}/set_alarm.cgi?motion_armed=0"
[ $2 = on ] && wget -q -O - "${addy}/set_alarm.cgi?motion_armed=1"
;;

sense)
wget -q -O - "${addy}/set_alarm.cgi?motion_sensitivity=${2}"
;;

mail)
[ $2 = off ] && wget -q -O - "${addy}/set_alarm.cgi?mail=0"
[ $2 = on ] && wget -q -O - "${addy}/set_alarm.cgi?mail=1"
;;

interval)
wget -q -O - "${addy}/set_alarm.cgi?mail=${2}"
;;

set)
[ $2 = 1 ] && wget -q -O - "${addy}/decoder_control.cgi?command=30"
[ $2 = 2 ] && wget -q -O - "${addy}/decoder_control.cgi?command=32"
[ $2 = 3 ] && wget -q -O - "${addy}/decoder_control.cgi?command=34"
[ $2 = 4 ] && wget -q -O - "${addy}/decoder_control.cgi?command=36"
[ $2 = 5 ] && wget -q -O - "${addy}/decoder_control.cgi?command=38"
[ $2 = 6 ] && wget -q -O - "${addy}/decoder_control.cgi?command=40"
[ $2 = 7 ] && wget -q -O - "${addy}/decoder_control.cgi?command=42"
[ $2 = 8 ] && wget -q -O - "${addy}/decoder_control.cgi?command=44"
[ $2 = 9 ] && wget -q -O - "${addy}/decoder_control.cgi?command=46"
[ $2 = 0 ] && wget -q -O - "${addy}/decoder_control.cgi?command=48"
[ $2 = 11 ] && wget -q -O - "${addy}/decoder_control.cgi?command=50"
[ $2 = 12 ] && wget -q -O - "${addy}/decoder_control.cgi?command=52"
[ $2 = 13 ] && wget -q -O - "${addy}/decoder_control.cgi?command=54"
[ $2 = 14 ] && wget -q -O - "${addy}/decoder_control.cgi?command=56"
[ $2 = 15 ] && wget -q -O - "${addy}/decoder_control.cgi?command=58"
[ $2 = 16 ] && wget -q -O - "${addy}/decoder_control.cgi?command=60"
;;

go)
[ $2 = 1 ] && wget -q -O - "${addy}/decoder_control.cgi?command=31"
[ $2 = 2 ] && wget -q -O - "${addy}/decoder_control.cgi?command=33"
[ $2 = 3 ] && wget -q -O - "${addy}/decoder_control.cgi?command=35"
[ $2 = 4 ] && wget -q -O - "${addy}/decoder_control.cgi?command=37"
[ $2 = 5 ] && wget -q -O - "${addy}/decoder_control.cgi?command=39"
[ $2 = 6 ] && wget -q -O - "${addy}/decoder_control.cgi?command=41"
[ $2 = 7 ] && wget -q -O - "${addy}/decoder_control.cgi?command=43"
[ $2 = 8 ] && wget -q -O - "${addy}/decoder_control.cgi?command=45"
[ $2 = 9 ] && wget -q -O - "${addy}/decoder_control.cgi?command=47"
[ $2 = 10 ] && wget -q -O - "${addy}/decoder_control.cgi?command=49"
[ $2 = 11 ] && wget -q -O - "${addy}/decoder_control.cgi?command=51"
[ $2 = 12 ] && wget -q -O - "${addy}/decoder_control.cgi?command=53"
[ $2 = 13 ] && wget -q -O - "${addy}/decoder_control.cgi?command=55"
[ $2 = 14 ] && wget -q -O - "${addy}/decoder_control.cgi?command=57"
[ $2 = 15 ] && wget -q -O - "${addy}/decoder_control.cgi?command=59"
[ $2 = 16 ] && wget -q -O - "${addy}/decoder_control.cgi?command=61"
;;

*)
echo "try h for help"
;;

esac

Followers