I am trying to create a domotica setup with my Arduino and my server. Before using the RF transmitter, I'm trying to control LEDs (setting them on/off) from my php webpage.
It all works perfectly, except for the fact that LED1 turns on when I'm loading/refreshing the webpage. My webpage contains the following code (which I adapted from https://www.lassiemarlowe.com/tutorials/power-led-bulbs-arduino-php-part-2/):
<html>
<head>
<title>Arduino Domotica Control Panel</title>
Some css code here...
<?php
switch($_POST)
{
case isset($_POST['submitOn']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 1);
fclose($fp);
break;
case isset($_POST['submitOff']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 2);
fclose($fp);
break;
case isset($_POST['submitOn1']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 3);
fclose($fp);
break;
case isset($_POST['submitOff1']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 4);
fclose($fp);
break;
case isset($_POST['submitOn2']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 5);
fclose($fp);
break;
case isset($_POST['submitOff2']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 6);
fclose($fp);
break;
case isset($_POST['allon']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 7);
fclose($fp);
break;
case isset($_POST['alloff']):
$fp = fopen("/dev/ttyUSB1", "w");
fwrite($fp, 8);
fclose($fp);
break;
}
?>
</head>
<body>
<h1>Control Panel</h1>
<form class="control-panel-frm" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type='submit' class="s3d turnOn" name='submitOn' value='LED 1 on'>
<input type='submit' class="s3d switchoff" name='submitOff' value='LED 1 off'>
<br><br>
<input type='submit' class="s3d turnOn" name='submitOn1' value='LED 2 on'>
<input type='submit' class="s3d switchoff" name='submitOff1' value='LED 2 off'>
<br><br>
<input type='submit' class="s3d turnOn" name='submitOn2' value='LED 3 on'>
<input type='submit' class="s3d switchoff" name='submitOff2' value='LED 3 off'>
<br><br>
<input type='submit' class="s3d turnOn" name='allon' value='All LEDs on'>
<input type='submit' class="s3d switchoff" name='alloff' value='All LEDs off'>
</form>
As stated before, the problem is that LED1 (corresponding to php post 'submitOn') turns on when I load/refresh the webpage. When checking the serial monitor, the Arduino receives a '1'.
What should I change in order to prevent my webpage from sending anything to the Arduino when it loads?