How to access a serial port and work with it from a web page?

HI all!

I’m a beginner with freePBX.
But I design my own server based on a ATOM computer and a 12V UPS system.

What I want to do is this, first wrote some code that talks with the serial port and update some MySQL table that then let me build a php active page that show this information.

So for now I need to know two things:

  1. Can I write some script/python that the OS can run and recovery data from the serial port ?
  2. How I can update a MySQL table ?
  3. How I can access this table from the WEB and recovery the MySQL table and print it in HTML?

A point to start will be great, I will read about it to clarify these ideas bur almost to start I need the basements

Best Regards

A beginner in FreePBX or a beginner in all things linx?, If you have a modicum of linux skills then a possibl;e good “basement” might be :-

I make some assumptions, your serial port is asynchronous (both in physical signaling and data stream) in other words what comes into the serial port needs to be buffered so you don’t lose data. This you can do with something like:-

socat -u /dev/ttyS0,raw,b19200,echo=0,crnl GOPEN:/yourfile &

make sure you set baudrate bytesize stopbits etc. to suit.

To update a mysql table the mysql syntax is:-

UPDATE table_reference SET col_name1=expr1, col_name2=expr2 […] WHERE where_condition;

Use bash or php or perl or whatever wrapper to do that. The data you want to update will be in /yourfile it is up to you to ensure all updates are applied before you discard that data.

That was your two questions, a free bonus to 3) is, php is well designed to do exactly that for you.

Good luck. I think you have a little work to do yet :wink:

Hi dicko!
Yeap! you are right I’m a beginner in all things.

Now, and talking about the scripting format. I’m thinking in a .bat file that have all the cmds or coding, what format use linux?

And how this file will be executed when the linux starts?

Best Regards!!!

Since you mentioned your 12v UPS, I’m assuming you wish to communicate with it… you can take a look at the SysAdmin Pro module that includes support for UPS integration. The module is $25.

UPS Management - UPS management can be integrated directly into FreePBX. This can be used to properly shutdown the PBX in case of power loss. This module can also alert you to power related issues.

Then welcome to the wonderful world of Linux.

I suggest you spend quite some time learning the basics of the OS and “scripting” by googleing for “bash tutorial”. It will then all slowly become clear.

Basically any text file can be made executable, the first line will let the OS what interpreter to use, for example


for bash or


for perl etc.

1 Like

Hi dicko!
I’m reading about bash and perl. But I remember something. Hem… what about python? The free PBX linux have the interpreter for this?

I wrote a lot of code in python so it will be very easy to me do this.

Best regards

FreePBX is CentOS. You can install Python using yum if it has not been already.

1 Like

Yep, what I will do is wrote my application in a language that I can do easy and then decide if I leave in python or I will recode it in bash or perl.

Best Regards!!