IOT 9 Telegram
IOT 9 Telegram
WEST PRACTICAL
JOURNAL
Class: TYIT Sem: V Roll No.: TYIT14 Date:
Course Name: Internet of Things
Page No.:
Practical Number:
AIM: Controlling Raspberry Pi with Telegram
Requirements:
Hardware Requirements:
1. Resistors
2. LEDs
3. Jumper Wires
4. Breadboard
Software Requirements:
1. Raspbian Strech OS
2. Telegram App
Steps:
For example,
connect:
______________
Teacher’s Signature
BHAVAN’S COLLEGE (AUTONOMOUS), ANDHERI-
WEST PRACTICAL
JOURNAL
Class: TYIT Sem: V Roll No.: TYIT14 Date:
Course Name: Internet of Things
Page No.:
Practical Number:
3. Write Code in Thonny IDLE.
Code:
import random
import datetime
import time
import telepot
import RPi.GPIO as GPIO
from telepot.loop import MessageLoop
red=31
now= datetime.datetime.now()
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(red,GPIO.OUT)
GPIO.output(red,0)
def action(msg):
chat_id=msg['chat']['id']
command=msg['text']
if 'Off' in command:
message= "Turn Off"
message=message+"red"
GPIO.output(red,0)
bot.sendMessage(chat_id,"Command received");
bot= telepot.Bot('7504375765:AAEdMmGiN7H1ns9v5V7I0ifrQeskmGEskBQ')
print(bot.getMe())
MessageLoop(bot, action).run_as_thread()
print('I am listening...')
while 1:
time.sleep(10)
______________
Teacher’s Signature
BHAVAN’S COLLEGE (AUTONOMOUS), ANDHERI-
WEST PRACTICAL
JOURNAL
Class: TYIT Sem: V Roll No.: TYIT14 Date:
Course Name: Internet of Things
Page No.:
Practical Number:
Steps to configure Telegram App:
Note: python telegram.py (here telegram.py is the name of our python code file)
[the last command will give you the bot details]
Step 9: Open Telegram and search for the username
Step 10: Click on the username and pass a command /start
Step 11: Write ‘On’ or ‘Off’
OUTPUT :
______________
Teacher’s Signature
BHAVAN’S COLLEGE (AUTONOMOUS), ANDHERI-
WEST PRACTICAL
JOURNAL
Class: TYIT Sem: V Roll No.: TYIT14 Date:
Course Name: Internet of Things
Page No.:
Practical Number:
OUTPUT:
Command Prompt :
Development Board:
______________
Teacher’s Signature