Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EspaceRaspberryFrancais/5ab526d2d2ed549a3ee05cff99a3c44e to your computer and use it in GitHub Desktop.
Save EspaceRaspberryFrancais/5ab526d2d2ed549a3ee05cff99a3c44e to your computer and use it in GitHub Desktop.
#!/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