3

I have a Pi set up with Apache and wiringpi, and I would like to read the state of an in pin (every 20 seconds, if possible) and display it on my webpage using PHP. The input is to determine if my computer is on or off remotely.

So basically, I want to store the output of a system(gpio -g read 7) command into a variable ($status) and then print it on the page like so:

Your computer is currently: $status.

Where $status can be either on or off depending on if the read command comes back as a 1 or 0.

I can post what code I already have, but right now it just sends a power toggle out of a GPIO out pin.

Any help is appreciated! Thanks.

  • I'd suggest that your web page makes a REST call back to a back-end application running on the Pi. For example a node.js/express app. This could then inquire the data values you want and return it as a JSON encoded set of data. Your web page could then interrogate that data and dynamically update the page without any page reloads. I don't know of any pre-canned code to do that but the complexity doesn't sound high if one can program web pages, Node.js and the wiring-pi npm library. – Kolban Jul 21 '16 at 5:28
1

If one googles this phrase "raspberry pi gpio web interface" and switches to images mode, we can see that there appear to be quite a number of pre-existing solutions and samples. For example:

http://hackaday.com/2013/02/02/easy-web-interface-with-gpio-access-runs-on-raspberry-pi/

https://www.raspberrypi.org/forums/viewtopic.php?t=15257

http://www.cupidcontrols.com/2014/04/raspberry-pi-cupid-webio-javascriptjquery-apache-python/

and quite a few others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.