Last active
April 24, 2021 12:08
-
-
Save EspaceRaspberryFrancais/5ab526d2d2ed549a3ee05cff99a3c44e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from flask import Flask, render_template | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setwarnings(False) | |
app = Flask(__name__) | |
# Fonction : Retourner la temperature actuelle et ordonner ou non son enregistrement | |
def getTemp(sauvegardeStatus): | |
# On ouvre le fichier de la sonde. Remplacer les X par le numero de la sonde | |
fichSonde = open("/sys/bus/w1/devices/28-XXXXXXXXXXXX/w1_slave") | |
contenu = fichSonde.read() | |
fichSonde.close() | |
# On 'nettoie' le contenu pour recuperer que la temperature | |
secondeLigne = contenu.split("\n")[1] | |
temperatureData = secondeLigne.split(" ")[9] | |
temperature = float(temperatureData[2:-2]) | |
temperature = temperature / 10 | |
return temperature | |
@app.route("/getTemp") | |
def affTemp(): | |
return render_template('index.html', temp=getTemp(0)) | |
app.run(debug=True, host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment