PHP -> Debian -> Arduino

Hi i'm controlling arduino from the webserver of my virtualbox running debian linux vm.. I can control it without any problems.. now i want to control it like this.. PHP -> debian -> arduino.. i know i can control it from the webserver of my debian vm.. but how can i let debian convert the data sent of php, then let debian send it to arduino like it's doing an echo?.. say for example..

PHP sends -> "Up" -> Debian dev ttsy0(convert "Up" to a hex for example 0xff then send it to -> arduino(Arduino will then read it as serial and print it);

Sample

$conn = fopen("/dev/ttyS0", "w+");
fwrite($conn, "Up");

Sample arduino

char c = Serial.read();
readData[pos] = c;
pos++;
if(c=='\n'){
Serial.print(readData);   //prints 0xff or ff;
}

How can i let debian do the processing once it receives data from php?.. do i need to create a char driver? say for example i created a char driver /dev/mydevice

php will then send data to /dev/mydevice then /mydevice will convert "Up" to hex 0xff or FF then pass the converted data to /dev/ttyS0 which is the serial port of linux to arduino..

Is there an easy or other way to do it?.. thank you in advance..

I think you could probably do it by having PHP write to the terminal device corresponding to the console that your application is running in, and have your application read/write to the Arduino's COM port. But if it's only transforming the format (binary/text etc) wouldn't it be better to do that either in PHP or within the Arduino sketch? You'd be introducing quite a lot of complexity for no obvious purpose.

PeterH: I think you could probably do it by having PHP write to the terminal device corresponding to the console that your application is running in, and have your application read/write to the Arduino's COM port. But if it's only transforming the format (binary/text etc) wouldn't it be better to do that either in PHP or within the Arduino sketch? You'd be introducing quite a lot of complexity for no obvious purpose.

Ok remove the transformation thingy.. I will write an application in linux that will read/write in a serial port?.. i will just do an if statements inside the application e.g. if data received from php check the data..

if equals to up send ff to serial port /dev/ttyS0..

is that ryt sir?

endl3ss: Ok remove the transformation thingy.. I will write an application in linux that will read/write in a serial port?.. i will just do an if statements inside the application e.g. if data received from php check the data..

if equals to up send ff to serial port /dev/ttyS0..

is that ryt sir?

I was think more along the lines of having the PHP open the serial port and write the binary message directly. Any reason your PHP can't do the text-to-binary conversion?