In this post I'm gonna show you that how I control LED's with Telegram messenger.
First I did some basic applications then I wanted to do serial port application. Of course I did it and it was really cool! After that I wanted to make it more cool and I decided to control devices over the serial port using mobile phones.
In this post I’m showing how to control a LED, but if you can control LED you can also control the other electrical devices. This is a sample application to show how it is possible.
Let’s talk more in details about it!
Step 1: Telegram Bot API and Bot Creation
As you know Telegram is a famous chat application that has a lot of users. Also they provide us some APIs to develop Telegram based applications.
The Telegram Bot API is one of them. Using this API you can create your own bot that can talk to the other people on telegram. With this bot you can implement so many interesting applications. Also I used this bot to do my control application. You can find more details here about telegram bot API
To create a new Bot you should talk with the BotFather. Don't worry it's so easy.
Just write him "/newbot" then after a while you will get your own bot and token number. And then you will be ready to use your bot in your applications. For more details about how to create a bot take a look here.
Step 2: Running the Application and Code
When the application starts, it’s simply waiting for messages coming from the Telegram server. When a user sends a message to our bot an event occurs in application. Then according to the text of the message we can understand what the user wants to do. If the command is correctly recognized, the application sends data over the serialport to MSP430 launchpad according to the specified command.
In there example we implemented 5 commands: LedGreenOn, LedGreenOff, LedRedOn, LedRedOff and Button. As you can see, four commands are for controlling the two LEDs (Green and Red) on the MSP430 Launchpad and then we have the Button command to read the status of the user push button on the launchpad. Also the commands are not case sensitive, you can write them as you wish, upper or lower case. And if you write an undefined command, the application will notify you and list all the available commands .
To run the application you should just specifiy which serial port do you use. The other serial port parameters are: 9600 baud, 8N1 as default.
Step 3: MSP430 Lauchpad Energia Application and Results
On the hardware side I used a simple MSP430 Launchpad and wrote code with Energia to make it simple. It is simple code, when MSP430 receives the data over the serial port it also makes some checks . According to the input data it controls LEDs and checks the button status. Then it sends the required responses to NodeJS appliaction over the serial port.
So, as result I think that the Telegram bot API is really useful. You can do amazing applications. And of course, all the source files about this application are available here as github project.
I hope that this post was useful for you.
See you next post "inşaallah". Have a nice day!