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