Simple web control with PiFace Digital

Difficulty: easy

Learn how to control your PiFace Digital using an Internet browser from any computer on your local network.

Getting started with simple web control for PiFace Digital

To control your PiFace Digital from a browser, first login into your Raspberry Pi with your PiFace Digital connected, then open a Terminal and enter the command:
python3 /usr/share/doc/python3-pifacedigitalio/examples/simplewebcontrol.py
This will start a simple web server for you to access.

Viewing the PiFace Digital's state

Open a browser on your Pi, or another computer on your network, and enter the following address into the address bar:
http://192.168.1.3:8000

Note: Replace 192.168.1.3 with your Pi's ip address. Hint, it will have been printed out when you started the web server.
The browser will return the state of PiFace Digital's buttons and LEDs. Have a go at holding some of the buttons down while refreshing the address in the browser, the number returned for the input will change.

Writing to PiFace Digital

You can set the output port of PiFace Digital (the LEDs) by adding the following line to the end of the address:
/?output_port=0xaa
So the full command will be:
http://192.168.1.3:8000/?output_port=0xaa

Web command in browser for alternated LEDs
Web command in browser for alternated LEDs

0xaais a representation of the output port values in hexidecimal. The PiFace Digital sees this in the binary form 10101010 with a 1 representing an LED on, and a 0 representing an LED off. 0xff would have all the LEDs turned on, and 0x00 would have them all off.