Page 1 of 1

How to: send image from camera with Telegram.

PostPosted: Thu Jun 16, 2016 2:08 pm
by johnB
If you want to send a picture from your camera With Telegram (after motion detected), this is how you can do it.

You make a chain with your camera, a motion detector and after the motion detector a module “save to file” and also “application runner”.

You can setup your motion detector yourself (I put post record on 0 seconds).

In the module save to file you have to define the path, for example: “/home/pi/picture.jpg”, the Type of stored files is Images (JPEG), the image saving intervals I have put on 30 seconds (you can play with this if you want more pictures) and precord 0 seconds.

In the module application runner you have to define the program:
curl -s -X POST "https://api.telegram.org/bot<token>/sendPhoto" -F chat_id=<id-receiver> -F photo="@/home/pi/picture.jpg"
Parameters is empty and interval of running is 30 seconds (you can play with this if you want more pictures).

Some explanation about Telegram, I find this a very useful guide: https://www.domoticz.com/wiki/Telegram_Bot.
Take a little time and you will see it is easy and very useful (also for other applications)! You will have to fill in your own token and id of the receiver of the Telegram-message send by your Xeoma-server.
I use curl –s –X POST to “run” the URL on linux.

You can test the full URL for sending the picture in a browser (for example Chrome or another one on that server) to see if it is functioning!

Some remarks:
- The picture send is a picture taken from the preview and not of the “high quality” stream of your camera. I have asked Xeoma about it. If I have news, I will report it.
- I was not successful with the module “request sender”, somehow the URL is not transmitted…..
- I am using Xeoma (latest standard version), Raspberry PI3-server and Mac/Windows-client.

Re: How to: send image from camera with Telegram.

PostPosted: Wed Jun 29, 2016 4:50 am
by korniza
:D Nice! This software is fantastic as you can direct images/events to almost any software/web app!
Thank you for sharing!

Re: How to: send image from camera with Telegram.

PostPosted: Fri Jul 08, 2016 3:21 pm
by Admin_K
Hello!

Thanks for sharing your ideas. Great that Xeoma is so flexible and can be used for any needs.

We're always happy to improve Xeoma, so please feel free to contact us and share your ideas with us: http://felenasoft.com/xeoma/en/contacts/

Re: How to: send image from camera with Telegram.

PostPosted: Mon Jul 17, 2017 1:08 am
by infernix
This is quite nice, but indeed the archive feed would be much better. I have set my preview to 720p for now.

Also, there is sendVideo but it only takes mp4 which is not a format that Xeoma currently supports; which is a shame because with H264 cameras, it is just a matter of writing the source feed in the right container format - no transcoding needed.

Re: How to: send image from camera with Telegram.

PostPosted: Tue Jul 25, 2017 1:07 pm
by Admin_P
Hello! "Save to File" works only with the preview stream, since the second stream is meant only for the Archive. Choosing a higher resolution stream for the preview is a viable option.
MP4 is currently not supported, unfortunately. If you'd like to be notified when the new functionality becomes available, please feel free to subscribe to our newsletter.

Re: How to: send image from camera with Telegram.

PostPosted: Tue Jul 25, 2017 1:47 pm
by infernix
Are you not constantly reading the second stream on the second thread? So it should be technically possible correct?

If so, please make it an option for the save to file module.

Re: How to: send image from camera with Telegram.

PostPosted: Sun Mar 15, 2020 10:25 am
by hmd
Hi!
Thanks for your tutorial.
I have a problem to send the picture with xeoma.
I have tried to send picture from CLI without problem, but when i try in xeoma with the application runner it doesn't work.

I use last release of Xeoma for ARMv8
Here the run code
Code: Select All Code
/usr/bin/curl -s -X POST 'https://api.telegram.org/botXXXXXXXXXXXXX/sendPhoto' -F chat_id=XXXXXX -F photo='@/mnt/download/xeoma/immagini/picture.jpg'



Please could you help me?
Thanks a lot

Re: How to: send image from camera with Telegram.

PostPosted: Mon Mar 16, 2020 8:17 am
by infernix
@hmd just put the curl stuff in a script.

In Xeoma I just call
Code: Select All Code
/usr/local/bin/xeoma-to-telegram


And the script does the real work. I found that the Telegram API is not always reliable, so I am retrying it. For example:

Code: Select All Code
#!/bin/bash
# Change these variables
CHAT_ID=-12345678
IMAGEPATH=/path/to/jpg/from/save-to-file/module.jpg
CAPTION="Motion detected"
TELEGRAMBOT="botXXXXXXX:YYYYYYYYYYYYYYYYY"

#
ok="false"
try=0

# retry until telegram accepts the msg
try=0
while [[ "$ok" == "false" ]]; do
        let try=$try + 1
        # Abort if not successful after 3 tries (seconds)
        if [[ $try -gt 3 ]]; then
                break
        fi
        # post to telegram
        RESULT=$(curl -s -X POST "https://api.telegram.org/${TELEGRAMBOT}/sendPhoto" -F "chat_id=${CHAT_ID}" -F photo="@${IMAGEPATH}" -F caption="${CAPTION}")
        # parse result
        ok="$(echo $RESULT | jq -r .ok)"
        # delay the next attempt if we did not succeed
        if [[ "$ok" == "false" ]]; then
                sleep 1s
        fi
done

if [[ "$ok" == "true" ]]; then
        echo "Image sent to telegram, try $try result $RESULT"
else
        echo "Failed to send to telegram, try $try result $RESULT"
fi


Note, you need jq installed or it won't be able to parse the result.

Re: How to: send image from camera with Telegram.

PostPosted: Thu Mar 19, 2020 12:18 pm
by hmd
Thank you!

I have put that file in /usr/local/bin, but in Xeoma, when i try that script, application runner tell me: "Cannot run application. Check command line for errors".
I have set with chown, root for user and group, and 755 with chmod
Another question, where I can find errors? in /usr/local/bin/xeoma/Log i'm not find so much

In the end, from CLI, when i try to execute the same bash file, everthings works!


Thanks

Re: How to: send image from camera with Telegram.

PostPosted: Fri Apr 03, 2020 12:49 pm
by test2014
Thank you. That helped me too.