I’ve been able to display the snapshot and video on my sitemap from my Hikvision DS-2CD2332-I What i want to do is add a button which takes a snapshot and sends it to my e-mail. I’ve actually got the button and the mail binding work, but i can’t get it to extract the photo.
I learned from a thread (that i can no longer find) that you cant use user:password in the mail binding, but apparently you can grab the snapshot and send it via e-mail some other way using the HTTP binding, but I can’t figure out how.
If I remember it right, you have to grab the picture through exec binding (curl …), save the picture in your local file system (./webapps/static/*) and then send the mail with this local copy.
2016-07-17 16:19:58.486 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine 'curl -m 10 -o /opt/openhab/webapps/static/pic.jpg http://user:pass@*****.selfhost.eu:58081/cgi-bin/video.cgi?msubmenu=jpg’
2016-07-17 16:19:58.512 [ERROR] [nhab.action.mail.internal.Mail] - Error adding attachment to email.
org.apache.commons.mail.EmailException: Invalid URL set:file:/opt/openhab/webapps/static/pic.jpg
at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:395) ~[commons-email-1.4.jar:1.4]
at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:339) ~[commons-email-1.4.jar:1.4]
at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:120) [bundlefile:na]
at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:89) [bundlefile:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor958.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:69) [org.openhab.model.script_1.8.2.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor959.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor973.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.openhab.model.script.internal.engine.ScriptImpl.execute(ScriptImpl.java:59) [org.openhab.model.script_1.8.2.jar:na]
at org.openhab.core.scriptengine.ScriptExecutionThread.run(ScriptExecutionThread.java:44) [org.openhab.core.scriptengine_1.8.2.jar:na]
Caused by: java.io.FileNotFoundException: /opt/openhab/webapps/static/pic.jpg (Datei oder Verzeichnis nicht gefunden)
at java.io.FileInputStream.open(Native Method) ~[na:1.7.0_60]
at java.io.FileInputStream.(FileInputStream.java:146) ~[na:1.7.0_60]
at java.io.FileInputStream.(FileInputStream.java:101) ~[na:1.7.0_60]
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) ~[na:1.7.0_60]
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) ~[na:1.7.0_60]
at java.net.URL.openStream(URL.java:1037) ~[na:1.7.0_60]
at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:390) ~[commons-email-1.4.jar:1.4]
… 29 common frames omitted
2016-07-17 16:20:05.666 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine 'rm /opt/openhab/webapps/static/pic.jpg’
2016-07-17 16:21:01.291 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘rm /opt/openhab/webapps/static/pic.jpg’
when
Item frontdoor_doorbell changed to ON
then
var FrontDoorCam = “FrontDoor”+ now.toString (“HH-mm_dd-MM-yyyy”) +".jpg"
var doorbellmessage = “Det ringet på døren kl. “+ now.toString (“HH:mm dd-MM-yyyy”) +”\nVi var sikkert ikke hjemme"
executeCommandLine(“wget http://admin:passwd@192.168.1.???/Streaming/Channels/1/picture -O /tmp/” +FrontDoorCam”,5)
Thread::sleep(5000)
sendMail("mail@gmail.com", “Det ringer på døren”, doorbellmessage, “file:///tmp/” +FrontDoorCam)
sendMail("mail@gmail.com", “Det ringer på døren”, doorbellmessage, “file:///tmp/” +FrontDoorCam)
end
I have also adapted one of my rules to use this store-send-timer-delete approach.
Now an image file is created, but when the e-mail including the attachment should be sent, I also see this error in the log:
I’m running OpenHAB 1.8.1 on a gentoo linux box, and I don’t understand why in the log there is only one slash (/) between file: and my file’s location, even though the attachment in the sendMail command is configured as
"file:///space/" + outputFile
Is there some restriction on where the file needs to be stored, or what is happening here?
OP here still trying to get things to work. My guess with @danielgauss148 is that it is using an escape character. Basically if you did only two // you would comment out the code but adding a third shows the system only two.
so in open hab i think ///=//
Anyway.
I’m closer, but mine still isn’t working.
Here is my rule:
rule "Frontdoor bell"
when
Item photoSwitch changed to ON
then
I came across this post when researching how to make this work with my Hikvision camera. I think I have a basic solution started that may work for you. I leveraged the avconv utility to grab an image from the rtsp stream.
First install the avconv utility:
sudo apt-get install lib-avtools
Next create a rule to grab a snapshot and e-mail a picture. I used a trigger of a motion detector detecting motion:
rule "SendCameraPic"
when
Item FrontPorchMotion changed to OPEN
then {
executeCommandLine("/usr/bin/avconv -loglevel fatal -rtsp_transport tcp -i ''rtsp://user:password@ip_address:554/PSIA/streaming/channels/101/'' -r 1 -vframes 1 /tmp/pic.jpg -y", 5000)
sendMail('emailaddress', "Picture captured from camera", "The attached picture was captured when motion was detected", "file:///tmp/pic.jpg");
}
Watch within the executeCommandLine that the single quotes around the rstp string are escaped (two single quotes, not a double quote).
I just got this working now, so will need to test to see if it is stable. I hope it helps.