-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
executable file
·68 lines (46 loc) · 1.51 KB
/
script.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
import time
import sys
import datetime
from influxdb import InfluxDBClient
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, True) # Eteind
# Set this variables, influxDB should be localhost on Pi
host = "localhost"
port = 8086
user = "root"
password = "root"
# The database we created
dbname = "mydb"
# Interval de temps entre chaque mesure
interval =3500
client = InfluxDBClient(host, port, user, password, dbname)
def consultationTemp():
with open("/sys/bus/w1/devices/28-00000636f828/w1_slave", "r") as fichierTemp:
searchfile = fichierTemp.readlines()
for line in searchfile:
if 't=' in line:
temperature = round((float(line[29:]) / 1000), 1)
json_body = [
{
"measurement": "temperature",
"fields": {
"valeur": temperature
}
}
]
# Write JSON to InfluxDB
client.write_points(json_body)
def regulation():
state = GPIO.input(11)
if liste[-1] > 21:
if state == 1: # Eteind
GPIO.setup(11, False) # state = 0 ; Allume
print('Temperature au dessus de 22 : Allumage ventilateur')
if liste[-1] < 21:
if state == 0: # Allume
GPIO.setup(11, True) # state = 1 ; Eteind
print('Temperature en dessous de 21 : Extinction ventilateur!')
while True:
consultationTemp()
time.sleep(interval)