0% found this document useful (0 votes)
36 views4 pages

IOT 9 Telegram

Uploaded by

Avon Numa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

IOT 9 Telegram

Uploaded by

Avon Numa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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:
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:

1. Connect LEDs to GPIO pins.


Use jumper wires to connect the anode (long leg) of each LED to different GPIO pins on the Raspberry Pi.

 For example,
connect:

o LED 1 to GPIO Pin 17


o LED 2 to GPIO Pin 27
o LED 3 to GPIO Pin 22

2. Connect GND pin of raspberry Pi to GROUND of LED Module.


Connect a ground (GND) pin from the Raspberry Pi to the ground rail on the breadboard.

3. Configure Telegram App & connect it with Rasberry Pi.


Follow the below steps to configure Telegram with Rasberry Pi.

______________
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']

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


if 'On' in command:
message= "Turn On"
message=message+"red"
GPIO.output(red,1)
bot.sendMessage(chat_id,"Command received");

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:

Step 1: Download the TELEGRAM app


Step 2: Go to the search bar and type BotFather
Step 3: Open the BothFather’s chat & type /start
Step 4: Then click on /newbot
Step 5: Enter username: TYIT2024_bot (the username must end with bot)
Step 6: Now we will get an access token
Step 7: Now connect the LED pins & write the code
Step 8: After writing the code, go to the terminal and type the below commands:

sudo apt-get update


sudo apt-get install python3-pip
sudo pip install telepot
python3 telegram.py (to run the program.)

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy