Hi Everyone,
I have been working on code for my DLink Web camera send a pictures via email. I have been able to get the email to send however, I am unable to get the image to send as an attachment or in the body of the email.
Here is the code, perhaps someone can help me out…
Is there a variable that is used that is storing the picture?
/** Dlink Cam */
preferences
{
input("username", "text", title:"Username", description: "Dlink Username:")
input("password", "password", title:"Password", description: "DLink Password:")
input("URL", "text", title:"IP", description: "URL of Camera")
input("port", "text", title:"port", description: "Port")
}
metadata {
tiles {
carouselTile("cameraDetails", "device.image", width: 3, height: 3) { }
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("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.custom.buttons.rec", backgroundColor: "#ccffcc", nextState: "on"
state "on", label: 'On', action: "switch.off", icon: "st.custom.buttons.rec", backgroundColor: "#EE0000", nextState: "off"
}
main "camera"
details(["cameraDetails","take","button"])
}
}
def parseCameraResponse(def response) {
if(response.headers.'Content-Type'.contains("image/jpeg")) {
def imageBytes = response.data
if(imageBytes) {
storeImage(getPictureName(), imageBytes)
sendpic()
}
}
}
private getPictureName() {
def pictureUuid = java.util.UUID.randomUUID().toString().replaceAll('-', '')
"image" + "_$pictureUuid" + ".jpg"
}
private take() {
log.debug("Take a photo")
//removed hard coded URL and replaced to keep my info private..
httpGet("http://username:password@ip:port/image/jpeg.cgi"){response ->
log.debug("Image captured")
parseCameraResponse(response)
}
}
// SendGrid Code from API
def sendpic(){
httpGet("http://sendgrid.com/api/mail.send.json?to=seanstozki%40me.com&toname=Sean&from=Sastozki%40optonline.net&fromname=SmartThings&subject=Picture&text=Pictture&api_user=xxxxx&api_key=xxxxx"){response ->
}
log.debug ("sending photo")
}