Search code examples
pythonhtmlsocketsserverraspberry-pi3

Displaying a Constantly Changing Python Variable in HTML


I am building a car server with Raspberry Pi 3.

I am reading the speed variable from serial ports using Python. This variable continuously changes as the car speed changes.

I want to display that value live, in a HTML file. How can I do this?

I tried creating a text file from the Python script which constantly overwrites a speed.txt and prints on the HTML but as I read it is not secure and fast enough for monitoring.


Solution

  • Your Html page must be dynamic and communicate with a web server. You have 2 options for updating the car speed :

    1. use XHR and read the speed periodically from the web server
    2. use websocket and let the server push the latest speed to your page.

    You can use a framework like Flask for both options