Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
JavaScript/python communications on two different devices

I have a python script that reads sensor data using pyserial and saves it on a .txt file. I have another python script that reads the data from a text file and puts it on an HTML page using Flask API. The HTML page is on a local network. I want to pass the sensor data from the HTML page to my User Interface code (.js) on another device. How can I make this communication possible? Here is my Python code that uses flask API to put the sensor data on an HTML page

global data
data='0'
@app.route('/')
def index():
    with open('Sensor_Data_Storage.txt', 'rb') as File1: 
        line = File1.readline().decode()
    print(line)
    return render_template('sensor.html',dist=line)

if __name__ == '__main__':
    try:
        wsgi.server(eventlet.listen(('192.168.0.110',8000)),app)
    except KeyboardInterrupt:
        print("Keyboard interrupt received. Exiting.")
    finally:
        # clean up
        File1.close()

Here is my HTML page code (sensor.HTML)

<div class="jumbotron jumbotron-fluid">
  <div class="container">
    <br>
    <br>
    <h3 class="Tem">{{dist}}</h3>
    <br>
    <br>
  </div>
</div>

This is my Javascript code (the UI)

const sensorDataUrl = "http://192.168.0.110:8000";

function Sensor1Data() {
  const [sensorData, setSensorData] = useState({});

  useEffect(() => {
    getSensorDataWithFetch();
  }, []);

  const getSensorDataWithFetch = async () => {
    const response = await fetch(sensorDataUrl);
    const jsonData = await response.json();
    setSensorData(jsonData);
  };

  return(
    <div>
      <p> {sensorData.dist} </p>

    </div>
  );
}

export default Sensor1Data;

Sensor Data on the HTML Page

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda