-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleverTemperatures.py
executable file
·45 lines (37 loc) · 1.3 KB
/
releverTemperatures.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import locale
import logging
import time
import datetime
from lib import ds18b20
INTERVALLE_ENTRE_2_RELEVES_EN_MINUTES=10
nbMaxTentatives = 3
FORMAT = '%(asctime)-15s:%(levelname)s:%(message)s'
logging.basicConfig(format=FORMAT,level=logging.DEBUG)
logging.info("Initialisation")
ds18b20.init()
locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')
devicesName=ds18b20.getDevicesName()
nbDevices=len(devicesName)
if (nbDevices > 0):
logging.info("Nombre de sondes : %s", nbDevices)
while True:
for deviceName in devicesName:
nbTentatives = 0
temperature = None
while temperature is None and nbTentatives < nbMaxTentatives:
temperature=ds18b20.getTemperature(deviceName)
nbTentatives += 1
if temperature is not None:
now = datetime.datetime.now()
ds18b20.insertTemperature(now, deviceName, temperature)
logging.debug("Température de la sonde %s : %s", deviceName, temperature)
else:
logging.error("Température non récupérée pour la sonde %s : %s tentatives en echec", deviceName, nbMaxTentatives)
#wait x seconds and repeat
logging.debug("Prochain relevé dans %s minutes", INTERVALLE_ENTRE_2_RELEVES_EN_MINUTES)
time.sleep(INTERVALLE_ENTRE_2_RELEVES_EN_MINUTES * 60)
else:
logging.error("Aucune sonde de température")
exit(0)