Skip to content

Instantly share code, notes, and snippets.

@rappleg
Created March 6, 2014 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rappleg/9397823 to your computer and use it in GitHub Desktop.
Save rappleg/9397823 to your computer and use it in GitHub Desktop.
/**
* Foscam
*
* Author: danny@smartthings.com
* Date: 2013-07-25
* Revisions: Chris Yard
* Edits for Foscam FI9831 commands
*/
// for the UI
metadata {
tiles {
carouselTile("cameraDetails", "device.image", width: 3, height: 2) { }
standardTile("camera", "device.image", width: 1, height: 1, canChangeIcon: false, inactiveLabel: true, canChangeBackground: false) {
state "default", label: "", action: "Image Capture.take", icon: "st.camera.dropcam-centered", backgroundColor: "#FFFFFF"
}
standardTile("take", "device.image", width: 1, height: 1, canChangeIcon: false, inactiveLabel: true, canChangeBackground: false, decoration: "flat") {
state "take", label: "", action: "Image Capture.take", icon: "st.secondary.take", nextState:"taking"
}
standardTile("left", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "take", label: "left", action: "left", icon: ""
}
standardTile("up", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "take", label: "up", action: "up", icon: ""
}
standardTile("right", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "take", label: "right", action: "right", icon: ""
}
standardTile("pause", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "pause", label: "pause", action: "pause", icon: ""
}
standardTile("down", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "down", label: "down", action: "down", icon: ""
}
standardTile("blank", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "pause", label: "", action: "pause", icon: ""
}
standardTile("set", "device.setStatus", width: 1, height: 1, canChangeIcon: false, inactiveLabel: true, canChangeBackground: false) {
state "set", label: "set", action: "set", icon: "", backgroundColor: "#FFFFFF"
state "setting", label: "set mode", action: "set", icon: "", backgroundColor:"#53a7c0"
}
standardTile("preset1", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "preset1", label: "preset 1", action: "preset1", icon: ""
}
standardTile("preset2", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "preset2", label: "preset 2", action: "preset2", icon: ""
}
standardTile("preset3", "device.image", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false, decoration: "flat") {
state "preset3", label: "preset 3", action: "preset3", icon: ""
}
main "camera"
details(["cameraDetails", "preset1", "preset2", "preset3", "take","up","set","left","pause","right","blank","down"])
}
}
def parseCameraResponse(def response) {
if (response.headers.'Content-Type'.contains("image/jpeg")) {
def imageBytes = response.data
if (imageBytes) {
storeImage(getPictureName(), imageBytes)
}
}
}
private getPictureName() {
def pictureUuid = java.util.UUID.randomUUID().toString().replaceAll('-', '')
"image" + "_$pictureUuid" + ".jpg"
}
private take() {
log.debug "take a photo"
httpGet("https://216.49.153.150:443/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&user=Camelot1&pwd=barney01") {response ->
log.debug "image captured"
parseCameraResponse(response)
}
}
def sendCmd(int num)
{
httpGet("http://Camelot1:barney01@216.49.153.150/decoder_control.cgi?command=${num}") {response ->
def content = response.data
log.debug content
}
}
def left() {
log.debug "Executing 'left'"
sendCmd(6)
}
def right() {
log.debug "Executing 'right'"
sendCmd(4)
}
def up() {
log.debug "Executing 'up'"
sendCmd(0)
}
def down() {
log.debug "Executing 'down'"
sendCmd(2)
}
def pause()
{
sendCmd(1)
}
def preset1()
{
preset(1)
}
def preset2()
{
preset(2)
}
def preset3()
{
preset(3)
}
//go to a preset location
def preset(def num)
{
if(num == null) return
if(device.currentValue("setStatus") == "setting")
{
setPreset(num)
}
else
{
log.debug "Go To Preset Location"
//1 is 31, 2 is 33, 3 is 35
def cmd = 30 + (num * 2) - 1
sendCmd(cmd)
}
}
//set the preset number to the current location
def setPreset(def num)
{
log.debug "Set Preset"
//1 is 30, 2 is 32, 3 is 34... 8 is 44
int cmd = 28 + (num * 2)
sendCmd(cmd)
log.debug "Exit Set Mode"
sendEvent(name:"setStatus", value:"set");
}
//toggle the the mode to set the preset
def set()
{
if(device.currentValue("setStatus") == "set")
{
log.debug "Entering Set Mode"
sendEvent(name:"setStatus", value:"setting");
}
else
{
log.debug "Exit Set Mode"
sendEvent(name:"setStatus", value:"set");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment