UI5 & IP Camera: Archives & Scenes busted, iVera works!

And for archive picture on a local storage (nas synology for exple) ?

thanks

You can’t redirect the MiOS archiving to a local storage. What you can do is make a Lua script that will get a picture from the camera and store it wherever you want.

mcvflorin, thank for your support.

could you provide us an example of the lua code needed to copy a file i nthe archive?

Thank you in advance
REgards,
matteo

[quote=“teonebello, post:23, topic:170049”]mcvflorin, thank for your support.

could you provide us an example of the lua code needed to copy a file i nthe archive?

Thank you in advance
REgards,
matteo

+1

and :wink: + 10000 for

mcvflorin, thank for your support.

This is the code that works on my Vera. In this case the server was my computer, and the camera was a VistaCam. You’ll need to modify the variables according to your setup. This code is designed to be used in a scene with an event (e.g. a motion sensor is tripped), but it can be easily modified to be able to run at a regular time interval (e.g. take a snapshot every x minutes).

-- The device ID of the camera
local CAMERA_DID = 14
-- The URL of the server
local SERVER_URL = "ftp://192.168.8.149"

-- The URL to get a snapshot from the camera
local camUrl = luup.devices[CAMERA_DID].ip .. "/img/snapshot.cgi?size=3&quality=1"
-- The image file name
local fileName = "/tmp/img"..os.time()..".jpg"

-- Command to get the image from the camera.
local getImgCmd = "curl -o "..fileName.." "..camUrl
-- Command to upload the image on the server.
local putImgCmd = "curl -T "..fileName.." "..SERVER_URL
-- Command to delete the temporary file.
local delImgCmd = "rm "..fileName

function uploadImage()
	os.execute(putImgCmd)
end

function deleteImage()
	os.execute(delImgCmd)
end

os.execute(getImgCmd)
luup.call_delay("uploadImage", 3)
luup.call_delay("deleteImage", 6)

thanks for your code

and to sent jpg to email ?

when motion sensor is trigged

thanks

It’s possible to send e-mail with curl, but I don’t know if it’s possible to attach files. Maybe someone that has tried this before can help you.

I have a mix of cameras (DLink, Foscam and a few others). They work great under UI4 and UI5 (Vera2 and Vera3). Within Vera I have them take pictures based on alarm system sensor events and things like that and they work very well. However the motion sensors and sound and such that the cameras detect do not function with Vera. I think that is what is being asked here. So to have the best of both words, work the cameras into Vera but also go into the Camera software itself and almost every IP camera I’ve seen allows you to setup motion detection, some even do sound detection. You can also enter email server information and have pictures emailed to you as the camera senses events happening. Of course all of this happens outside of Vera.
For example I have a Foscam outside Camera that I have set detection zones on my driveway. Whenever a car enters that zone on my driveway I get an email showing me the car and/or person. Again this is all outside of Vera.
Maybe someday someone much smarter than I at programming will be able to program all of the camera features to work with Vera but until that happens using the combination of Vera and the built in Camera software features will likely get you everything you want.

[quote=“mcvflorin, post:25, topic:170049”]This is the code that works on my Vera. In this case the server was my computer, and the camera was a VistaCam. You’ll need to modify the variables according to your setup. This code is designed to be used in a scene with an event (e.g. a motion sensor is tripped), but it can be easily modified to be able to run at a regular time interval (e.g. take a snapshot every x minutes).

[code]
– The device ID of the camera
local CAMERA_DID = 14
– The URL of the server
local SERVER_URL = “ftp://192.168.8.149

– The URL to get a snapshot from the camera
local camUrl = luup.devices[CAMERA_DID].ip … “/img/snapshot.cgi?size=3&quality=1”
– The image file name
local fileName = “/tmp/img”…os.time()…“.jpg”

– Command to get the image from the camera.
local getImgCmd = "curl -o “…fileName…” "…camUrl
– Command to upload the image on the server.
local putImgCmd = "curl -T “…fileName…” "…SERVER_URL
– Command to delete the temporary file.
local delImgCmd = "rm "…fileName

function uploadImage()
os.execute(putImgCmd)
end

function deleteImage()
os.execute(delImgCmd)
end

os.execute(getImgCmd)
luup.call_delay(“uploadImage”, 3)
luup.call_delay(“deleteImage”, 6)
[/code][/quote]

Hi Mcvflorin,

