PHP Communication not working...

Discussion in 'Troubleshooting' started by VMannell0, Jan 18, 2014.

  1. VMannell0

    VMannell0 New Member

    Joined:
    Jan 13, 2014
    Messages:
    1
    Likes Received:
    0
    I have the SD image offered on this site running Apache PHP5 etc...

    Trying to duplicate the Meteorological project this is my PHP:
    Code:
    <?php
    
    include "php_serial.class.php";
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    define("PORT","/dev/ttymxc3");
    $serial = new phpSerial;
    $serial->deviceSet(PORT);
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    
    $rawTemps=0;
    
    if (isset($_GET["REFRESH"]))
    { 
            $serial->deviceOpen();
            $serial->sendMessage("c");
            $rawTemps = $serial->readPort();
            $serial->deviceClose();
    
    }
    else
    { 
            $serial->deviceOpen();
            $serial->sendMessage("c");
            $rawTemps = $serial->readPort();
            $serial->deviceClose();
    }
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html> 
    <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
            <title>Temperature and Humidity with DHT11</title> 
    </head> 
    <body>
            <h1>--UDOO SYSTEM--METEO DATA DETECTION--</h1>
            Last Detection <?php echo date('Y-m-d H:i:s', time()); ?><br/><br/>
            <?php echo $rawTemps; ?>
            <br><br><br>
            <form <?php echo $_SERVER['PHP_SELF']; ?> method="get">
                    <input type="submit" name="REFRESH" value="REFRESH">
            </form>
    </body> 
    </html>
    How ever it can not open the port...
    "Warning: Unable to open the device in /var/www/php_serial.class.php on line 157"

    www-data is a member of "intserial" "dialout" & "www-data"

    HELP greatly appreciated!!
     
  2. venkatbo

    venkatbo Member

    Joined:
    Jun 14, 2013
    Messages:
    45
    Likes Received:
    1
    Have no php experience, but a clue may be here...

    Your code is setting up the serial port /dev/ttymxc3 for its operations and includes functions in php_serial.class.php. Looking on the web for an implementation of that php file, I found one at: http://www.phpclasses.org/browse/file/17926.html. Unsure if your php lib code matches or not, but, looking at line 157 (in function deviceOpen ($mode = "r+b"), I see this:
    Code:
    trigger_error("Unable to open the device", E_USER_WARNING);[/i]
    
    which matches the error msg you are seeing...

    So looks like one or more of the following possible issues are at play:
    • . /dev/ttymxc3 may not be defined on your system
    • . It may be being used by another app
    • . your php script is failing to open the port
    • . you are not setting the port for read/write mode per deviceOpen api signature ....

    hth,
    /venkat
     

Share This Page