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

108
Views
Caching of CSV files on Apache or a problem with the javascript fetch command?

I have a rather strange problem with csv files begin read by some javascript code. The csv file contains one line which changes every 10 seconds and the javascript code displays the data. The csv file is generated by a Python script which reads sensor values. The code runs fine for many hours, (surviving reboots or refreshes) but eventually with no apparent reason it seems that when the web page is reloaded (after a reboot or just a reload) the CSV file is read once and then never updates after that. Checking the CSV file with a text editor at that point shows that it is changing every 10 seconds as expected. The only solution at that point is to stop the Python script, change the file name of the CSV file and change the javascript to the same and then all is well until the whole thing repeats. Here is the javascipt code:

<script>
    setInterval(connectWeatherStation, 10000);
    function connectWeatherStation(){
        fetch('data4.csv') <!-- file needs name change after some time -->
        .then(response => response.text())
        .then(text => {
            var data = text.split(",");
            document.getElementById("ir_ambient").innerHTML = "IR Ambient: " + data[0];
        document.getElementById("sky_temperature").innerHTML = "IR Sky: " + data[1];
            document.getElementById("temperature").innerHTML = "Temp: " + data[2];
        document.getElementById("humidity").innerHTML = "Humidity: " + data[3];
            document.getElementById("rain_status").innerHTML = "Rain Status: " + data[4];
            document.getElementById("cloud_status").innerHTML = "Cloud Status: " + data[5];

            var clockElement = document.getElementById( "clock" );
            clock.innerHTML = new Date().toLocaleTimeString();
        })
    }

</script>

When this happens, the clock keeps running, so I know the javascript is actually running. I tried editing the apache2.conf adding some code to prevent caching but then the apache server would not start. I then tried a .htaccess in /var/www/html but it appears it will not load it. Perhaps something is wrong with the fetch command? This is all on the raspberry pi. Any suggestions? Thanks, Tom

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!