93 lines
3.1 KiB
Python
93 lines
3.1 KiB
Python
import time
|
||
|
||
# --------------------------------------------------------------------------------
|
||
# Gestion des pages web
|
||
# --------------------------------------------------------------------------------
|
||
|
||
import bottle, threading
|
||
|
||
def nouvelle_temp_cible (temperature):
|
||
""" Cette fonction sauvegarde la température cible """
|
||
with open('cible.txt', 'w', coding="utf8") as f:
|
||
f.write(température)
|
||
|
||
def temp_format_html ():
|
||
""" Cette fonction retourne un texte HTML contenant les mesures de températures"""
|
||
return 'Non implémenté'
|
||
|
||
|
||
@bottle.get('/')
|
||
def get_temp():
|
||
return temp_format_html()
|
||
|
||
threading.Thread(target=bottle.run, kwargs=dict(host='', port=8080)).start()
|
||
|
||
# --------------------------------------------------------------------------------
|
||
# Gestion du capteur de température
|
||
# --------------------------------------------------------------------------------
|
||
|
||
import os
|
||
import glob
|
||
|
||
# On trouve où sont les valeurs du capteurs
|
||
dossier_base = '/sys/bus/w1/devices/'
|
||
dossier_capteur = glob.glob(dossier_base + '28*')[0]
|
||
fichier_capteur = dossier_capteur + '/w1_slave'
|
||
fichier_actionneur = 'TODO'
|
||
|
||
def lecture_temp_brute():
|
||
""" Cette fonction retourne la valeur du capteur sans traitement """
|
||
with open(fichier_capteur, 'r') as f:
|
||
lines = f.readlines()
|
||
return lines
|
||
|
||
def lecture_temp():
|
||
""" Cette fonction calcule la température à partir des mesures brutes """
|
||
lines = lecture_temp_brute()
|
||
while lines[0].strip()[-3:] != 'YES':
|
||
time.sleep(0.2)
|
||
lines = lecture_temp_brute()
|
||
equals_pos = lines[1].find('t=')
|
||
if equals_pos != -1:
|
||
temp_string = lines[1][equals_pos+2:]
|
||
temp_c = float(temp_string) / 1000.0
|
||
return temp_c
|
||
|
||
# --------------------------------------------------------------------------------
|
||
# Gestion du capteur de température
|
||
# --------------------------------------------------------------------------------
|
||
|
||
def chauffage_on ():
|
||
""" Cette fonction allume le chauffage de la cuve """
|
||
with open(fichier_actionneur, 'w') as f:
|
||
f.write('1')
|
||
|
||
def chauffage_off ():
|
||
""" Cette fonction éteint le chauffage de la cuve """
|
||
with open(fichier_actionneur, 'w') as f:
|
||
f.write('0')
|
||
|
||
# --------------------------------------------------------------------------------
|
||
# Fonctions d’aide
|
||
# --------------------------------------------------------------------------------
|
||
|
||
def ajout_ligne_fichier(nom_fichier, ligne):
|
||
""" Cette fonction ajoute le texte dans la variable ligne à la fin du fichier « nom_fichier » """
|
||
with open(nom_fichier, 'a', encoding="utf8") as f:
|
||
f.write(ligne)
|
||
|
||
def temp_cible():
|
||
""" Cette fonction retourne la température cible qui doit être maintenue pendant la fermentation """
|
||
with open("cible.txt", 'r', coding="utf8") as f:
|
||
return f.read().strip()
|
||
|
||
# --------------------------------------------------------------------------------
|
||
# Programme principal
|
||
# --------------------------------------------------------------------------------
|
||
|
||
while True:
|
||
print(lecture_temp())
|
||
time.sleep(1)
|
||
|
||
|