I'm not exactly the most knowledgeable on the server-side aspects of how this kind of thing should/would work, but I do tend to pick things up pretty quickly.

I've played around with WebIOPi and a few different scripts running from the pi itself etc, but I was wondering what the steps involved would be to implement a similar kind of thing, but running from an external website.

Essentially, I'd like to be able to control the Pi from any internet connection: run pre-written scripts or just turn pins on/off. I can't seem to find much information on how to do this that starts at a more basic level with some descriptions of WHY you're doing certain things to make stuff work, which is problematic when you're trying to learn.

Just a basic outline of the steps to be implemented would be helpful, but a link or to to descriptions of what they do and why you need them would be amazing.

  • 1
    This is a really a system administration question. First you need something like DynDNS to be able to find your machine on the internet, then to configure the router that connects it to the internet to port forward to (possibly traversing the NAT) a port on the WAN part of the router to the port you want to access on the Raspberry Pi.
    – Marco Poli
    Commented Apr 13, 2014 at 18:39
  • 1
    You could just have the pi poll for updates from the server. This would be the easiest to implement (no port forwarding needed). Just have the server generate a plain text page containing the GPIO pin and the state it wants them to be in (Low or high). Then have the Pi load this file every second or so, and update the pins in accordance the the file received.
    – Gerben
    Commented Apr 13, 2014 at 19:04
  • This seems like an interesting idea. No idea how to do it, but it gives me something to look into. Commented Apr 13, 2014 at 22:48

2 Answers 2


Following Gerben's comment on the question, one way to make that would be implementing a Message Broker and have a client poll for messages from a server with a known and static address (or a DNS entry that follows a dynamic address).

I suggest taking a look at RabbitMQ. There is also a tutorial on how to install it in the Pi. Consider that the server will be in the remote machine, and you will need a client installed in the Pi with the GPIO.

You can find a list of clients for many programing languages in RabbitMQ's devtools page.

  • Will something like this not work with port forwarding as well as your proposed method? (however, I've got stuck where I can't find the config file :/ ) Commented Apr 14, 2014 at 17:29
  • 1
    Yes, it will work. But you will have to configure port forwarding anyway, as this step from the guide you linked shows. This is a specific configuration of your router, but a Pi-related issue.
    – Marco Poli
    Commented Apr 14, 2014 at 18:31

Basically you have to do the following steps:

First you have to be able to access your Pi from any network. To do this, go to any Dynamic DNS Host and register. Services like DynDNS or no-ip provide an internet address for your home router.

Than go to your Routers IP-Adress and see if there is already a build in functionallity for Dynamic DNS. You need to configure this, so you router sends his external IP-Adress to you DynDNS Host. This will make your router accessible. If not, than use software on the pi to send the IP-Adress.

Either set your Pi to an static IP or tell the router in his settings to give the pi an static IP and then forward Ports 80 and 443 to this IP-Adress. With this step you tell the router to forward every incomming traffic on the two ports to the raspberry pi.

Set up an webserver like apache on your Pi in order to provide a webserver funtionality.

There are definitely many ways to access the GPIO pins from a website, one way is:

Write a php script for your website. This is the page you will see when you access your pi.

Within it should be buttons and stuff so you can control something end send it via POST method to the script.

Extract the message and call a python script which will do the actual change on the GPIO.

$command = escapeshellcmd(sudo python /home/pi/path/to/script.py led 1); exec("$command > /dev/null &");

The first line would call the python script located in /home/pi/path/to/ and execute it. The > /dev/null will tell it to put all output into an non-existing file and the & will run it in the background. The last 2 are not really necessary but without it your website will load as long as it takes to execute the python script.

At the moment php could not start python because of the sudo command. It is nessesary because we need the privileges to work with the GPIO Pins. So we need to do: sudo nano /etc/sudoers and at the end add www-data ALL=(ALL) NOPASSWD: ALL

The last step is to write your Python script and work with the input variables you put in via php. I assume you already now how to do that based on your question.

  • Wow. Very comprehensive! Ill be trying this in a few days when i get the time. Commented May 1, 2014 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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