I have a LAMP web server with a Python script continuously monitoring a serial port for incoming data. This is part of a home automation system (with Arduino Yun and a bunch of Pro Minis each with nrf24L01+ RF transceivers).
My goals are to:
- Save the incoming data to MySQL in the appropriate location, like 'door open' or 'temp = 72F'. I believe the Python script can handle this.
- Use Server Sent Events (SSE) to push new data to a client browser (when a client is connected).
I realize I could use AJAX, but pushing the data seems better than polling. The wrinkle is that I somehow have to get the SSE bound data from the python script over to PHP, but only when the SSE PHP script is running. Also, I believe a new instance of the SSE PHP script is created with each client - so there won't even be a 1:1 ratio of python to PHP. I thought about having the SSE PHP monitor the MySQL database, but that is essentially back to polling, albeit likely very high frequency polling.
Alternatively, I was thinking that the SSE PHP script could monitor the serial port, but I think the serial data can only be read once, so multiple scripts would be competing for the data, which would not work either.
What is the best way to achieve these two goals of saving the incoming data to my datase and using SSE as a transport layer?