Image to Email via SendGrind


(SStozki) #1

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")
}
 

D-Link IP Camera device type (DCS-930L tested)
(Austin Fonacier) #2

That is pretty awesome. I hope the SmartThings team provides us with a standard API to store and /or send images out.


(SStozki) #3

@austinrf

It’s pretty neat, I agree that ST team needs to work on something that will send our images.

The storing ability has been working with the storeImage(getPictureName(), imageBytes) function. From what I found the image is stored in the cloud and has a url of https://smartthings-smartsense-camera.s3.amazonaws.com/xxxxxx.

I did find a few other sample codes that have images stored in private AWS and send out a link to the image. However, since my coding days are long behind me (and the coding world had changed) I am trying to refresh to a point that I can work with Smartthings. But it’s a bit frustration trying to figure this out.

Any suggestions or help would be appreciated :slight_smile:


#4

@Sean
Did you ever get the email pics from your DLink cameras to work?

With my DLink DCS-930L cameras I’m not interested in retrieving or viewing my pics from ST, I’m just looking for a simple method to turn the camera on and off or to turn the motion on and off using the AWAY and HOME modes. After that I will let the DLink software directly email me the motion pics when the camera and motion are on. Currently I’m using a ST SmartPower Outlet on one of my cameras to do this but it’s too expensive and silly to have to put them on each camera.


(SStozki) #5

@Dave

I have not been able to get this. I am just able to view the photo in the Smartthings APP.


#6

@Sean
You might be interested in this code that Scott is working on, maybe you can help us get it up and running! See post #73

D-Link IP Camera device type (DCS-930L tested)