0% found this document useful (0 votes)
58 views

Experiment 5 MSK Raspberry Telegram

This document provides instructions for setting up a Telegram bot on a Raspberry Pi to control an LED. It discusses installing Telegram and the Telepot library on the Pi, obtaining an access token from BotFather to identify the bot, and writing Python code to define bot commands to turn the LED on and off in response to messages sent to the bot. The code imports necessary libraries, sets up GPIO pin 3 to control the LED, defines on and off functions to control the pin, and includes a message handling function and loop to listen for commands and trigger the LED functions.

Uploaded by

Manoj Kavedia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Experiment 5 MSK Raspberry Telegram

This document provides instructions for setting up a Telegram bot on a Raspberry Pi to control an LED. It discusses installing Telegram and the Telepot library on the Pi, obtaining an access token from BotFather to identify the bot, and writing Python code to define bot commands to turn the LED on and off in response to messages sent to the bot. The code imports necessary libraries, sets up GPIO pin 3 to control the LED, defines on and off functions to control the pin, and includes a message handling function and loop to listen for commands and trigger the LED functions.

Uploaded by

Manoj Kavedia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Set Up Telegram Bot on

Raspberry Pi
Er. Manoj S. Kavedia
www.kaizenfuturetech.com
www.kavediasir.yolasite.com
9324258878 / 8329988738
Raspberry Pi Pin Out
About Telegram Bot
• On 24 June, 2015, Telegram published the Bot
API, enabling machines to talk Telegram.

• From that day on, not only can human use


Telegram, so can machines.
Install Telegram on Cell Phone
Search for BotFather
Click on BotFather
To Start BotFather
Type /start in Message
Text /newbot to BotFather
Give Name and User Name
Obtain Access Token copy it or Mail it
Setup on RPi
Setup on Raspberry Pi
Install “Python Package Index and “Telepot” using
$ sudo apt-get install python-pip
$ sudo pip install telepot
Python Code
import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

chat_id=""
#LED

def on(pin):
GPIO.output(pin,GPIO.HIGH)
#bot.sendMessage (chat_id, "device On")
return

def off(pin):
GPIO.output(pin,GPIO.LOW)
#bot.sendMessage (chat_id, "device Off")
return
Python Code
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

#Turn off the warning Messges


GPIO.setwarnings(False)

# set up GPIO output channel


GPIO.setup(3, GPIO.OUT)

def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']

print ('Got command: %s' % command)

if command == 'on':
bot.sendMessage(chat_id, on(3))

elif command =='off':


bot.sendMessage(chat_id, off(3))
Python Code
bot = telepot.Bot('Token U Recevied')
bot.message_loop(handle)
print ('I am listening...')

while 1:
time.sleep(10)
Run Child Bot and Give Command
Er. Manoj S. Kavedia

Contact on Watsapp to join Students Forum : 9324258878

You might also like