deepaks1010
Posts: 2
Joined: Thu May 09, 2019 8:33 am

Controlling Raspberry Pi using Telegram

Sat May 11, 2019 2:27 am

Hi,

I am facing an issue while Interfacing Telegram to Raspberry Pi 3B+. As i installed the telepot library but still it is showing an error as attached.
Anyone can please help me out in solving the issue.
Attachments
IMG_20190511_075121 (1).jpg
Python shell window
IMG_20190511_075121 (1).jpg (8.7 KiB) Viewed 165 times

Andyroo
Posts: 2964
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Controlling Raspberry Pi using Telegram

Sat May 11, 2019 12:36 pm

Could you please copy and paste both the code and error here?

If you use the code tags </> it will maintain the layout.

The picture is too small for my poor old eyes :oops:
Need Pi spray - these things are breeding in my house...

deepaks1010
Posts: 2
Joined: Thu May 09, 2019 8:33 am

Re: Controlling Raspberry Pi using Telegram

Sat May 25, 2019 2:37 am

Hi,

Sorry for the late reply, Please find the below code for the Telebot program


#Sample program for Light LED on/off using Telegram
import time, datetime
import RPi.GPIO as GPIO
import telepot
from telepot.loop import MessageLoop
now = datetime.datetime.now()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#LED Red
GPIO.setup(red, GPIO.OUT)
GPIO.output(red, 0) #Off initially
def action(msg):
chat_id = msg['chat']['id']
command = msg['text']
print ('Received: %s' % command)
if 'on' in command:
message = "on"
if 'red' in command:
message = message + "red "
GPIO.output(red, 1)
GPIO.output(red, 1)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)
if 'off' in command:
message = "off "
if 'red' in command:
message = message + "red "
GPIO.output(red, 0)
if 'all' in command:
message = message + "all "
GPIO.output(red, 0)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)
telegram_bot = telepot.Bot('808360144:AAG8ngYU6wwluGV6_8HFo2jEr6df7Z-5qCY')
print (telegram_bot.getMe())
MessageLoop(telegram_bot, action).run_as_thread()
print ('Up and Running....')
while 1:
time.sleep(10)

Return to “Beginners”