.1 | <?php if($_SERVER['REQUEST_METHOD']==='POST'){#$start=number_format(microtime(true),10,'.','');
.2 | system('tail /media/peplive/1844AEA344AE82DC/ALL/bot/o.txt');
.3 | #$end=number_format(microtime(true),10,'.','');echo '<br><br>'.($end-$start)*1000;
.4 | exit();}?>
.5 | <!DOCTYPE HTML><meta name="viewport" content="width=device-width,initial-scale=1.0">
.6 | <html><style><?php include('style.css'); ?></style>
.7 | <body><nav><h1><span id="c">🟤</span> Arduino log</h1></nav>
.8 | <div><span id="b">This shows the log of the Arduino's counting script. Refresh manually to see it change since JS isn't running</span><br>
.9 | <span style="color:#930">I first have a <a href="/source.php?f=arduino.c" target="_blank">simple Arduino script</a> to read millis(), an internal timer that ticks every millisecond and output it to serial (USB). I then use a bash script on the server to stream the output to the HDD, where <a href="/source.php?f=arduino.php" target="_blank">this PHP code</a> tails the file. JS, if enabled, will request an update every second and blink the virtual LED here.</span>
10 | <pre id="a" style="color:#03f"><?php system('tail /media/peplive/1844AEA344AE82DC/ALL/bot/o.txt');?></pre></div><script>
11 | document.getElementById('b').innerHTML='This shows the log of the Arduino\'s counting script. It should update every second.';
12 | setInterval(sync,1000);
13 | function cls(){document.getElementById('c').innerHTML='⚫️';}cls();
14 | function sync(){
15 | var x=new XMLHttpRequest();
16 | x.onreadystatechange=function(){
17 | if(this.readyState==4&&this.status==200){
18 | document.getElementById('a').innerHTML=this.responseText;
19 | document.getElementById('c').innerHTML='🟡';setTimeout(cls,100);
20 | }};
21 | x.open('POST','arduino.php',true);
22 | x.send();}
23 | </script></body></html>