-
Notifications
You must be signed in to change notification settings - Fork 0
/
blynk_ifttt.py
61 lines (48 loc) · 1.59 KB
/
blynk_ifttt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
Guy Shiff - 308577469
Nadav Lotan - 312346406
Sensing - Blynk app & IFTTT
'''
import BlynkLib
import time
import Adafruit_DHT
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
import requests
import threading
temperatureSensor = Adafruit_DHT.DHT22
BLYNK_AUTH = 'e6eba6bed75e4b179b85830d8a6f2943'
temperatureSensorPin = 5
CLK = 18
MISO = 23
MOSI = 24
CS = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
def temperature():
while True:
humidityCurVal, temperatureCurVal = Adafruit_DHT.read_retry(temperatureSensor, temperatureSensorPin)
blynk.virtual_write(0, temperatureCurVal)
time.sleep(0.5)
def humidity():
while True:
humidityCurVal, temperatureCurVal = Adafruit_DHT.read_retry(temperatureSensor, temperatureSensorPin)
if int(humidityCurVal) > 82:
requests.post('https://maker.ifttt.com/trigger/humidOver_82/with/key/lfnRM_16wslaPk3UDONUe')
blynk.virtual_write(1, humidityCurVal)
time.sleep(0.5)
def potentiometer():
while True:
potenValue = mcp.read_adc(0)
if int(potenValue) == 1023:
requests.post('https://maker.ifttt.com/trigger/potnInMaxVal/with/key/lfnRM_16wslaPk3UDONUe')
blynk.virtual_write(2, potenValue)
time.sleep(0.5)
tempThread = threading.Thread(name='temperature', target=temperature)
humThread = threading.Thread(name='humidity', target=humidity)
potnThread = threading.Thread(name='potentiometer', target=potentiometer)
tempThread.start()
humThread.start()
potnThread.start()
blynk.run()