I am working on a system that has a bunch of sensors communicating with a linux machine. I need to make a web interface for this to display status of sensors and automatically update them when the status of any of the sensors changes(or just automatically update them every few seconds).
The code for reading sensors is all in C code. What are the options for pushing the sensor data to the web browser automatically or even by continuously requesting the data?
I have considered the following scheme: Allocate shared memory in the C program for the sensor data, which can be read by a server side script like php. Then have some ajax or something requesting the data on a loop or timer event.
Is it possible to push the data to the client rather than pull?
I really do not have any experience with php/ajax, so any tips on how to implement this would be great.
Some key elements I do not know:
-How to do timing in javascript
-How to get some sort of structured data in javascript on the fly from a request to the server(eg php page reading the sensor data)
setInterval
for this.setTimeout("yourAjaxRequestFunction",delay);
As you say , to getting data , you have two solutions :
A) Pulling data with ajax
You easily can do some periodical task with setInterval :
setInterval(callbackserver, PERIOD_MILLIS);
If you use a framework like jquery, there is plenty of plugin for periodical updating.
B) Pushing Data with a js server
Data can be push to the browser instead of pulling it. For that you need a server based on protocol like Comet. Check this project for more information
How to get some sort of structured data in javascript on the fly from a request to the server
json seems to be a perfect solution for structured data accross langage.
I have considered the following scheme: Allocate shared memory in the C program for the sensor data, which can be read by a server side script like php
Why not simply make a deamon in C and get data from it via PHP with a exec("mydeamon -data")
command for exemple
In your case, if you/your company can afford it, I'd recommend Wt.
If your application is written in C then C++ would likely be more familiar than PHP or Javascript.
It can also handle pushing data to a web page using either ajax pull or web sockets.