Hello,
I am using php to write to Arduino via a serial port (/dev/ttyACM0). The problem that I ran into is that I keep getting an Access Denied error in the log for the port. If I chmod the port, I can then write to it, but that only lasts until I make a change to the Arduino code or reset the device or computer. I tried adding myself to the dialout group and the uucp group like some sites suggested, but I still can not write to the port unless I chmod it first. I can also write to the port using python without any errors. Is their a way to force php to always allow me to write to that port?
Here is the php code
<?php
$verz="1.0";
$comPort = "/dev/ttyACM0"; /*change to correct com port */
if (isset($_POST["rcmd"])) {
$rcmd = $_POST["rcmd"];
switch ($rcmd) {
case "ON":
$fp = fopen($comPort, "w") or die("Can't Open Port");
fwrite($fp, "1");
sleep(1);
fclose($fp);
break;
case "OFF":
$fp = fopen($comPort, "w");
fwrite($fp, "0");
sleep(1);
fclose($fp);
break;
}
}
?>
<html>
<body>
<center><h1>Arduino from PHP Example</h1><b>Version <?php echo $verz; ?></b></center>
<form method="post" action="index.php">
<input type="submit" value="ON" name="rcmd">
<input type="submit" value="OFF" name="rcmd">
</form>
</body>
</html>
and here is the error
[Tue Oct 22 14:19:10 2013] [error] [client 127.0.0.1] PHP Warning: fopen(/dev/ttyACM0): failed to open stream: Permission denied in /var/www/arduino/index.php on line 10, referer: http://127.0.0.1/arduino/index.php
Any help would be appreciated,
Thanks