My headache is, that the e-mail attachment has no file extension, but is only named “encoder”, which my mobile phone doesn’t like. I have tried just to fill in “.png” following the filename “encoder” in the door cam URL, but that’s not working at all. Opening the e-mail attachment on my Win10 PC, lets me choose what program to use, and using for an example Windows Paint, lets me see the image snapshot.
I would like to know, if anyone can explain a way to provide a file extension to the attachment?
I just happened to be playing with exactly the same thing. After a lot of hours of testing and googling I managed to sort of make it work. I think you need to just save it the image in your OS and then send it via email as an attachment
I tested this with my foscam and it works
Here is what I did
// Create a file in /home/openhab/ with the current time and date. Make sure /home/openhab folder exists and the permissions are set to openhab user
var outputFile = "/home/openhab/FrontDoor"+ now.toString ("HH-mm_dd-MM-yyyy") +".jpg"
// the url where you will be sending the query.
var url = "http://192.XX.XX.XX:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=admin&pwd=XXXXX"
//here we construct the command to execute
var cmd = "wget --output-document " + outputFile + " " + url
// here is the execute command. You need to put a delay of 5 seconds otherwise it does not work. Not sure why is that
executeCommandLine(cmd,5000)
// send the email
sendMail("XXX@mail.com", "Camera snapshots", "Here is a camera snapshot", "file:///" + outputFile)
Initially I can not make it to work. I’m pretty sure it has something to do with setting the file path.
I’m running OpenHAB on a Windows Homeserver, from C:\openHAB2. Here I have made a library named temp. So my wish is to write the file in C:\openHAB2\temp\
I have commented out the “send mail part” of the rule, so only the execute command is done when “ringing my door bell”
I’m in doubt if I shall use “/” or “”, but have tried to define the path with:
var outputFile = "/temp/FrontDoor"+ now.toString ("HH-mm_dd-MM-yyyy") +".jpg"
and
var outputFile = "C:/openHAB2/temp/FrontDoor"+ now.toString ("HH-mm_dd-MM-yyyy") +".jpg"
Both generates the following warn in the OpenHAB log, and no file appear in the library “temp”
08:22:29.399 [WARN ] [lipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “wget” (in directory “.”): CreateProcess error=2, The system cannot find the file specified)
Do you know what is the correct syntax for the path when running on a MS Win OS?
But even if there is a way, when it comes to the path syntax, I will get stuck on the lack of this “wget” command, when running my OpenHAB on a Win OS machine? Or did I misunderstand?
I have tried to get the wget to work, but unfortunately without success. I would say that I basically have done, as described in the corresponding documentation, as far as I understand.
The installation is carried out seamlessly, and I notice that something “wget related” is installed in c:\Program Files (x86)\GnuWin32.
However, running the wget command in OpenHAB result in the same warn as before.
[WARN ] [lipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “wget” (in directory “.”): CreateProcess error=2, The system cannot find the file specified)
It might be misinterpreting the warn, but “Cannot run program “wget” (in directory “.”)” makes me wonder, if some part / files of the wget installation must reside in the folder from where OpenHAB is running (c:\openHAB2), or if manually registration of the command must be performed?
A short update on this one. Finally, I managed it to work.
I believe the problem has something to do with wget not being associated as a native command during installation, and I don’t know if it is possible to do so. As a workaround, changing the rule to use absolute paths worked for me.
var cmd = "c:\\Program Files (x86)\\GnuWin32\\bin\\wget.exe --output-document c:\\openHAB2\\temp\\bagdor.png http://192.168.16.8/cgi-bin/encoder?USER=user&PWD=pwd&SNAPSHOT=N640x480,100"
rule "E-mail door cam snapshot back door"
when
Item T_ST1_RingklokkeBagdor changed from OFF to ON
then
// here is the execute command. You need to put a delay of 5 seconds otherwise it does not work. Not sure why is that
executeCommandLine(cmd,5000)
// send the email
sendMail("my@email.dk; my_wife@email.dk", "Ringklokke bagdør aktiveret!", "", "file:c:\\openHAB2\\temp\\bagdor.png")
end
Hi, today I took a new approach to get this command running.
Also @watou suggested this in another post.
But I failed.
When I looked into it I realized, that strange things happen here.
Just for testing I thought I do it step by step. So I typed in the following commandline at the puTTY-console and pressed ENTER: wget --output-document /home/openhabian/cam/test.jpg http://192.168.xxx.xxx:xx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxxxxxxxxxxxx&pwd=xxxxxxxxxxxxxxxx
What I don’t understand is: The console prompt appears and a new commandline is created automatically and is executed automatically! And the valid url I had typed in has changed to a invalid url! As you can see here:
The created file /home/openhabian/cam/test.jpg is no picture, it’s a xml file with error code -2 = Username or password error. What could be expected, because of the invalid url: (Foscam FI9900P)
<CGI_Result>
<result>-2</result>
</CGI_Result>
Can anyone explain this strange behavour?
Edit: Can anyone point me to a solution, how to get the cam-snapshot saved into test.jpg?
Regards.
Thanks! Sorry, I don’t know the verbose option. Do you mean I should switch to debug mode?
I did this and couldn’t see any related info. Maybe I do something wrong?
Edit: I found this https://wiki.ubuntuusers.de/wget/
So I changed my command to wget --verbose --output-document ... but didn’t get more information.
To see, if something is wrong with my wget I searched the web and found this command apt-cache show wget which shows the following: (Should I be worried about: Conflicts: wget-ssl?)
Package: wget
Version: 1.16-1+deb8u2
Architecture: armhf
Maintainer: Noël Köthe <noel@debian.org>
Installed-Size: 1683
Depends: libc6 (>= 2.17), libgnutls-deb0-28 (>= 3.3.0), libidn11 (>= 1.13), libnettle4, libpsl0 (>= 0.4.0), libuuid1 (>= 2.16), zlib1g (>= 1:1.1.4)
Recommends: ca-certificates
Conflicts: wget-ssl
Multi-Arch: foreign
Homepage: http://www.gnu.org/software/wget/
Priority: important
Section: web
Filename: pool/main/w/wget/wget_1.16-1+deb8u2_armhf.deb
Size: 474544
SHA256: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SHA1: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MD5sum: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Description: retrieves files from the web
Wget is a network utility to retrieve files from the web
using HTTP(S) and FTP, the two most widely used internet
protocols. It works non-interactively, so it will work in
the background, after having logged off. The program supports
recursive retrieval of web-authoring pages as well as FTP
sites -- you can use Wget to make mirrors of archives and
home pages or to travel the web like a WWW robot.
.
Wget works particularly well with slow or unstable connections
by continuing to retrieve a document until the document is fully
downloaded. Re-getting files from where it left off works on
servers (both HTTP and FTP) that support it. Both HTTP and FTP
retrievals can be time stamped, so Wget can see if the remote
file has changed since the last retrieval and automatically
retrieve the new version if it has.
.
Wget supports proxy servers; this can lighten the network load,
speed up retrieval, and provide access behind firewalls.
Description-md5: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Package: wget
Status: install ok installed
Priority: important
Section: web
Installed-Size: 1683
Maintainer: Noël Köthe <noel@debian.org>
Architecture: armhf
Multi-Arch: foreign
Version: 1.16-1+deb8u1
Depends: libc6 (>= 2.17), libgnutls-deb0-28 (>= 3.3.0), libidn11 (>= 1.13), libnettle4, libpsl0 (>= 0.4.0), libuuid1 (>= 2.16), zlib1g (>= 1:1.1.4)
Recommends: ca-certificates
Conflicts: wget-ssl
Conffiles:
/etc/wgetrc xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Description: retrieves files from the web
Wget is a network utility to retrieve files from the web
using HTTP(S) and FTP, the two most widely used internet
protocols. It works non-interactively, so it will work in
the background, after having logged off. The program supports
recursive retrieval of web-authoring pages as well as FTP
sites -- you can use Wget to make mirrors of archives and
home pages or to travel the web like a WWW robot.
.
Wget works particularly well with slow or unstable connections
by continuing to retrieve a document until the document is fully
downloaded. Re-getting files from where it left off works on
servers (both HTTP and FTP) that support it. Both HTTP and FTP
retrievals can be time stamped, so Wget can see if the remote
file has changed since the last retrieval and automatically
retrieve the new version if it has.
.
Wget supports proxy servers; this can lighten the network load,
speed up retrieval, and provide access behind firewalls.
Description-md5: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Homepage: http://www.gnu.org/software/wget/
Like described here I did sudo apt-get install wget but that didn’ change anything. Still the same informations with option verbose.
I will get a different cam and see if the problem still exist. Thanks.