<< Summary

Drive a relay, in Java Raspberry PI
...and remote control your home's appliances
through HTTP

This project uses the exact same settings as the one mentionned here, but with two appliances.
The software part is a bit different, as it uses an HTTP server.
The interaction with the Raspberry PI, its GPIO header, and as a result the relays connected to it, are done through a web page, hosted on the Raspberry PI itself (a tiny HTTP server...). This small server is in fact just bridging the gap between the HTTP Requests sent by the web client and the GPIO operations driving the relays.
This means that the Raspberry PI - and its network - must be in reach.
This being granted, the reactions are much faster than in the email case. It can be used for any kind of appliance. Lights, AC, garage doors, heaters...

The default http port is 9999. Start the server by using


 Prompt> ./start.server
      
Stop it with a SIGTERM (Ctrl+C).
Then go to the web page by reaching - from a browser:

 http://raspberrypi:9999/web/index.html
      
where raspberrypi is the machine name of the Raspberry PI.
See below what it looks like in the browser of an Android phone or tablet.
When a button is clicked, a JavaScript function is triggered, using Ajax to send a GET request to the server.
As you would see in the code (and in the GUI above), this one is driving two relays, connected on pins GPIO_00 (#17) and GPIO_01 (#18).
Again, the HTTP server, written in Java, is a very tiny piece of code implemented using TCP, and supporting some basics of the HTTP protocol. It is suitable for this project, but should be used with care for bigger projects that would need more HTTP features.

Click to enlarge
Controlling 2 relays over HTTP


Oliv did it