Khadas Blog | How To Send LAN IP Address To Telegram Chat
Updated: Mar 9, 2020
Get your Khadas VIM SBC to notify you when it boots up!
1. Login To Your Khadas VIM Via SSH
$ ssh email@example.com $ firstname.lastname@example.org's password: khadas
2. Create A Bash Script
$ cd /home/khadas $ nano notify.sh
3. Paste The Following Telegram Web-Request String
...paste this into the nano editor...but edit it first! !/bin/bash curl "https://api.telegram.org/bot<bot-api-key>/sendMessage?chat_id=<chat-id>&text=<name-of-your-vim>"$(hostname -I | sed 's| |%20|g')""
Substitute these variables with your own, I will explain how to get them later:
...save and exit nano...press the following keys... [ Control-X ] [ y ] [ Enter ]
Do note that you can modify $(hostname -I | sed ‘s| |%20|g’) to include additional information that you want to pull from the Khadas VIM. Just remember to substitute all spaces with %20 using sed!
4. Edit The rc.local File To Run The Bash Script On Boot
$ sudo nano /etc/rc.local
...above the line that says "exit 0"...add the following line... /home/khadas/notify.sh ...save and exit rc.local...press the following keys... [ Control-X ] [ y ] [ Enter ]
5. Reboot Your Khadas VIM To Test
Alternatively, just run the bash script within the ssh session, to see if it works, before you reboot to do a final test.
$ bash /home/khadas/notify.sh
You should see this as the result:
6. How To Get A <bot-api-key>
...search for... botfather
...talk to botfather using these commands... /start /newbot <input name of your bot> <input user name of your bot>
The <bot-api-key> will be highlighted in red colour! Copy it!
7. How To Get A <chat-id>
Create a new group. Press the compose button, then press New Group.
Add at least one user into this group. Don’t add TeleCast v1.0, add another user or even the bot you created earlier in step 6.
Just press “next” to continue on.
Give your group a name…in my case, I called it the “VIM_Demo_Group”.
Press the three dots … and then press Info.
Inside the information pane, press + Add Member.
Add the bot you had created previously in step 6. Telegram search is a bit flaky, be sure to type your bot’s full name, exactly.
Now visit the TeleCast v1.0 bot for real, and type /start, to begin interacting with it. Here’s a link if you can’t find it: https://t.me/telecast_v1_0_bot
Now you may add TeleCast v1.0 into your newly created Telegram Group.
After TeleCast v1.0 has been added to your group, type /telecast.
Return to the TeleCast v1.0 bot (https://t.me/telecast_v1_0_bot), and type /chn, it will then display your <chat-id> of the group you just created! Copy it! It always starts with a -minus sign. Remember to copy the minus sign as well!
8. Naming Your Khadas VIM With <name-of-your-vim>
You can name your Khadas VIM anything you like, just be sure that it follows some rules…
"My Name" should be spelt as "My%20Name" without the double-quotes. Any special characters should be converted to web-safe characters, please refer to: https://www.w3schools.com/tags/ref_urlencode.asp
For The Lazy:
If you don't want to go about getting your own <bot-api-key>, and <chat-id>, you're welcome to use mine first. Simply copy this exact string into your notify.sh bash script.
#!/bin/bash curl "https://api.telegram.org/bot606694295:AAEnUENJJwhDBBQzehVtupaxFdQ-2T6p0LA/sendMessage?chat_id=-285153354&text=VIM%20Booted%20"$(hostname -I | sed 's| |%20|g')""
<bot-api-key> 606694295:AAEnUENJJwhDBBQzehVtupaxFdQ-2T6p0LA <chat-id> -285153354 <name-of-your-vim> VIM%20Booted%20
You can visit the Telegram Group here, its not a secret, you're welcome to add your own bots, just don't spam please: https://t.me/joinchat/GXXcFRD_GEqU1eNPmkkCCQ
Khadas Products Used In This Post:
VIM2 Pro — $119.90