Форум сайта python.su
ZerG
Моя твоя не понимать! Давайте по сути! Вы код скопировали последний? Запустили? Нажали кнопку от пустилипри етом сообщения в консоли появились Button ON и Message was sent ?
pi@raspberrypi:~/linzer $на нажатие кнопки не реагирует.
python button.py
I am listening .
pi@raspberrypi:~/linzer $
python button.py
I am listening …
(-155539430, u'hello')
Got command: hello
(-155539430, u'hi')
Got command: hi
Button ON
Отредактировано mindwrk (Окт. 12, 2016 13:24:40)
Офлайн
все понятно!
А ну ка - немного модифицируйте код а именно
def handle(): chat_id = '1' command = '2' ...
Офлайн
ZerGна кнопку не реагирует
все понятно! А ну ка - немного модифицируйте код а именно
python button.py
I am listening …
('1', ‘2’)
Got command: 2
('1', ‘2’)
Got command: 2
Button ON
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/telepot/__init__.py”, line 738, in collector
callback(item)
File “button.py”, line 15, in handle
bot.sendMessage(chat_id, str('/ring)'))
File “/usr/local/lib/python2.7/dist-packages/telepot/__init__.py”, line 409, in sendMessage
return self._api_request('sendMessage', _rectify(p))
File “/usr/local/lib/python2.7/dist-packages/telepot/__init__.py”, line 398, in _api_request
return api.request((self._token, method, params, files), **kwargs)
File “/usr/local/lib/python2.7/dist-packages/telepot/api.py”, line 131, in request
return _parse(r)
File “/usr/local/lib/python2.7/dist-packages/telepot/api.py”, line 126, in _parse
raise exception.TelegramError(description, error_code, data)
TelegramError: (u'Bad Request: chat not found', 400, {u'error_code': 400, u'ok': False, u'description': u'Bad Request: chat not found'})
-155539430
I am listening …
('1', ‘2’)
Got command: 2
Button ON
Message was sent
Отредактировано mindwrk (Окт. 12, 2016 13:34:03)
Офлайн
Вопрос решил.
import time import datetime import telepot import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(16,GPIO.IN) def handle(msg): chat_id = msg['chat']['id'] command = msg['text'] print('Got command: %s' % command) if command == '/status': bot.sendMessage(chat_id, str('online')) elif command == '/open': bot.sendMessage(chat_id, str('moving')) elif command == '/time': bot.sendMessage(chat_id, str(datetime.datetime.now())) bot = telepot.Bot('*********') bot.message_loop(handle) print('I am listening ...') while 1: if GPIO.input(16)==0: pass else: bot.sendMessage(-155539430, str('/ring)')) time.sleep(3)
Офлайн