-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather-station.py
108 lines (82 loc) · 2.24 KB
/
weather-station.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import time
import datetime
import requests
import json
from matrix_lite import gpio
from meteocalc import Temp, dew_point, heat_index
from matrix_lite import led
from matrix_lite import sensors
def temperatureReadout(override):
temperature = sensors.pressure.read().temperature
print(temperature)
temperatureLED = temperature - 10
if (override > 0):
temperatureLED = override
ledSet = []
for x in range(1, int(temperatureLED)):
ledSet.append((25,0,0,0))
led.set(ledSet)
time.sleep(0.1)
led.set(ledSet)
if(temperatureLED > 40):
phoneContact()
led.set('White')
dangerAlert()
time.sleep(5)
def humidityReadout():
humidity = sensors.humidity.read().humidity
print(humidity)
humidityLED = int((humidity / 100) * 35)
if (humidityLED > 34):
humidityLED = humidityLED / 2
brightness = 2
else:
brightness = 1
ledSet = []
for x in range(1, int(humidityLED)):
ledSet.append((0,0,25 * brightness,0))
led.set(ledSet)
time.sleep(0.1)
time.sleep(5)
def heatIndex():
temperatureHI = (sensors.pressure.read().temperature) - 8
humidityHI = sensors.humidity.read().humidity
hi = heat_index(temperature=temperatureHI, humidity= humidityHI)
ledSet = []
for x in range(1, int(hi)):
ledSet.append((25,0,25,0))
led.set(ledSet)
time.sleep(0.1)
if (int(hi) >= 40):
phoneContact()
dangerAlert()
print(hi)
time.sleep(5)
def phoneContact():
url = 'https://maker.ifttt.com/trigger/call/with/key/br6w0TeQJiNDHpWuKYInm6'
x = requests.post(url, data = 'test')
print("Reached")
def dangerAlert():
while True:
led.set('Red')
time.sleep(.5)
led.set('Black')
time.sleep(.5)
def sendWeatherData():
humidity = sensors.humidity.read().humidity
temperature = sensors.pressure.read().temperature - 8
hi = heat_index(temperature=temperature, humidity= humidity)
uri = "https://shellhacks2019-1f061.appspot.com/addMarker"
x = requests.post(uri, json = {'humid' : int(humidity), 'heatindex' : int(hi), 'bodytext' : 'SOS', 'fallenAlert' : 'false', 'temp' : int(temperature)})
print(x)
gpio.setFunction(0, 'DIGITAL')
gpio.setMode(0, "input")
while True:
currentDT = datetime.datetime.now()
led.set('Black')
temperatureReadout(0)
humidityReadout()
heatIndex()
if (currentDT.minute % 6 == 0):
sendWeatherData()
led.set('Black')