microcontroller with temperature sensor sends readings by the get method
To create an http server that records the temperature received in the GET request from the microcontroller and shows it later in subsequent requests, you can use the bottle library :
#!/usr/bin/env python from bottle import route, request, run, template # $ pip install bottle temperature = None @route('/') def index(): global temperature temperature = request.query.temperature or temperature return template('<b>Temperature: {{temperature}}</b>', temperature=temperature) run(host='localhost', port=8000)
When you run this Python script, an http server is started, which listens on the local machine on port 8000.
When a GET request containing a temperature parameter is received, the global temperature variable is updated and immediately displayed as html. If the temperature parameter is not specified, then the previous value is returned or None , if the temperature parameter has not been specified yet.
That is, it is expected that the part reading the temperature from the sensor performs queries of the type:
$ http ':8000?temperature=20'
which sets the value (20).
To read this value, it is enough to omit the parameter:
$ http :8000
You can see in the browser (the same request):
$ python -mwebbrowser http://localhost:8000
http command can be obtained by installing the httpie library :
$ pip install httpie
Usually, instead of using global variables, a database is used (which allows you to save the temperature value between the server process runs or its instances in different processes). In the simplest case, a simple flat text file can be used. Here is an example c sqlite .
If you do not want to put the bottle using the command (preferably inside virtualenv):
$ pip install bottle
it is enough to download bottle.py and put it next to the server code.