this code works fine but I wanted to take 10 pictures in 10 seconds if a trigger that initiates

thanks

Hello

i have tested this i = 0 while i < 15 do os.execute(getImgCmd) print (i) i = i + 0.5 end luup.call_delay("uploadImage", 15) luup.call_delay("deleteImage", 25)

but no good

have you a idea ?

thanks

I don’t think you can take 10 pictures in 10 second, at least not using this method. It takes more than a second to get the image, and more than a second to upload the image.

i have tested with sleep but no result

and i have tested

i upload all jpg at the end ? and delete after with rm *.jpg

but the code incorrect with “*.jpg” at the place of fileName

have you a solution ?

Can you post your code?

hello

the problem is for the upload of the picture
curl -T “[*.jpg]” error with the caracter *

mput or mget is good with vera ?

[quote=“mcvflorin, post:25, topic:170049”]This is the code that works on my Vera. In this case the server was my computer, and the camera was a VistaCam. You’ll need to modify the variables according to your setup. This code is designed to be used in a scene with an event (e.g. a motion sensor is tripped), but it can be easily modified to be able to run at a regular time interval (e.g. take a snapshot every x minutes).

[code]
– The device ID of the camera
local CAMERA_DID = 14
– The URL of the server
local SERVER_URL = “ftp://192.168.8.149

– The URL to get a snapshot from the camera
local camUrl = luup.devices[CAMERA_DID].ip … “/img/snapshot.cgi?size=3&quality=1”
– The image file name
local fileName = “/tmp/img”…os.time()…“.jpg”

– Command to get the image from the camera.
local getImgCmd = "curl -o “…fileName…” "…camUrl
– Command to upload the image on the server.
local putImgCmd = "curl -T “…fileName…” "…SERVER_URL
– Command to delete the temporary file.
local delImgCmd = "rm "…fileName

function uploadImage()
os.execute(putImgCmd)
end

function deleteImage()
os.execute(delImgCmd)
end

os.execute(getImgCmd)
luup.call_delay(“uploadImage”, 3)
luup.call_delay(“deleteImage”, 6)
[/code][/quote]

Thank you for this code, florin, but is it possible to do the same thing with a video???

Hello Florin,

Iv’e tried your code with an authenticated ftp. I can get a jpg file in the ftp, but I cannot read it! Any idea? Where is my error? I can send you the file I get as the result, if you want. Here’s the code I use:

– The device ID of the camera
local CAMERA_DID = 73
– The URL of the server
local SERVER_URL = “ftp://Mylogin:Mypasswrd@myIP/home/

– The URL to get a snapshot from the camera
local camUrl = luup.devices[CAMERA_DID].ip … “/snap.jpg”
– The image file name
local fileName = “/tmp/img”…os.time()…“.jpg”

– Command to get the image from the camera.
local getImgCmd = "curl -o “…fileName…” "…camUrl
– Command to upload the image on the server.
local putImgCmd = "curl -T “…fileName…” "…SERVER_URL
– Command to delete the temporary file.
local delImgCmd = "rm "…fileName

function uploadImage()
os.execute(putImgCmd)
end

function deleteImage()
os.execute(delImgCmd)
end

os.execute(getImgCmd)
luup.call_delay(“uploadImage”, 3)
luup.call_delay(“deleteImage”, 6)

Ok, I’ve opened the uploaded file and it’s an XML file talking about an error username: The username of the ftp is correct, otherwise the file could’t have been uploaded, any idea???

ipCAM You input an error username, please input again!

[quote=“davidd1205”]thanks for your code

and to sent jpg to email ?

when motion sensor is trigged

thanks[/quote]

This is the script i ended up with. One shortcoming is that i am not sure how to support smtps with lua sockets. Another is that i don’t seem to be able to extract URL variable from camera definition so i kind of hardcoded a few choices here. You need to specify device id and the url stub for a still to download from.

It uploads whatever many emails you configure, with 2 snapshots in each, with reasonable pauses made between each of snapshots. It works for 3 types of cameras i have. Improvements for the aforementioned shortcomings are welcome (surely, i would like to use TLS and upload it directly to gmail instead of having 2 providers talking plain smtp to each other).


local smtp = require("socket.smtp")
local mime = require("mime")
local ltn12 = require("ltn12")

-- how many emails with snapshots in this scene to send.
local EMAILS = 5

