0

Just performing a simple turn on LED via web page script I found online and it would seem that echo commands are being executed after the shell_exec commands that follow them, is there a reason for this? Basically the on and off are quick enough not to really notice but the blinking echo only comes on after the blinking sequence has finished.

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>WIFI Controlled LED</title>
</head>
       <body>
       <center><b><font size = '20'>Control LED:</b>       
         <form method="get" action="index.php">                 
                 <input type="submit" style = "font-size: 16 pt" value="OFF" name="off">
                 <input type="submit" style = "font-size: 16 pt" value="ON" name="on">
                 <input type="submit" style = "font-size: 16 pt" value="BLINK" name="blink">
         </form>
         <?php
         shell_exec("/usr/local/bin/gpio -g mode 17 out");
         if(isset($_GET['off']))
         {
        echo "LED is off";
        shell_exec("/usr/local/bin/gpio -g write 17 0");
         }
    else if(isset($_GET['on']))
    {
        echo "LED is on";
        shell_exec("/usr/local/bin/gpio -g write 17 1");
    }
    else if(isset($_GET['blink']))
    {
        echo "LED is blinking";
        for($x = 0;$x<=4;$x++)
        {
            shell_exec("/usr/local/bin/gpio -g write 17 1");
            sleep(1);
            shell_exec("/usr/local/bin/gpio -g write 17 0");
            sleep(1);
        }
    }
        ?>
   </center></font>
   </body>
 </html>
miken32
  • 42,008
  • 16
  • 111
  • 154
Paul Reay
  • 3
  • 2
  • 2
    https://stackoverflow.com/questions/3133209/how-to-flush-output-after-each-echo-call – miken32 Dec 17 '18 at 18:46
  • Tried some of the options there but they didn't help. Would I be better off not using echo and getting php to alter the css of a html element to make it hide/show as needed? – Paul Reay Dec 17 '18 at 21:12
  • I find it unlikely that none of those solutions worked; are you sure you're not looking at an old or cached version of the page? You could put the PHP code controlling the LEDs at the very end of the document after all the HTML has been output. – miken32 Dec 17 '18 at 22:46

0 Answers0