Pages: [1]   Go Down
Author Topic: How to capture serial data and show it in a php webpage?  (Read 1100 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 150
veroboaring is the new XGame - Extreme Veroboarder
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all!

I have my Arduino as a batery charger and batery monitor.
This send via RS-232 a string similar to this:

13.8|0.22|12.5|CRC|CR&LF

I'm using a linux server with an Apache web server.
Now I know that I must use BASH or PERL to write an script to capture this data at the serial port and parse it.

Now what is the best way to do this? capture the string into a text file using a BASH script and then read the file from the PHP page and print it in the webpage?

Best Regards!
Frank
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now I know that I must use BASH or PERL to write an script to capture this data at the serial port and parse it.
Those are only two possibilities. There are dozens of others.

Quote
Now what is the best way to do this? capture the string into a text file using a BASH script and then read the file from the PHP page and print it in the webpage?
Neither of those languages would be my choice. PHP can read directly from the serial port, and skip all that crap with having the script open a file, write to it, close it, and then having PHP open it, read it, and close it.
Logged

ITA - PV - Canneto Pavese
Offline Offline
Newbie
*
Karma: 0
Posts: 36
oggi sono stanco; non parlatemi di lavoro!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the monitoring is web based you can use Perl with module device:SerialPort or PHP with php_serial_class; there are other options to write what you need  but using Perl or Php you can find many examples on web.
All "todo" is to read the data from serial port, split(Perl)/(explode Php) it using the pipe (|) char and print the resulting array rows (quite similar in both languages).
You might also use bash or Perl to write a simple text console monitor; in this case you don't need Apache
« Last Edit: January 23, 2013, 04:08:16 pm by lsinfo » Logged

Leo55

0
Offline Offline
Full Member
***
Karma: 0
Posts: 150
veroboaring is the new XGame - Extreme Veroboarder
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

May be this will be helpfully to decide the software structure.
This battery system is inside my Atom & Linux SIP server. What I need to do when the battery system will be empty is send a cmd to the computer to shutdown itself. So for this case I think that PHP is no the option because we must have a user session on it.

So I need to execute the shutdown cmd and save in some file the battery controller string.

I think that the option will be BASH for the main and PHP for html printing

I'm correct?

Best Regards
Frank


Logged

Pages: [1]   Go Up
Jump to: