0

I have a microcontroller which reads a thermocouple and sends its values to a textfile on the Raspberry Pi.

On the Pi runs a apache server which hosts my website. The website shows the value from the textfile, but to get the actual value I have to refresh the page.

index.php

<html>
<?php $temp = file_get_contents('Temp.ESP'); ?>
 
     <header>
      <h2><?php echo $temp; ?> °C</h2>
     </header>
   
</html>

Thanks in advance

1 Answers1

1

with javascript Use the setTimeout() global method to create a timer. This will refresh the content after 5000 milliseconds (5 seconds): also don't forget to load the jquery lybrary inside the html head adding

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
setTimeout(function(){ 

$.get( "mydata.php", function( data ) {
$( "#mydata" ).html( data ); // this will replace the html refreshing its content using ajax

});


 }, 5000);` 
</script>

on the html change

<header>
<h2 id="mydata"></h2> ºC
</header>

notice the id="mydata"

the php only needs to echo the file contents also create the file mydata.php

Geomorillo
  • 985
  • 1
  • 9
  • 14