Page 1 of 1

Script fail.

Posted: Thursday 31 December 2015 14:54
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!

Re: Script fail.

Posted: Thursday 31 December 2015 18:09
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

Re: Script fail.

Posted: Thursday 31 December 2015 20:25
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

Re: Script fail.

Posted: Thursday 31 December 2015 21:39
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.

Re: Script fail.

Posted: Friday 01 January 2016 21:04
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