Saturday, October 12, 2013

Controlling My Pi from the Internet

Back in post 28, I described my method for getting data from my Pi to its web page. That's been working for a few weeks now.

A few days back I added a FORM SUBMIT button that can control how the Pi operates. The new feature is at the bottom of The button is labeled "LED On!".

When that button is clicked PHP code in that page writes a particular value into a data file on that server.

Once per minute the Pi reads that same file -- like so:

while true
  a=`curl --silent --netrc -R ftp://ftp.???.com/data/led`
  if [ "$a" = 'ON' ] ;
   curl --silent --netrc -T web/null ftp://ftp.???.com/data/led
   sudo python web/
  sleep 60

So IF the file named "led" has the magic value "ON" THEN that file is erased AND the associated LED is turned on for 20 seconds. 

Note that the way I did this is rather inefficient -- but it works. If I can turn an LED on then I can control anything else the Pi is connected to -- e.g.:

lights, fans, thermostat, irrigation valves, ...

Of course, I'd have add some security to the web interface.

No comments:

Post a Comment