Помогите разобраться, изучаю питон и попутно пишу телеграмм бот управляющий gpio малинки pi.
суть вопроса: как правильно и без ошибок вызвать эту строку?
def vlaga1(chat_id):
bot.sendMessage(chat_id, str("тест"))
import datetime # Importing the datetime library
import telepot # Importing the telepot library
from telepot.loop import MessageLoop # Library function to communicate with telegram bot
import RPi.GPIO as GPIO # Importing the GPIO library to use the GPIO pins of Raspberry pi
from time import sleep # Importing the time library to provide the delays in program
red_led_pin = 11 # Initializing GPIO 21 for red led
vlaga_pin = 7 # Initializing GPIO 20 for green led
GPIO.setmode(GPIO.BCM) # Use Board pin numbering
GPIO.setup(red_led_pin, GPIO.OUT) # Declaring the GPIO 21 as output pin
GPIO.setup(vlaga_pin, GPIO.IN) # Declaring the GPIO 20 as output pin
now = datetime.datetime.now() # Getting date and time
def handle(msg, chat_id):
chat_id = msg['chat']['id'] # Receiving the message from telegram
command = msg['text'] # Getting text from the message
return handle
print ('Received:')
print(command)
# Comparing the incoming message to send a reply according to it
if command == '/hi':
bot.sendMessage (chat_id, str("привет"))
elif command == '/time':
bot.sendMessage(chat_id, str("Time: ") + str(now.hour) + str(":") + str(now.minute) + str(":") + str(now.second))
elif command == '/date':
bot.sendMessage(chat_id, str("Date: ") + str(now.day) + str("/") + str(now.month) + str("/") + str(now.year))
elif command == '/red_1':
bot.sendMessage(chat_id, str("Red led is ON"))
GPIO.output(red_led_pin, True)
elif command == '/red_0':
bot.sendMessage(chat_id, str("Red led is OFF"))
GPIO.output(red_led_pin, False)
elif command == '/vl':
vlaga=int(GPIO.input(vlaga_pin))
if vlaga == 1:
bot.sendMessage(chat_id, str("Сухая почва"))
else:
bot.sendMessage(chat_id, str("Влажная почва"))
def vlaga1(chat_id):
bot.sendMessage(chat_id, str("тест"))
GPIO.add_event_detect(vlaga_pin, GPIO.FALLING, callback=vlaga1, bouncetime=10)
# Insert your telegram token below
bot = telepot.Bot('тут код моего бота')
print (bot.getMe())
# Start listening to the telegram bot and whenever a message is received, the handle function will be called.
MessageLoop(bot, handle).run_as_thread()
print ('Listening....')
while 1:
sleep(10)
а еще посоветуйте хороший литературы по питону? русскоязычной желательно