I have a webcam running on my web server of a goldfish in a tank. I want to have a link on the webpage interact with the Arduino. One thing will be to open a hacked toy backhoe bucket in order to put food into the tank.
I am running a headless Ubuntu 12.04 server so i thought the easiest way to do this is with a shell script so i wrote:
#! /bin/bash
echo -n "1" > /dev/ttyACM0
That interacts with this sketch:
int feedPin = 13;
void setup(){
Serial.begin(9600);
pinMode(feedPin, OUTPUT);
}
void loop(){
while (Serial.available() == 0);
int val = Serial.read() - '0';
if (val == 1) {
Serial.println("Feeding the fish");
digitalWrite(feedPin, HIGH);
delay(1500)
digitalWrite(feedPin, LOW);
}
else if (val ==0){
Serial.println("Stopping");
digitalWrite(ledPin, LOW);
}
else{
Serial.println("invalid");
}
}
For debugging right now all that does is turn on an LED and that is fine. I have a 100uf capacitor in between reset and ground to keep the connection alive (overkill but it works). When i run the shell script life is good and it words great.
So i wrote a simple PHP script that runs this shell script:
<h3>Feeding the Fish</h3>
<?
exec('sh feed.sh');
?>
When i run that from the command line it works great. So i put a link on the website to run it for me:
<li><a href="feed.php">Feed the Fish</a></li>
when i click the link nothing happens =(
So i went back to the command line and checked and chmoded all the permission, and then ran # sudo -u www-data php feed.php
to make sure apache could perform the task. It could not so i added www-data to the dialout goup using this:# usermod -a -G dialout www-data
and now it it works fine.
Now i switch over to my browser and click the link and it works! So i reload the page and it works again! Then about a minute later i try and do a page reload and nothing happens. Igo back to the webpage and re-click the link. Nothing.
That makes me think that it has something with me running # sudo -u www-data php feed.php
which opens the connection and then it times out and apache cant re-open the connection.
any ideas?