I want to control a relay board using arduino for home automation. I am using raspberry-pi2 on which a PHP script to run a python script that establishes a serial com to arduino via USB. Every time I run the python script by PHP, the arduino restarts and there is no effect. When I run the py script on terminal, it works. Is there a way to keep the SERIAL COM on throughout and communicate to the arduino?
PHP :
<?php
$pin = $_GET["pin"];
exec("sudo python switch.py");
echo "Switched";
?>
<script type = "text/javascript">
setTimeout("self.close()",1000);
</script>
Python:
import serial
import sys
ser = serial.Serial('/dev/ttyACM0',9600)
ser.write('8')