Automatic IP camera snapshot on intercom call
Example: Automatic IP camera snapshot on intercom call
Task
The example below shows how to snapshot IP camera when the intercom call is done and send this snapshot over email.
Resident script
Add the following resident script and run once.
- --***********************************************************--
- --** Email image attachment created by Erwin van der Zwart **--
- --***********************************************************--
- --******************* Start of parameters *******************--
- --***********************************************************--
-
- --Gmail (smtp) username !IMPORTANT!
- user = 'YOUR.ADDRESS@GMAIL.COM'
-
- --Gmail (smtp) password !IMPORTANT!
- password = 'YOUR GMAIL PASSWORD'
-
- --Sender for e-mail
- from = '<your.address@gmail.com>'
- alias_from = 'YOUR FULL NAME'
-
- --Recipient for e-mail
- to = '<recipient@domain.com>'
- alias_to = 'recipient full name'
-
- --Subject for e-mail
- subject = 'Snapshot from camera automaticly send by homeLYnk'
-
- --Attachment and filetype (set filetype as 'gif', 'png', 'bmp', 'jpg' or 'jpeg' according image source)
- image_type = 'jpeg'
- image_name_attachment = 'snapshot'
- source_image_url = 'http://your.camara.ip/snapshot.jpeg'
- image_description = 'Snapshot from IP Camera'
-
- --Message on bottom of email (will only be showed when client don't understand attachment)
- epilogue = 'End of message'
-
- --***********************************************************--
- --******************** End of parameters ********************--
- --***********************************************************--
- --********** DON'T CHANGE ANYTHING UNDER THIS LINE **********--
- --***********************************************************--
-
- --Get remote (from HTTP) image and put image file to HL (will be deleted when end of script)
- os.execute('wget -O /www/scada/vis/' .. image_name_attachment .. '.' .. image_type .. ' ' .. source_image_url .. '')
-
- --Create filename and location
- local fileName = '/www/scada/vis/' .. image_name_attachment .. '.' .. image_type
-
- --Create table to include mail settings
- local settings = {
- from = from,
- rcpt = to,
- user = user,
- password = password,
- server = 'smtp.gmail.com',
- port = 465,
- secure = 'sslv23',
- }
-
- --Load required modules to send email with attachment
- local smtp = require("socket.smtp")
- local mime = require("mime")
- local ltn12 = require("ltn12")
-
- --Create e-mail header
- settings.source = smtp.message{
- headers = {
- from = '' .. alias_from .. ' ' .. from .. '',
- to = '' .. alias_to .. ' ' .. to .. '',
- subject = subject
- },
-
- --Load attachment inside body
- body = {
- preamble = "",
- [1] = {
- headers = {
- ["content-type"] = 'image/' .. image_type .. '; name="' .. image_name_attachment .. '.' .. image_type .. '"',
- ["content-disposition"] = 'attachment; filename="' .. image_name_attachment .. '.' .. image_type .. '"',
- ["content-description"] = '' .. image_description .. '',
- ["content-transfer-encoding"] = "BASE64"
- },
-
- body = ltn12.source.chain(
- ltn12.source.file(io.open(fileName, "rb")),
- ltn12.filter.chain(
- mime.encode("base64"),
- mime.wrap()
- )
- )
- },
- epilogue = epilogue
- }
- }
-
- --Send the email
- r, e = smtp.send(settings)
-
- --Create alert when sending gives an error with error message
- if (e) then
- alert("Could not send email: ", e, "\n")
- end
-
- --Delete downloaded image file from HL
- os.remove(fileName)