Hello,
I am making a home automation system which will work over the web.
RIght now, I am trying to do basic serial port IO through PHP. For some strange reason PHP serial class is not working in my ubuntu installation.
So, I tried file IO functions in PHP and fwrite() worked well and sent character data to arduino which my arduino could recognise correctly.
The code for writing to the port is this :
<?PHP
$f_pointer =fopen("/dev/ttyS1", "w");
fwrite($f_pointer, chr(1));
flose($f_pointer);
?>
This code sends ASCII of 1 which I read on my arduino and do some stuff.
But the fread function doesn't seem to work, maybe something else is needed than this but I am not sure.
<?PHP
$f_pointer =fopen("/dev/ttyS1", "r");
$var=fread($f_pointer, 8); //8 is the character length to be read. arduino sends a char length data
print "$var";
flose($f_pointer);
?>
Is the above code correct? What can be done to read the serial port if PHP serial is not working??