OK I may be onto something. With Uno plugged into ttyACM0 directly on the Ubuntu 10.4 PC
Using the reset resistor between 3.3v and reset (120ohms i think)
10 second delay after opening the serial port
1.5 second delay after starting to read the data from the port.
using a cron script with no browser involved running for 15 minutes at one minute intervals I got results 100% of the time.
<?php
/* Script for turning LED on and off based on temperature*/
// Load the serial port class
require("php_serial.class.php");
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//Initialize the class
$serial = new phpSerial();
//Specify the serial port to use... in this case COM1
$serial->deviceSet("/dev/ttyACM0");
//Set the serial port parameters. The documentation says 9600 8-N-1, so
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
$serial->deviceOpen();
sleep(10); //wait for Arduino reset after serial open
$serial->sendMessage(chr(10)); // start transmission
$serial->sendMessage(chr(50));
$serial->sendMessage(chr(13)); // end transmission
$read = '';
$theResult = '';
$start = microtime_float();
while ( ($read == '') && (microtime_float() <= $start + 1.5) ) {
$read = $serial->readPort();
if ($read != '') {
$theResult .= $read;
$read = '';
}
}
$serial->deviceClose();
// etc...
echo "Read data: ".$theResult."
";
mysql_query("INSERT INTO logging (stuff,Sensor) VALUES ($theResult,'Air Temp')");
?>
Now on to the xbees and see what happens.