-- The device ID of the camera
-- and camera specific stuff. 
-- Question: how do we yank perhaps configured 
-- camera user and password out of the vera configuration, 
-- along with the image url?

local CAMERA_DID = 3

-- foscam setting: 
-- local CAMERA_JPGURL = "/snapshot.cgi"

-- ASANTE VOYAGER
-- local CAMERA_JPGURL = "/image.cgi"

-- TRENDNET PTZ 
-- local CAMERA_JPGURL = "/cgi/jpg/image.cgi"

local CAMERA_USER = luup.devices[CAMERA_DID].user..":"..luup.devices[CAMERA_DID].pass
local CAMERA_NAME = luup.devices[CAMERA_DID].description

-- smtp stuff configuration
local smtpFrom = "<abc@comcast.net>"
local smtpTo =  "<abc@gmail.com>"
local smtpServer = "smtp.comcast.net"
local smtpUser = ""
local smtpPassword = ""


-- The URL to get a snapshot from the camera
-- local camUrl = luup.devices[CAMERA_DID].ip.."/"..luup.devices[CAMERA_DID].URL
local camUrl = luup.devices[CAMERA_DID].ip..CAMERA_JPGURL


-- The image file name
local fileName1 = "/tmp/img"..os.time()..CAMERA_DID.."-1.jpg"
local fileName2 = "/tmp/img"..os.time()..CAMERA_DID.."-2.jpg"

-- Command to get the image from the camera.
local getImgCmd1 = "curl -o "..fileName1.." -u '"..CAMERA_USER.."' "..camUrl
local getImgCmd2 = "curl -o "..fileName2.." -u '"..CAMERA_USER.."' "..camUrl

-- Command to delete the temporary file.
local delImgCmd = "rm "..fileName1.." "..fileName2

function sendImages()  
  
  mesgt = {
    headers = {
      from = smtpFrom,
      to = smtpTo,
      subject = "Vera camera '"..CAMERA_NAME.."' snapshots scene."
    },
    body = { 
      preamble = "Mime attachements enclosed",
      -- The mime.eol low-level filter normalizes end-of-line markers
      [1] = { 
	body = mime.eol(0,[[
	  This email is formed by a Vera scene.
	  Camera name: ]]..CAMERA_NAME..[[. 
	]]) 
      },
      [2] = { 
	headers = {
	  ["content-type"] = 'image/jpeg; name="snapshot.jpg"',
	  ["content-disposition"] = 'attachment; filename="snapshot.jpg"',
	  ["content-description"] = 'security cam snapshot',
	  ["content-transfer-encoding"] = "BASE64"
	},
	body = ltn12.source.chain(
	  ltn12.source.file(io.open(fileName1, "rb")),
	  ltn12.filter.chain(
	    mime.encode("base64"),
	    mime.wrap()
	  )
	)
      },
      [3] = { 
	headers = {
	  ["content-type"] = 'image/jpeg; name="snapshot-2.jpg"',
	  ["content-disposition"] = 'attachment; filename="snapshot-2.jpg"',
	  ["content-description"] = 'security cam snapshot',
	  ["content-transfer-encoding"] = "BASE64"
	},
	body = ltn12.source.chain(
	  ltn12.source.file(io.open(fileName2, "rb")),
	  ltn12.filter.chain(
	    mime.encode("base64"),
	    mime.wrap()
	  )
	)
      },
      epilogue = "Home Vera generated"
    }
  }
  
  r, e = smtp.send {
    from = smtpFrom,
    rcpt = smtpTo, 
    source = smtp.message(mesgt),
    server = smtpServer,
    port = 25,
    user = smtpUser,
    password = smtpPassword
  } 
end

function deleteImage()
  os.execute(delImgCmd)
end

i = 0 
while i < EMAILS do 
  os.execute(getImgCmd1)
  luup.sleep(1000)
  os.execute(getImgCmd2)
  sendImages()
  luup.sleep(2000)
  i = i + 1 
end

luup.call_delay("deleteImage", 2)

Actually it seems that trigger execution does not create a worker thread per scene so sending 5 emails with sleeps would cause quite a bit of a delay before next scene’s script is fired. So i rewrote it in completely in terms of asynchronous callbacks. DELAY variable specify delay between snapshots in seconds and should not be less than 0.5. As usual, put your device id, camera specific url and smtp parameters.

