Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!