Pages: [1]   Go Down
Author Topic: Arduino + Virtualbox running debian linux vm  (Read 1263 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..


PHP - works well in my host system..
Code:

$fp =fopen("com7", "w");
fwrite($fp, chr(97));               
fclose($fp);


I did the same thing in the webserver of my debian linux vm..

i created test.php: nano /var/www/test.php

PHP- webserver in debian vm which i open in my host system by localhost:8888/test.php

Code:

$fp =fopen("/dev/ttyS0", "w");
fwrite($fp, chr(97));               
fclose($fp);


it does not work..

How can i control my arduino via the webserver of virtualbox running debian linux?

Thanks in advance..


Logged

CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it does not work..

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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Dallas, Texas
Offline Offline
God Member
*****
Karma: 31
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
stty -F /dev/ttyS0

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...

Quote
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.

Code:

$conn = fopen("/dev/ttyS0", "w+");
if(!$conn) echo "fail";
else echo "pass";
fclose($conn);


thank for the reply.. what might be causing it?

Quote
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?..

Quote
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..
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what i meant is that it can't open the com port..
i even test if the com port is open and i always get fail

How absolutely positively certain are you that you have spelled the device name correctly?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i use the php serial class to do it.
maybe this will help you:
Code:
<?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";
$resultsmysql_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();
?>
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2512
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the Debian VM does /dev/ttySO have root-only permissions? Your Apache/PHP is assuredly not running with root permissions.

chmod a+rw /dev/ttySO or create the appropriate udev rule to relax the permissions.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i use ubuntu and you are right.  This gets me everytime I use a different computer.
do what Chagrin said.
Logged

CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Pages: [1]   Go Up
Jump to: