[Erhan] has been playing around with the Telegram instant messaging service. Initially, he worked out how to turn on and off LEDs from his cell phone: he sent commands from the phone through the Telegram bot API, to a computer that’s connected over serial to an MSP430 board that actually controlled the LEDs.
But that’s a little bit complicated. Better to cut out the middleman (err…microcontroller) and implement the Telegram reception and LED blinking on a Raspberry Pi. For a project that’s already using a Pi, using the instant messaging service’s resources is a very simple way to interface to a cellphone.
The code for both the standalone RPi project and the MSP430-based microcontroller application are available at [Erhan]’s GitHub. You’re going to be installing Node.js for their telegram-bot-api and jumping through the usual OAuth hoops to get your bot registered with Telegram. But once you’ve done that all on the Raspberry Pi (or target computer of your choice) it’s all just a few lines of fairly high-level code.
We’ve only seen one other Telegram application on Hackaday.io and we’re wondering why. It looks pretty slick, and with the bot’s ability to send a custom “keyboard” to the phone along with the message, it could make cell-phone-based control interfaces a cinch. Anyone else using Telegram for bots?
18 thoughts on “Telegram Your Devices”
I have this Telegram bot that messages me whenever my Raspberry Pi downloads a new podcast and puts it in my dropbox, here is how it looks:
They code for it is hosted on Github, feel free to contribute: https://github.com/Algram/PodcastAutomator
The answer to the question at the end of this post is it’s simply not needed and a lot of overhead if you are using other platforms. My Particle Photon can just initiate and receive web calls to any service without being physically connected to a computer. The Particle Electron can do it over cellular networks. It’s very quick and simple to create something like this. App and website integration can be done via a rest call.
I agree, without the need to consider Telegram’s worth, I’d also say that for many tasks nodemcu on an ESP gives you all of the functionality that many projects need. Storage is not an issue either, or even computational power because the scripts and resources the client needs can be on a web server and the heavy lifting can be done on the client too, with the nodemcu server just providing and receiving the encrypted parameters for those scripts running on the client.
However if you need to punch through firewalls, cross multiple network types and or need message caching, group communications etc. then Telegram may be appropriate.
Does any firmware on ESP support TLS (SSL)? Can any it serve pages with TLS? TLS server even with just fixed keys and support for just few clients (or only one client) would be great.
We use WolfSSL as a client on the ESP8266. I think it would be possible to use it as a server-side SSL also. You should try it.
Great. I used NodeMCU for my project but I can always rewrite my code in C++ for Arduino if that is supported. Anything else probably needs much more learning.
And by fixed keys I meant fixed certs as only the computer connecting needs to be trusted without any CA. At least is I understood right, I’m not a security expert and therefore I don’t want to make a new implementation.
That is why I suggested what I did, less overhead to secure the link if you invert the server-client relationship.
I’m not sure that would work for my use case, but I probably should think about it. Maybe some example project would help.
How much data traffic will you have? Assuming you are just transmitting tag and variable pairs. i.e. setX:YY GetX:
Do you need to push a notification at the client, or can the client regularly interrogate your project for a status change in a variable? That status does not need to be secured, it is just a flag that says a buffer is not empty, the transmission of the buffered variables would be secured.
How important is security? What level do you need? I ask because absolutely unbreakable security with very little computational overhead is possible even on an AVR level project, for the price of the storage (SD card) required for a 1 time pad and if you are prepared to compromise that to a certain degree you can reuse the pad data via a random walk and a shared seed value.
If none of the above makes a lot of sense to you then perhaps you should just go with using the higher level APIs that Telegram offers you.
I’ve set up a telegram bot on my server to monitor it, i can send command such “Free Ram” to receive a message containing ram informations, also disk space usage, process list, uptime, vnc server start & stop, reboot and other, bot replies only to me. On raspberry i’ve added commands like “picture” or “video” associated with the output of a usb web cam, supporting v4l, recycled from an old portable computer. Everythings is easy to get working thanks to python and subprocess & telepot modules.
Now that’s a great usage scenario! Do you have any code on github to have a look at what you tried?
I did something similar months ago, but I used plain C for the code and XMPP as the protocol instead of node.js and Telegram.
There is a plugin for Octoprint using a Telegram Bot for anyone that is interested.
A couple of months ago I managed to create a bot which talks with an Arduino with PIR motion sensor and notifies when something moves in my dorm room. Telegram was pretty cool for this job also fun to play with!
here’s my project: https://github.com/syxanash/joshua_bot/tree/spioncino
I have a Bot speaking form an ESP8266 so the Wife knows whether power is on at home and she can therefore work from home ( we have a lot of power outtages and she does a lot of remote standby )
build it from here : https://github.com/Lstt2005/ESP8266_I.O.Broker/tree/master/Arduino/Telegram/TelegramBot-master
For these purposes you should really look into the ‘keyboards’ feature of a bot. It allows your bot to send custom keyboards (for example with a whole menu structure) to your smart phone. No more typing, just tapping the right buttons.
I quite liked the API when I was playing with it. I’d just like that the Telegram server could prevent access for random people to my bot.
… Totally read over the fact he’s already using the keyboards. But still: totally awesome. No need to make a dedicated app for your application. Just use the Telegram GUI.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)