Failed with sending camera data to email

Hi,

Im using a raspberry pi with the Openhab image to send emails with some of my cameras.
If i use the commandline to fetch the image i can see with one camera i first get a 401 error and then it download the image, with the other it just takes a bit longer to download.
But they both fetch the image.
when executing the commands seperatly i dont have a issue.
I can access the folder with openhabian in the terminal without issue, also.

Ive also tried to use /home/tmp after creating it but that also doenst work.

Working commandline:
wget http://user:password123@192.168.0.10/snap.jpg -O /home/openhabian/tmp/FrontDoorCam.jpg
–2022-08-07 16:01:20-- http://user:*password*@192.168.0.10/snap.jpg
Connecting to 192.168.0.10:80… connected.
HTTP request sent, awaiting response… 401 Unauthorized
Authentication selected: Digest realm=“Please log in with a valid username.”,nonce=“48e71c1546a52fa67af318f57ec3422e”,opaque=“”,stale=FALSE,algorithm=MD5,qop=“auth”
Connecting to 192.168.0.10:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 235500 (230K) [image/jpeg]
Saving to: ‘/home/openhabian/tmp/FrontDoorCam.jpg’

rule "Doorbell Pressed Closed"
when
	Item GroundFloorHallwayDoorbell_DoorBellSensor changed from CLOSED to OPEN
then { 
	logInfo	("Door bell pressed closed", "doorbell pressed")
	executeCommandLine("wget http://192.168.0.15/stream.jpg -O /home/openhabian/tmp/FrontDoorCam2.jpg")


Thread::sleep(10000)  // 10 second wait

sendMail(getActions("mail","mail:smtp:ff634c00d8"), "myfirstemail@gmail.com", "the doorbell was pressed","mail body" , "file:///home/openhabian/tmp/FrontDoorCam2.jpg" )

}
end

Code 2:

rule "Doorbell Pressed Closed"
when
	Item GroundFloorHallwayDoorbell_DoorBellSensor changed from CLOSED to OPEN
then { 
	logInfo	("Door bell pressed closed", "doorbell pressed")
 executeCommandLine("wget http://user:mypassword@192.168.0.10/snap.jpg -O /home/openhabian/tmp/FrontDoorCam.jpg")

Thread::sleep(10000)  // 10 second wait

sendMail(getActions("mail","mail:smtp:ff634c00d8"), "myfirstemail@gmail.com", "the doorbell was pressed","mail body" , "file:///home/openhabian/tmp/FrontDoorCam.jpg" )

}
end
  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:3.2.0
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:
`2022-08-07 17:09:06.325 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Error occurred when executing commandLine '[wget http://192.168.0.15/stream.jpg -O /home/openhabian/tmp/FrontDoorCam2.jpg]'
java.io.IOException: Cannot run program "wget http://192.168.0.15/stream.jpg -O /home/openhabian/tmp/FrontDoorCam2.jpg": error=2, No such file or directory`
executeCommandLine

expect all arguments to be separaterd by a comma. In the way you use it it is expected to be one argument. And the Renault then is that the command is not found.

This is not what you ment i suppose ?
I dont get an error any more but nothing is written to the folder

executeCommandLine("wget" , "http://192.168.0.15/stream.jpg", "-O /home/openhabian/tmp/FrontDoorCam2.jpg")

This is what I meant.
But you also need to separate “-O” and the path by using a comma.

From the docs’ examples:

// Space separated constants must be given as separate parameters as well
// e.g. path/to/your/script.sh xyz fred.file
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/your/script.sh", "xyz", "fred.file");

So if you add the Duration.ofSeconds parameter it will wait for an answer from the cam and if you add the ScriptResponse variable you can check for a returned message and print it to the logfile.

In case the file still will not be written check for the permissions of the folder. Keep in mind the command line ( depending on how you checked it ) works with a different user. The OH service runs with user openhab which needs to have user resp. group write access to the directory.

This does indeed work :slight_smile:

rule "Doorbell Pressed Closed"


when
	Item GroundFloorHallwayDoorbell_DoorBellSensor changed from CLOSED to OPEN 
or
	Item GroundFloorHallwayDoorbell_DoorBellSensor changed from OPEN to CLOSED
then { 
	logInfo	("Door bell pressed closed", "doorbell pressed")



	
	executeCommandLine("wget", "http://192.168.0.15/snapshot.jpg" , "-O" , "/home/openhabian/tmp/camfrontdoor.jpg"); 


Thread::sleep(3000)  // 3 second wait

sendMail(getActions("mail","mail:smtp:guidhere"), "myemail@gmail.com", "the doorbell was pressed","mail body" , "file:///home/openhabian/tmp/camfrontdoor.jpg")


}
	
end


1 Like

The

Thread::sleep(3000)  // 3 second wait

is not required if you use executeCommandLine with Duration.ofSeconds(3)

I did not look into the implementation of the wait statement in executeCommandLine. It could be that if the result is returned earlier that the rule continues faster than waiting for a fixed time.