I succeed in taking a snapshot with a IP cam triggerd by a sensor (doorsensor or motionsensor), with the plugin Netcam I can make
an event that stores the pictures in Netcam.
My problem is that I want to store the last picture and send this picture to a mail adres as a attachment, where and how do I store the cam pictures?
So I want to take a snapshot when a sensor is triggerd and then send this picture to a email adres.
Is Netcam the plugin to use? or is it better to use a script? please give me an example of a script
Snapshot storage
Moderator: Esteban
Re: Snapshot storage
This is the script I use to send an email when someone presses the doorbell. It is triggered by pressing the doorbell and takes a picture of the person in front of the bell and embeds this message in an email. The part that attaches the photo to the email is a bit complicated because I wanted the photo embedded within the message so it is instantly visible when openening the message without the need to open an attachment. So if you do not need this functionality, the code can be simplified. You do not require any plugin for this script.
Things that you need to specify are:
<hostname of camera>: The host name or ip address of your IP cam
<url to take snapshot>: The url (without the host name) that triggers making a snapshot (this is specific for each type of cam.
<sender address>: The email address used as sender address
<recpient address>: The email address the message must be sent to
<hostname of homeseer>: The host name or ip address of the server running Homeseer. This is required to enable email clients that do not support embedded images to capture the image via the Homeseer web server. Off course this is only possible when you Homeseer server is accessable from the location where you read the email.
<hostname of SMTP mail server>: The host name or ip address of the server (SMTP) you use to send any mail. This is probably a server at your ISP.
Things that you need to specify are:
<hostname of camera>: The host name or ip address of your IP cam
<url to take snapshot>: The url (without the host name) that triggers making a snapshot (this is specific for each type of cam.
<sender address>: The email address used as sender address
<recpient address>: The email address the message must be sent to
<hostname of homeseer>: The host name or ip address of the server running Homeseer. This is required to enable email clients that do not support embedded images to capture the image via the Homeseer web server. Off course this is only possible when you Homeseer server is accessable from the location where you read the email.
<hostname of SMTP mail server>: The host name or ip address of the server (SMTP) you use to send any mail. This is probably a server at your ISP.
Code: Select all
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Sub Main(parm as object)
Dim sFileName As String
Dim mail As New MailMessage()
Dim htmlView As AlternateView
Dim plainView As AlternateView
Dim now As DateTime
' Get Timestamp
now = DateTime.Now
sFileName = "entrance_" & now.Year & now.Month.ToString() & now.Day.ToString() & "-" & now.Hour.ToString() + now.Minute.ToString() & ".jpg"
' Take pictures
hs.GetURLImage("<hostname of camera>","<url to take snapshot>",false,80,"/html/snapshots/" & sFileName)
' Set the addresses
mail.From = New MailAddress("<sender address>")
mail.To.Add("<recipient address>")
' Set the subject
mail.Subject = "Er wordt gebeld"
' Create the text only part for those readers not able to view HTML with embedded images (only valid when your homeseer server is accessable from where you receive your email)
plainView = AlternateView.CreateAlternateViewFromString("Wie staat er voor de deur?" & vbCrLf & "https://<hostname of homeseer>/snapshots/" & sFilename, Nothing, "text/plain")
' Create the HTML mail with the embedded photo
htmlView = AlternateView.CreateAlternateViewFromString("Wie staat er voor de deur?<br /><img src=cid:deurbel>", Nothing, "text/html")
Dim imageView As New AlternateView(hs.GetAppPath & "/html/snapshots/" & sFileName, MediaTypeNames.Image.Jpeg)
imageView.ContentId = "deurbel"
imageView.TransferEncoding = TransferEncoding.Base64
Dim data As New Attachment(imageView.ContentStream, MediaTypeNames.Image.Jpeg)
data.ContentDisposition.Inline = true
data.ContentId = "deurbel"
data.TransferEncoding = TransferEncoding.Base64
data.Name = hs.GetAppPath & "/html/snapshots/" & sFileName
' Add the views
mail.AlternateViews.Add(plainView)
mail.AlternateViews.Add(htmlView)
mail.Attachments.Add(data)
' Send the message
Dim smtp As New SmtpClient("<hostname of SMTP mail server>")
smtp.Send(mail)
End Sub
Rene.
Re: Snapshot storage
Thanks for your quick reply, I got another script line from an other member.
Run script: &hs.GetURLImage "http://user:password@192.168.1.123","/axis-cgi/jpg/image.cgi?camera=3",false,80,"/html/images/CamAlerts/GarageDoorLast.jpg"
what is camera=3 in this line and what is the function of false,80? is html/images/CamAlerts the directory to save the pictures?
Sorry for the lot of questions but I have never used a script in HS.
Run script: &hs.GetURLImage "http://user:password@192.168.1.123","/axis-cgi/jpg/image.cgi?camera=3",false,80,"/html/images/CamAlerts/GarageDoorLast.jpg"
what is camera=3 in this line and what is the function of false,80? is html/images/CamAlerts the directory to save the pictures?
Sorry for the lot of questions but I have never used a script in HS.
Re: Snapshot storage
This is probably a script-line from somebody using an Axis 240/241q. This is a video encoder which serves 4 videostreams. 'Camera=3' indicates the feed that is requested. You don't need that if you're using a regular Axis camera.
Use something along those lines:
http://www.yourIP.com/axis-cgi/jpg/imag ... on=640x480
'False, 80' is for Homeseer.
'False':Use TRUE to strip HTML tags from the returned page or FALSE to not alter the page.
'80': Is the port of the camera.
Update: After reading your other post (Please don't ask the same question in several threads btw) I see you don't have an Axis camera. That means that these example URLs won't work with your camera. These only function when you have an Axis on the other end. For it to work you need to find out via what URL pictures can be requested from your own camera and use that.
Use something along those lines:
http://www.yourIP.com/axis-cgi/jpg/imag ... on=640x480
'False, 80' is for Homeseer.
'False':Use TRUE to strip HTML tags from the returned page or FALSE to not alter the page.
'80': Is the port of the camera.
Update: After reading your other post (Please don't ask the same question in several threads btw) I see you don't have an Axis camera. That means that these example URLs won't work with your camera. These only function when you have an Axis on the other end. For it to work you need to find out via what URL pictures can be requested from your own camera and use that.
Re: Snapshot storage
Here is an overview of what is what:
hs.GetURLImage "http://YOUR-CAMERA-IP","CAMERA-IMAGE-URL",false,80,"NAME-AND-LOCATION-NEW-IMAGE"
YOUR-CAMERA-IP: The http address of the camera.
CAMERA-IMAGE-URL: The URL that tells your camera to give a picture.
NAME-AND-LOCATION-NEW-IMAGE: You need to give the image you receive a name and save it in a folder. This is what you indicate here. For example if you indicate '/html/doorbell.jpg' it will save a file called 'doorbell.jpg' in the HTML directory of Homeseer.
This should give you something like this:
hs.GetURLImage "http://192.168.0.2","/blablamypanasoniccamera/getimageforme.cgi?image=320x240",false,80,"/html/doorbell.jpg"
For more information do some searches on the forum, there's plenty of information on here already. For scripting, the HELP button in Homeseer gives all the information necessary to help you getting started with this.
Good luck!
hs.GetURLImage "http://YOUR-CAMERA-IP","CAMERA-IMAGE-URL",false,80,"NAME-AND-LOCATION-NEW-IMAGE"
YOUR-CAMERA-IP: The http address of the camera.
CAMERA-IMAGE-URL: The URL that tells your camera to give a picture.
NAME-AND-LOCATION-NEW-IMAGE: You need to give the image you receive a name and save it in a folder. This is what you indicate here. For example if you indicate '/html/doorbell.jpg' it will save a file called 'doorbell.jpg' in the HTML directory of Homeseer.
This should give you something like this:
hs.GetURLImage "http://192.168.0.2","/blablamypanasoniccamera/getimageforme.cgi?image=320x240",false,80,"/html/doorbell.jpg"
For more information do some searches on the forum, there's plenty of information on here already. For scripting, the HELP button in Homeseer gives all the information necessary to help you getting started with this.
Good luck!