Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. import time, datetime
  2. import RPi.GPIO as GPIO
  3. import telepot
  4. from telepot.loop import MessageLoop
  5.  
  6. white = 26
  7. yellow = 19
  8. red = 13
  9. green = 6
  10.  
  11. now = datetime.datetime.now()
  12. GPIO.setmode(GPIO.BCM)
  13. GPIO.setwarnings(False)
  14.  
  15.  
  16. #LED White
  17. GPIO.setup(white, GPIO.OUT)
  18. GPIO.output(white, 0) #Off initially
  19. #LED Yellow
  20. GPIO.setup(yellow, GPIO.OUT)
  21. GPIO.output(yellow, 0) #Off initially
  22. #LED Red
  23. GPIO.setup(red, GPIO.OUT)
  24. GPIO.output(red, 0) #Off initially
  25. #LED green
  26. GPIO.setup(green, GPIO.OUT)
  27. GPIO.output(green, 0) #Off initially
  28.  
  29. def action(msg):
  30. chat_id = msg['chat']['id']
  31. command = msg['text']
  32.  
  33. print 'Received: %s' % command
  34.  
  35. if 'on' in command:
  36. message = "Turned on "
  37. if 'white' in command:
  38. message = message + "white "
  39. GPIO.output(white, 1)
  40. if 'yellow' in command:
  41. message = message + "yellow "
  42. GPIO.output(yellow, 1)
  43. if 'red' in command:
  44. message = message + "red "
  45. GPIO.output(red, 1)
  46. if 'green' in command:
  47. message = message + "green "
  48. GPIO.output(green, 1)
  49. if 'all' in command:
  50. message = message + "all "
  51. GPIO.output(white, 1)
  52. GPIO.output(yellow, 1)
  53. GPIO.output(red, 1)
  54. GPIO.output(green, 1)
  55. message = message + "light(s)"
  56. telegram_bot.sendMessage (chat_id, message)
  57.  
  58. if 'off' in command:
  59. message = "Turned off "
  60. if 'white' in command:
  61. message = message + "white "
  62. GPIO.output(white, 0)
  63. if 'yellow' in command:
  64. message = message + "yellow "
  65. GPIO.output(yellow, 0)
  66. if 'red' in command:
  67. message = message + "red "
  68. GPIO.output(red, 0)
  69. if 'green' in command:
  70. message = message + "green "
  71. GPIO.output(green, 0)
  72. if 'all' in command:
  73. message = message + "all "
  74. GPIO.output(white, 0)
  75. GPIO.output(yellow, 0)
  76. GPIO.output(red, 0)
  77. GPIO.output(green, 0)
  78. message = message + "light(s)"
  79. telegram_bot.sendMessage (chat_id, message)
  80.  
  81.  
  82.  
  83. telegram_bot = telepot.Bot('470583174:AAG7MPZc93qchp-tjqA_K2meRYcQiOR7X7Y')
  84. print (telegram_bot.getMe())
  85.  
  86. MessageLoop(telegram_bot, action).run_as_thread()
  87. print 'Up and Running....'
  88.  
  89. while 1:
  90. time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement