Marius
Marius

Reputation:

Taking analog inputs to website

I have a php web app.

I want to collect data from analog sensors to display values on the web app (temperature and such)

I can collect the data using an SPI or IIC analog to digital converter, but what are the most rational methods (software) to fetch the data from the ADC and pass it to php?

Upvotes: 0

Views: 99

Answers (3)

pino42
pino42

Reputation: 146

Are you going to pick your analog sensors and ADC's of choice? Otherwise there are integrated solutions that can do both jobs for you. One example is on this forum.

Once you have that building block – something that monitors environment data and outputs it on a serial connection – the most rational way would be to write a daemon that every few seconds polls the device, reads the data and records it on your server, perhaps using RRDtool, which has PHP bindings.

In your PHP page you would then simply use rrd_lastupdate() to fetch the current data, or you might want to build something fancier, using the archived data too.

Otherwise, if the server and the sensors are not close by, you might want to use a platform like Arduino to build your own device with sensors, possibly ADC's, an Ethernet port and C/C++ code that speaks HTTP (there are libraries for that) and outputs the current values.

Upvotes: 0

Alexandre Lavoie
Alexandre Lavoie

Reputation: 8771

One way could be to write some C/C++ application that read your ADC and return values to the system out. After, your PHP can use the function http://php.net/manual/en/function.exec.php to run your application and get the output.

Doing data monitoring since 10 years this is not the way I would do it, but this is a simple way to achieve with PHP I think!

Upvotes: 0

symcbean
symcbean

Reputation: 48357

HTTP is all about concurrent access - but the AD converter is constrained to a specific device - meaning you'll need some sort of mutex or queueing mechanism (although queueing is a bad idea for HTTP based apps) to gate access - but a better solution would be to run a cron job or daemon to poll the device and publish the results to a database where the web application can retrieve them (concurrently).

Upvotes: 1

Related Questions