Home‎ > ‎

GPIO Control from Dashboard


This option is currently only available for subscribers to the High Availability Service.

Control the GPIO digital pins of multiple Raspberry Pi's from a single online dashboard. You can switch the GPIO pins high/low simply by clicking the tiles shown in Figure 1. Connect your Raspberry Pi GPIO to a relay swicth or a wireless relay to create powerful home automation possibilities.


Figure 1 - Control GPIO output to the Raspberry Pi GPIO


Configuration Steps

1. Create GPIO definition

Click on the GPIO menu option and add a new GPIO definition as shown in Figure 2. The number you use in the "Number" field does not need to correspond to the GPIO number of the Raspberry Pi. This number is simply a unique identifier. Later on you will link this number to the GPIO number of the Raspberry Pi. The Description can be any text. In figure 2 we've used the description GPIO 12 because we will be using this to switch GPIO 12 on the Raspberry Pi. 103 is just a arbitrary number we will use later. 

Figure 2 - Create a GPIO definition

2. Create Location

Click on the Location menu option and add a new Location using the "GPIO" type, as shown in Figure 3.

Figure 3 - Create a Location
3. Install software on your Pi

On your Raspberry Pi:
3.2 Install control.py that came with your High Availability subscription
3.3 Install messaging software:

sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install mosquitto
pip install paho-mqtt

3.4 Edit control.py:

cd /home
sudo nano control.py

Page down top the main() section where you should see the following code:

def main():
global mqttc
global threadstart
global GPIOList
global connected
globals.init()
GPIOList = []
GPIOList.append([103,11])
GPIOList.append([104,12])
InitializeGPIO()

Change the two lines in blue to link the GPIO definition you created in Step 1 to the GPIO pins you want to associate with the Locations. For example if you have three locations and want to link them to GPIO pins 7,11 and 12 then it should look as follows:

def main():
global mqttc
global threadstart
global GPIOList
global connected
globals.init()
GPIOList = []
GPIOList.append([103,7)
GPIOList.append([104,11])
GPIOList.append([105,12])
InitializeGPIO()


Where 103,104 and 105 are the GPIO numbers you assigned in Step 1.

When finished press Ctrl-X followed by y and ENTER to save and exit.


4. Test 

Test it is working by running control.py from the command line:

cd /home
python control.py

Then go to your PrivateEyePi dashboard and click the Control menu option at the top. The status light at the top of the screen will turn green if everything is working and communication is working between the web page you your Raspberry Pi. The status light has three states:

1. Offline - Web page cannot contact the server. 



2. Server online, but Raspberry Pi no communicating. Check control.py is running.


3. Online. OK!


Once it is online the web page will request the status's of each of the GPIO pins on the Raspberry Pi(s). The grey tiles next to the descriptions will turn green (on), red(off) or remain grayed out (in which case re-check step 1-3). 

Click the tiles to switch the GPIO pins on and off. After you click a tile the GPIO pin will switch status and then the Raspberry Pi will send the new state back to the web page and change the color red/green. This gives you a guarantee that you know that the Raspberry Pi has received your command and has responded with the new altered state of the GPIO pin. 

Tip : Connect LED's to the GPIO pins to test whether the GPIO pins are changing when you click the tiles.

5. Automate control.py

Follow the automation tutorial to automate control.py so that it is always running in the background, even if you log off or restart your Pi. There is a new option (not shown in the tutorial) called auto_control in globals.py that must be set to True. 


Comments