How to: send image from camera with Telegram.

Xeoma Software

Moderators: Admin_N, Administrator, Admin_P, Admin_K

How to: send image from camera with Telegram.

Postby johnB » Thu Jun 16, 2016 2:08 pm

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.
johnB
 
Posts: 6
Joined: Thu Jun 09, 2016 7:10 am

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

Postby korniza » Wed Jun 29, 2016 4:50 am

:D Nice! This software is fantastic as you can direct images/events to almost any software/web app!
Thank you for sharing!
korniza
 
Posts: 35
Joined: Mon Jan 04, 2016 4:31 pm

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

Postby Admin_K » Fri Jul 08, 2016 3:21 pm

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/
Admin_K
 
Posts: 342
Joined: Tue Apr 07, 2015 2:20 pm

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

Postby infernix » Mon Jul 17, 2017 1:08 am

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.
infernix
 
Posts: 4
Joined: Sat Jul 15, 2017 9:31 pm

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

Postby Admin_P » Tue Jul 25, 2017 1:07 pm

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.
Admin_P
 
Posts: 245
Joined: Wed Aug 24, 2016 1:49 pm

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

Postby infernix » Tue Jul 25, 2017 1:47 pm

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.
infernix
 
Posts: 4
Joined: Sat Jul 15, 2017 9:31 pm

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

Postby hmd » Sun Mar 15, 2020 10:25 am

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
Attachments
Annotazione 2020-03-15 111528.jpg
Annotazione 2020-03-15 111528.jpg (125.25 KiB) Viewed 6157 times
hmd
 
Posts: 3
Joined: Sun Mar 15, 2020 10:07 am

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

Postby infernix » Mon Mar 16, 2020 8:17 am

@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.
infernix
 
Posts: 4
Joined: Sat Jul 15, 2017 9:31 pm

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

Postby hmd » Thu Mar 19, 2020 12:18 pm

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
hmd
 
Posts: 3
Joined: Sun Mar 15, 2020 10:07 am

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

Postby test2014 » Fri Apr 03, 2020 12:49 pm

Thank you. That helped me too.
test2014
 
Posts: 1
Joined: Fri Apr 03, 2020 12:46 pm


Return to Xeoma - General discussion

Who is online

Users browsing this forum: Bing [Bot] and 18 guests