php - Serial Push to Server Sent Script -
i have lamp web server python script continuously monitoring serial port incoming data. part of home automation system (with arduino yun , bunch of pro minis each nrf24l01+ rf transceivers).
my goals to:
- save incoming data mysql in appropriate location, 'door open' or 'temp = 72f'. believe python script can handle this.
- use server sent events (sse) push new data client browser (when client connected).
i realize use ajax, pushing data seems better polling. wrinkle somehow have sse bound data python script on php, when sse php script running. also, believe new instance of sse php script created each client - there won't 1:1 ratio of python php. thought having sse php monitor mysql database, polling, albeit high frequency polling.
alternatively, thinking sse php script monitor serial port, think serial data can read once, multiple scripts competing data, not work either.
what best way achieve these 2 goals of saving incoming data datase , using sse transport layer?
so here ended doing:
- python daemon runs on arduino yun monitoring ttyath0 serial port new data. when new string received (i choose terminate strings ~ character), parses , stores mysql database. update of mysql entry automatically updates time stamp on row. configuration of table.
- loading html page starts browser subscription server sent events .php script running on server
- the script searches mysql database entries newer couple seconds old , passes json webpage parsed javascript animate page.
i decided 3 second refresh time of server sent script sufficient needs. in theory run continuously, flood webpage , reduce performance. script configured run every 1 second - perhaps i'll make update someday.
...anyways, that's how did it, no websockets required! think more elegant hanging ajax query.
Comments
Post a Comment