-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (32 loc) · 1.08 KB
/
main.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
from bmp180 import bmp180
import pymysql.cursors # type: ignore
import requests # type: ignore
class mySensor:
def __init__(self):
self.sensor = bmp180(0x77)
self.connection = pymysql.connect(
host="127.0.0.1",
user="marcos",
password="Tucm+1985",
db="mySensors"
)
def sensorInformation(self):
data = (
self.sensor.get_temp(),
self.sensor.get_altitude()
)
cursor = self.connection.cursor(pymysql.cursors.DictCursor)
cursor.execute("INSERT INTO temperature (value1, value2) VALUES (%s, %s)", data)
self.connection.commit()
return data
# main code start here!
setpoint = 35
sensor = mySensor()
url = "https://io.adafruit.com/api/v2/webhooks/feed/wCTd1eGUXzsVyVUT99TCRhh3qBpZ/raw"
headers = {
'Content-Type': 'application/octet-stream'
}
temperature = sensor.sensorInformation()[0]
print("Current Temperature: {0:.2f}".format(temperature))
if temperature > setpoint:
requests.request('POST', url, headers=headers, data=str(temperature))