andrewsg3 / gurgi_ws1

This repo contains all code necessary to run a raspberry-pi enabled weather station designed to support GUR's Saltire-II launch.
https://www.gurocketry.com/
The Unlicense
0 stars 0 forks source link

Integrate Sam's code #7

Closed andrewsg3 closed 2 years ago

andrewsg3 commented 2 years ago

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 (), 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("").innerHTML = '<ParameterNamee.g.Humidity'> + body.parameterName . This is where the values get updated on the clients page.

andrewsg3 commented 2 years ago

app.py code: image

andrewsg3 commented 2 years ago

Integrated in latest update.