Script fail.

Moderator: leecollings

Post Reply
Tjeerd13
Posts: 34
Joined: Thursday 07 May 2015 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Assen
Contact:

Script fail.

Post by Tjeerd13 »

Hello 1 have 2 scripts.

telegram.sh to post an PNG image from axis camera to telegram.

Code: Select all

convert http://192.168.10.106/axis-cgi/jpg/image.cgi image.jpg
curl -s -X POST "https://api.telegram.org/bot<MyCode>/sendPhoto" -F chat_id=<Mycahtid> -F photo="@/home/pi/domoticz/scripts/image.jpg"
and
imagetv.sh to post an image from axis camera with some tekst to my philips tv

Code: Select all

convert http://192.168.10.106/axis-cgi/jpg/image.cgi imageplaatje.png
/opt/JSTx/JSTx -F /opt/JSTx/font/decker.ttf -s 100 -x 60 -y 40 -i image:imageplaatje.png -x 600 -y 200 -t "$*" t -T 5 -b "100,100,100,128" -f "255,127,0,255" --dfb:quiet --remote=192.168.10.200./
The first one is not working when i bash the script i get this code With an error in the text @ g/image.cgi $'image.jpg\r' (When there is an image on the location its working with the old image) I trijd to use " and "in diverent ways.

Code: Select all

convert http://192.168.10.106/axis-cgi/jpg/image.cgi image.jpg
+ convert http://192.168.10.106/axis-cgi/jpg/image.cgi $'image.jpg\r'
curl -s -X POST "https://api.telegram.org/bot<MyCode>/sendPhoto" -F chat_id=<Mycahtid> -F photo="@/home/pi/domoticz/scripts/image.jpg"
+ curl -s -X POST https://api.telegram.org/bot<MyCode>/sendPhoto -F chat_id=<Mycahtid> -F photo=@/home/pi/domoticz/scripts/image.jpg
With an error in the text @ g/image.cgi $'image.jpg\r' (When there is an image on the location its working with the old image)

The second script is working ok.

Code: Select all

convert http://192.168.10.106/axis-cgi/jpg/image.cgi imageplaatje.png
+ convert http://192.168.10.106/axis-cgi/jpg/image.cgi imageplaatje.png
/opt/JSTx/JSTx -F /opt/JSTx/font/decker.ttf -s 100 -x 60 -y 40 -i image:imageplaatje.png -x 600 -y 200 -t "$*" t -T 5 -b "100,100,100,128" -f "255,127,0,255" --dfb:quiet --remote=192.168.10.200./
Why?
My Problem 2; I would like to use http://user:[email protected]/axis-cgi/jpg/image.cgi to fetch the image.(or something else to use user password) now i have to turn of security for the live vieuw in the axis camera.
My problem 3l I thik its also posible to use a url in the telegram curl. Instead of a lokal file, so i dont need to use the covert script, telegram can use JPG images.

Any sugestions?

Thanks!
Pi3, Pi4, Pi4 for Testing, Dashticz, RFXtrx433, Nest: "Thermostat V2, V3, Hello". Honywell Lyric T6R, RFXCom, KaKu, HUE, P1, Open Zwave USB,
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Script fail.

Post by jvdz »

How are you running the script as the first line will create image.jpg in it's current directory?
Did you check whether the image.jpg was actually created and it the proper directory?

This example has full path coded in both lines:

Code: Select all

convert http://192.168.10.106/axis-cgi/jpg/image.cgi /home/pi/domoticz/scripts/image.jpg
curl -s -X POST "https://api.telegram.org/bot<MyCode>/sendPhoto" -F chat_id=<Mycahtid> -F photo="@/home/pi/domoticz/scripts/image.jpg"
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Tjeerd13
Posts: 34
Joined: Thursday 07 May 2015 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Assen
Contact:

Re: Script fail.

Post by Tjeerd13 »

The image get created when I run only the convert. But when I ad the second line I get a corrupt jpg file with a small size. If I check with bash I see the $ and \r added to the image file. it's the same line I used with the second script

Verstuurd vanaf mijn HTC One_M8 met Tapatalk
Pi3, Pi4, Pi4 for Testing, Dashticz, RFXtrx433, Nest: "Thermostat V2, V3, Hello". Honywell Lyric T6R, RFXCom, KaKu, HUE, P1, Open Zwave USB,
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: Script fail.

Post by nayr »

make sure your using bash in your interpreter line (ie, #!/bin/bash) so its executing on the same shell as you are manually..

might add a sleep before you post, also check the file exists and is not empty, then cleanup your file when done.. kinda like this:

Code: Select all

#!/bin/bash
convert http://192.168.10.106/axis-cgi/jpg/image.cgi /home/pi/domoticz/scripts/image.jpg
sleep 1
if [ -s "/home/pi/domoticz/scripts/image.jpg" ];then
        curl -s -X POST "https://api.telegram.org/bot<MyCode>/sendPhoto" -F chat_id=<Mycahtid> -F photo="@/home/pi/domoticz/scripts/image.jpg"
        rm /home/pi/domoticz/scripts/image.jpg
fi
If you have a ramdisk/tmpfs, it would be better to have your image.jpg stored there instead of invoking a write to your sd/usb/hdd each time this script is triggered.. Personally I make /tmp a tmpfs and would save it there instead.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Tjeerd13
Posts: 34
Joined: Thursday 07 May 2015 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Assen
Contact:

Re: Script fail.

Post by Tjeerd13 »

:oops: :oops:

Thanks for the sugestions ! ! :D
After edditiing my file it was saved as microsoft file (WinSCP --> Notepad++) en i get the error:

convert http://192.168.10.106/axis-cgi/jpg/image.cgi image.jpg
+ convert http://192.168.10.106/axis-cgi/jpg/image.cgi $'image.jpg\r

after converting the file back to linux format it worked fine!
I also combined both scripts to one script and created a ramdisk.
When someone presses the doorbel i use as on action script://combi.sh deurbel En get an cameraimage on my TV with the text doorbel, and and cameraimage on my phone with telegram.

Next step for me is:
Check if TV is on/sourceforge running. If not only send a message to telegram.
Use my axis camera username and password. instead of accesing it without password. (somethiong like http://user:pass@ 192.168.10.106/axis-cgi/jpg/image.cgi )
Blink my ambilight of the tv in a colour. But for now its working :) !

Code: Select all

   #!/bin/bash
    convert http://192.168.10.106/axis-cgi/jpg/image.cgi /var/tmp/image.png
    if [ -s "/var/tmp/image.png" ];then
          			     curl -s -X POST "https://api.telegram.org/bot<KEY>/sendPhoto" -F chat_id=<ChatID) -F photo="@/var/tmp/image.png"
						/opt/JSTx/JSTx -F /opt/JSTx/font/decker.ttf -s 100 -t "                 $*" -b "100,100,100,128" -f "255,127,0,255" -i image:/var/tmp/image.png -x 50 -y 5  -T 5 --dfb:quiet --remote=192.168.10.200
				rm /var/tmp/image.png
			fi
Pi3, Pi4, Pi4 for Testing, Dashticz, RFXtrx433, Nest: "Thermostat V2, V3, Hello". Honywell Lyric T6R, RFXCom, KaKu, HUE, P1, Open Zwave USB,
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest