Web Page Interaction "Press to Turn on/off"

4 posts
by eeyore.t.mule » Thu Jun 28, 2012 11:31 am
I'm after a couple of pointers for an idea i've had
I'm gonna be setting my pi up as a web host and one of the pages i've had an idea for is to have a button or buttons to activate a small swich to trigger a pump (This pump would have ist own power supply and would be used to water some of my plants in a green house)
Does anyone have any links to projects like this?
Donkeys like Pi
Posts: 10
Joined: Mon Jun 25, 2012 4:40 pm
Location: Stockport or Barrow
by mr.molez » Thu Jun 28, 2012 11:52 am
its as simple as

if(isset($_POST['submit'])) {
shell_exec("echo 1 > /sys/devices/virtual/gpio/gpio4/value")

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit" value="Click Me">

to turn it on with a button on a website, no need to use other peoples fail-scripts :P
Posts: 3
Joined: Tue Apr 10, 2012 12:17 pm
by cheery » Thu Jun 28, 2012 12:57 pm
You could setup a small web api.

Code: Select all
<p>The pump is <a id="pump" href="#">...</span></p>

Code: Select all
$ ->
    pump = $("#pump")
    currently = false
    toggle = (state) ->
        currently = state
        pump.text("on") if state
        pump.text("off") unless state

    $.getJSON "/api/pump", (state) ->

    pump.click (e) ->
        $.postJSON"/api/pump", !currently, (state) ->

Then have a python script or something which gives response to this /api/pump and that's it. Include the pump indicator markup and the script anywhere where you want to control the pump. If you care about security, you can put up a password for the pump api, either by digest or cookie..
User avatar
Posts: 219
Joined: Wed Jan 25, 2012 9:39 pm
by SteTommo » Thu Jun 28, 2012 2:32 pm
I'm making an add-on board with loads of different inputs and outputs all controlled by really simple php. It may be a little overkill, but you could go on to make it do all sorts of other cool stuff too.


You wouldn't have to worry about building the circuitry to interface with your pump and protect the Pi, just connect the pump to one of the relay outputs, job done.

The code would be something like..


$pio = new Pio;


Posts: 8
Joined: Tue Jun 19, 2012 7:27 pm