local smtp = require("socket.smtp")
local mime = require("mime")
local ltn12 = require("ltn12")

-- how many emails with snapshots in this scene to send.
local EMAILS = 5
local DELAY = 0.700

-- The device ID of the camera
-- and camera specific stuff. 
-- Question: how do we yank perhaps configured 
-- camera user and password out of the vera configuration, 
-- along with the image url?

local CAMERA_DID = 3

-- foscam setting: 
-- local CAMERA_JPGURL = "/snapshot.cgi"

-- ASANTE VOYAGER
-- local CAMERA_JPGURL = "/image.cgi"

-- TRENDNET PTZ 
-- local CAMERA_JPGURL = "/cgi/jpg/image.cgi"

local CAMERA_USER = luup.devices[CAMERA_DID].user..":"..luup.devices[CAMERA_DID].pass
local CAMERA_NAME = luup.devices[CAMERA_DID].description

-- smtp stuff configuration
local smtpFrom = ""
local smtpTo =  ""
local smtpServer = "smtp.comcast.net"
local smtpUser = ""
local smtpPassword = ""


-- The URL to get a snapshot from the camera
-- local camUrl = luup.devices[CAMERA_DID].ip.."/"..luup.devices[CAMERA_DID].URL
local camUrl = luup.devices[CAMERA_DID].ip..CAMERA_JPGURL


-- The image file name
local fileName1 = "/tmp/img"..os.time()..CAMERA_DID.."-1.jpg"
local fileName2 = "/tmp/img"..os.time()..CAMERA_DID.."-2.jpg"

-- Command to get the image from the camera.
local getImgCmd1 = "curl -o "..fileName1.." -u '"..CAMERA_USER.."' "..camUrl
local getImgCmd2 = "curl -o "..fileName2.." -u '"..CAMERA_USER.."' "..camUrl

-- Command to delete the temporary file.
local delImgCmd = "rm "..fileName1.." "..fileName2

function sendImages()  
  
  mesgt = {
    headers = {
      from = smtpFrom,
      to = smtpTo,
      subject = "Vera camera '"..CAMERA_NAME.."' snapshots scene."
    },
    body = { 
      preamble = "Mime attachements enclosed",
      -- The mime.eol low-level filter normalizes end-of-line markers
      [1] = { 
	body = mime.eol(0,[[
	  This email is formed by a Vera scene.
	  Camera name: ]]..CAMERA_NAME..[[. 
	]]) 
      },
      [2] = { 
	headers = {
	  ["content-type"] = 'image/jpeg; name="snapshot.jpg"',
	  ["content-disposition"] = 'attachment; filename="snapshot.jpg"',
	  ["content-description"] = 'security cam snapshot',
	  ["content-transfer-encoding"] = "BASE64"
	},
	body = ltn12.source.chain(
	  ltn12.source.file(io.open(fileName1, "rb")),
	  ltn12.filter.chain(
	    mime.encode("base64"),
	    mime.wrap()
	  )
	)
      },
      [3] = { 
	headers = {
	  ["content-type"] = 'image/jpeg; name="snapshot-2.jpg"',
	  ["content-disposition"] = 'attachment; filename="snapshot-2.jpg"',
	  ["content-description"] = 'security cam snapshot',
	  ["content-transfer-encoding"] = "BASE64"
	},
	body = ltn12.source.chain(
	  ltn12.source.file(io.open(fileName2, "rb")),
	  ltn12.filter.chain(
	    mime.encode("base64"),
	    mime.wrap()
	  )
	)
      },
      epilogue = "Home Vera generated"
    }
  }
  
  r, e = smtp.send {
    from = smtpFrom,
    rcpt = smtpTo, 
    source = smtp.message(mesgt),
    server = smtpServer,
    port = 25,
    user = smtpUser,
    password = smtpPassword
  } 
end

function deleteImage()
  os.execute(delImgCmd)
end

local snapshot = 0

function processEmail()
  if (EMAILS>0) then
    if ( snapshot==0 ) then
      snapshot = 1
      os.execute(getImgCmd1)
      luup.call_delay("processEmail",DELAY)
    else 
      snapshot = 0
      EMAILS = EMAILS - 1
      os.execute(getImgCmd2)
      sendImages() 
      luup.call_delay("processEmail",DELAY-0.5)
    end
  else 
    deleteImage()
  end 
end

processEmail()