Closed andrewsg3 closed 2 years ago
), a script tag is opened . Everything in here relates to calling a function in app.py at a fixed interval.
the "fetch" function asks app.py to run /update, and this is then piped to "response". This is again piped to document.getElementById("
app.py code:
Integrated in latest update.
Sam Obosu provided me with javascript-based code that would allow values on the webpage to be updated at a fixed interval. The code can be found in two places:
app.py A new route called /update is created. In this, we have a line to be printed for debugging purposes to make sure its getting called (print("Updated data")) and only one task: return {'temperature': value}. Everything inside the curly brackets gets passed back to javascript for re rendering the page. So we can fill that with whatever names we've given to each of our parameters e.g. humidity, temperature and every time the javascript code in index.html calls /update it will return the current values of those variables.
templates/index.html After the closing tag of body (