Search code examples
pythonflaskraspberry-pi2

Continuously read data in real time with Flask + Python


I want to read in a webapp some elements (CPU temperature, CPU usage, state of some sensors...) in real-time from my Raspberry Pi. I know Python instruction to do this, but I want to read these values (let's focus now only on CPU temperature, for example) from a PHP page in real-time, so continuously refreshing the page. I've found various methods on the internet, but there's here a SIMPLE mode to do this?

This is my code:

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    temp="There I'll put instructions..."
    return render_template("index.php", temp=temp)


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

Solution

  • I simply resolved adding <body onload="location=''"> in the HTML code of PHP page.