Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import cgitb ; cgitb.enable()
  2. import spidev
  3. import time
  4. import sys
  5. from pubnub.callbacks import SubscribeCallback
  6. import RPi.GPIO as GPIO
  7. import smtplib
  8. from email.mime.text import MIMEText
  9. from twilio.rest import Client
  10. from pubnub.pnconfiguration import PNConfiguration
  11. from pubnub.pubnub import PubNub
  12. mailja = 0
  13. smsja = 0
  14. # HIERONDER NOG INVULLEN
  15. account_sid = ""
  16. auth_token = ""
  17. client = Client(account_sid, auth_token)
  18. GPIO.setmode (GPIO.BCM)
  19. PIN1 = 17
  20. PIN2 = 18
  21. GPIO.setup(PIN1,GPIO.OUT)
  22. GPIO.setup(PIN2,GPIO.OUT)
  23. pnconfig = PNConfiguration()
  24. pnconfig.subscribe_key = 'sub-c-0-96a8-ea37cc28f519'
  25. pnconfig.publish_key = 'pub-c-57b8bec9'
  26. pubnub = PubNub(pnconfig)
  27. channel = 'examen'
  28. pnconfig2 = PNConfiguration()
  29. pnconfig2.subscribe_key = 'sub-c-dd0a240a50a3'
  30. pnconfig2.publish_key = 'pub-c03645cdf2c49'
  31. pubnub2 = PubNub(pnconfig2)
  32. channel2 = 'potmeter'
  33. spi = spidev.SpiDev()
  34. spi.open(0,0)
  35.  
  36. def readadc(adcnum):
  37. if ((adcnum > 7) or (adcnum < 0)):
  38. return -1
  39. r = spi.xfer2([1,(8+adcnum)<<4,0])
  40. adcout = ((r[1]&3) << 8) + r[2]
  41. return adcout
  42.  
  43. class MySubscribeCallback_ITF(SubscribeCallback):
  44. def message (self, pubnub, message):
  45. if message.message == '0':
  46. print('Alarmknop ingedrukt!!')
  47.  
  48.  
  49. def site(procent0,procent1):
  50. site1 = str(procent0) + "%"
  51. site2 = str(procent1) + "%"
  52. try:
  53. pubnub2.publish().channel('potmeter').message(site1 + " " + site2).sync()
  54. except PubNubException as e:
  55. print(e)
  56.  
  57. # MAILGEGEVENS INVULLEN
  58. def mail(procent0):
  59. message = "procent0" + "%!"
  60. msg = MIMEText(message)
  61. msg['Subject'] = ''
  62. msg['From'] = ''
  63. msg['To'] = ''
  64. username = ''
  65. password = ''
  66. server = smtplib.SMTP('smtp.gmail.com:587')
  67. server.starttls()
  68. server.login(username,password)
  69. server.sendmail(msg['From'], msg['To'], msg.as_string())
  70. server.quit()
  71.  
  72.  
  73. # SMS GEGEVENS INVULLEN
  74. def sms(procent1):
  75. message = client.messages.create(
  76. to="",
  77. from_="",
  78. body="procent1" + "%!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement