title: Serial connection with Arduino, PHP & OpenWrt. Bug?
body: <p>I'm trying to create a PHP web interface to control Arduino Uno via USB interface on TP-Link MR3420 router using OpenWrt firmware</p>
  
  <p>The weird thing is that my PHP script only get reply from arduino after running a python script that communicate with arduino</p>
  
  <p>I'm sure that my PHP script is working since it was able to turn off leds on arduino but get no reply from arduino</p>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>require("lib/php_serial.class.php");
  
  $serial = new phpSerial;
  
  $serial-&gt;deviceSet("/dev/ttyACM0");
  $serial-&gt;confBaudRate(9600);
  
  $serial-&gt;deviceOpen();
  $serial-&gt;sendMessage($cmd);
  sleep(1);
  $read = $serial-&gt;readPort();
  $serial-&gt;deviceClose();
  </code></pre>
  
  <p>Here is my arduino sketch:</p>
  
  <pre><code>int numSerial;
  if (Serial.available() &gt; 0)
  {
  char inByte = Serial.read();
  switch (inByte)
  {
  case 'l':
    numSerial = numberFromSerial();
    if (numSerial &gt;= 0)
    {
      Serial.print("LED Mode: ");
      switch (numSerial)
      {
      case 0:
        ledMode = 0;
        Serial.print("OFF");
        break;
      case 1:
        ledMode = 1;
        Serial.print("TEMP");
        break;
      case 2:
        ledMode = 2;
        Serial.print("KR");
        break;
      }
    }
    else
      Serial.print(ledMode);
    break;
  case 't': //Data request
    Serial.print(getTemp());
    break;
  }
  }
  </code></pre>
  
  <p>And here is my python code:</p>
  
  <pre><code>    import serial
  ser = serial.Serial("/dev/ttyACM0", 9600, timeout=3)
  ser.open()
  ser.write("t")
  print ser.readline()
  ser.close()
  </code></pre>
  
  <p>Please help.
  Thanks.</p>
  
  <p><strong>Found the real source of the problem!</strong></p>
  
  <p>In phpSerial Class:</p>
  
  <p><code>$ret = $this-&gt;_exec("stty -F " . $this-&gt;_device . " " . (int) $rate, $out);</code></p>
  
  <p>Replace with:</p>
  
  <p><code>$ret = $this-&gt;_exec("stty -F " . $this-&gt;_device . " raw speed " . (int) $rate, $out);</code></p>