Hi i have windows 7 as host and a virtualbox guest os running debian linux vm.
I have accessed the webserver of my debian vm from my host system by doing a portforward in virtualbox eg. host port: 8888 guest: 80 so when im going to access the webserver of my debian vm I'll just open my host browser and type in localhost:8888..
Now what i want to do is control arduino via webserver of debian vm using php.. i can do this with no problem in my host system.. but when im using the webserver of debian vm i can't seem to make it work.. i even mapped my serial port COM1 to /dev/ttyS0 in virtualbox so now i can echo in the terminal of my debian to control my arduino which works well..
eg.
echo "a" > /dev/ttyS0 - turn the led on in arduino // works well
echo "b" > /dev/ttyS0 - turn the led off // works well
now how can i use the webserver of debian linux vm to control my arduino..
here's how i control it in my host system without a problem..
Just a guess, but it might have something to do with the stty settings. Maybe php sets the stty to some default set of settings which don't work with your Arduino. Possibly baud rate, and/or some others.
What I would do is, in a terminal window of virtualbox running debian linux, do
stty -F /dev/ttyS0
at the point where your echo commands work,
and then do it again after you run your php script. Then compare the two.
I haven't ever tried to do serial IO in php, but I assume there are some functions for setting the port characteristics. You might have to use those. Might even be that there's a specific function, not fopen(), to use for port IO, rather than file IO.
Can you be a bit more specific? Does the fopen() succeed? Does the user account that the webserver is running under have permission to write to the device?
PeterH:
Can you be a bit more specific? Does the fopen() succeed? Does the user account that the webserver is running under have permission to write to the device?
Typically, IIRC, in a default php installation, the error reporting is set such that a failed fopen() would spew a message back to the web browser. But, the OP should check the Apache error log for pertinent messages too.
I wonder if pup is being placed in some kind of dmz to insulate hardware from crackers. Try to turn on logs and see if any errors/warnings are generated.
for some reasons i can't make that code work everytime i use that command it always says unknown command -f.. but i use this instead to check the configuration of the port stty -a < /dev/ttyS0 ..
thank you sir for the reply...
Can you be a bit more specific? Does the fopen() succeed? Does the user account that the webserver is running under have permission to write to the device?
what i meant is that it can't open the com port.. it does not turn the led on.. i even test if the com port is open and i always get fail.. here's the code im using for testing.. Im using root and yes it does have permission to write in the device.
Typically, IIRC, in a default php installation, the error reporting is set such that a failed fopen() would spew a message back to the web browser. But, the OP should check the Apache error log for pertinent messages too.
thank you for the reply sir..how can i check the error logs in debian linux vm?..
I wonder if pup is being placed in some kind of dmz to insulate hardware from crackers. Try to turn on logs and see if any errors/warnings are generated.
thank you sir.. but how can i turn it on?.. i know how in windows but in linux i dont sir..
i use the php serial class to do it.
maybe this will help you:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'asdf';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'arduino';
mysql_select_db($dbname);
$sql="select * from levels";
$results= mysql_query($sql);
$row = mysql_fetch_array($results);
/* Script for Checking all the levels*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
// Load the serial port class
require("php_serial.class.php");
//Initialize the class
$serial = new phpSerial();
//Specify the serial port to use... in this case COM1
$serial->deviceSet("/dev/ttyUSB0");
//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")
// Ask drydingledongle Arduino what the levels are.
$sometext = " Air Temp: 70F|CO2:770 Hum:70| H2O Temp:65F|PPM:1200 PH:5.8";
$serial->deviceOpen();
sleep(10); //wait for Arduino reset after serial open
$serial->sendMessage(chr(36)); // start transmission
$serial->sendMessage($sometext); //Ask Dry Dingle Dongle for its readings
$serial->sendMessage(chr(35)); // end transmission
$read = '';
$theResult = '';
$start = microtime_float();
while ( ($read == '') && (microtime_float() <= $start + 1.5) )
{
$read = $serial->readPort();
if ($read != '')
{
$theResult .= $read;
$read = '';
}
}
$serial->deviceClose();
?>
endl3ss:
thank you sir.. but how can i turn it on?.. i know how in windows but in linux i dont sir..
By default, logging is already enabled (well, that's what I remember). Look in /var/log/apache2 for the most recent error.log file. Directory name might be different, but it'll be somewhere down in /var/log.
You might need to play around with logging settings in your php.ini file, but I doubt it. However, learning to do so can't hurt either. So head to php.net and do some reading.