Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cgitb ; cgitb.enable()
- import spidev
- import time
- import sys
- from pubnub.callbacks import SubscribeCallback
- import RPi.GPIO as GPIO
- import smtplib
- from email.mime.text import MIMEText
- from twilio.rest import Client
- from pubnub.pnconfiguration import PNConfiguration
- from pubnub.pubnub import PubNub
- mailja = 0
- smsja = 0
- # HIERONDER NOG INVULLEN
- account_sid = ""
- auth_token = ""
- client = Client(account_sid, auth_token)
- GPIO.setmode (GPIO.BCM)
- PIN1 = 17
- PIN2 = 18
- GPIO.setup(PIN1,GPIO.OUT)
- GPIO.setup(PIN2,GPIO.OUT)
- pnconfig = PNConfiguration()
- pnconfig.subscribe_key = 'sub-c-0-96a8-ea37cc28f519'
- pnconfig.publish_key = 'pub-c-57b8bec9'
- pubnub = PubNub(pnconfig)
- channel = 'examen'
- pnconfig2 = PNConfiguration()
- pnconfig2.subscribe_key = 'sub-c-dd0a240a50a3'
- pnconfig2.publish_key = 'pub-c03645cdf2c49'
- pubnub2 = PubNub(pnconfig2)
- channel2 = 'potmeter'
- spi = spidev.SpiDev()
- spi.open(0,0)
- def readadc(adcnum):
- if ((adcnum > 7) or (adcnum < 0)):
- return -1
- r = spi.xfer2([1,(8+adcnum)<<4,0])
- adcout = ((r[1]&3) << 8) + r[2]
- return adcout
- class MySubscribeCallback_ITF(SubscribeCallback):
- def message (self, pubnub, message):
- if message.message == '0':
- print('Alarmknop ingedrukt!!')
- def site(procent0,procent1):
- site1 = str(procent0) + "%"
- site2 = str(procent1) + "%"
- try:
- pubnub2.publish().channel('potmeter').message(site1 + " " + site2).sync()
- except PubNubException as e:
- print(e)
- # MAILGEGEVENS INVULLEN
- def mail(procent0):
- message = "procent0" + "%!"
- msg = MIMEText(message)
- msg['Subject'] = ''
- msg['From'] = ''
- msg['To'] = ''
- username = ''
- password = ''
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(msg['From'], msg['To'], msg.as_string())
- server.quit()
- # SMS GEGEVENS INVULLEN
- def sms(procent1):
- message = client.messages.create(
- to="",
- from_="",
- body="procent1" + "%!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement