Last week I posted a vine video of one of the cool raspberry pi features I just got working for cBAM and a few people asked for more details about how I did it e.t.c. The short answer is ‘I used the fantastic PiUi plugin provided by David Singleton’ the long answer is the short answer plus lots of swearing at slightly inaccurate how-to guides. So I thought a quick combined write up of these guides might also help anyone else Googling around for solutions.

Things you will need

RaspberryPi (+monitor, keyboard, mouse, operating system, power supply, power, a surface to put it on, a roof to keep water off, etc..)

The internet

Some kind of other internet linked device

Step 1: Set up connection

So the first step in using PiUi is making sure that you can login to Raspberry Pi from another device. All you need to do is setup the Raspberry Pi so that it is broadcasting a wi-fi network you can log into. That one simple sentence belies how difficult that actually is to do. Thankfully the process is made a little simpler by the existence of a module called Pi-Point which handles most of the details. Unfortunately the documentation for pi-point is a little patchy and hilariously the ‘Online docs‘ and the ‘Docs in PDF format‘ don’t actually contain all the same instructions. So to speed this up I’ve reproduced a combination of them in the steps below – if you have any problems please go read both of them as they contain more details.

Update your Pi libraries with (all commands are in the LXTerminal) sudo apt-update

Restart the Raspberry Pi using the command sudo reboot or just unplugging it and plugging it back in again (the first method is considered a bit more technical than the second)

Edit the hostap config file with sudo nano /etc/hostapd/hostapd.conf this may be blank but make sure it has the following contents (you can save with Ctrl+O);interface=wlan0driver=nl80211ssid=Testy-fihw_mode=gchannel=1ignore_broadcast_ssid=0wpa=2wpa_passphrase=supergoodpasswordwpa_key_mgmt=WPA-PSKwpa_pairwise=TKIP CCMPrsn_pairwise=TKIP CCMP

Restart hostapd with the command sudo service hostapd restart following this you should be able to see your new wi-fi network being broadcast on other devices

Edit the dnsmasq config file with sudo nano /etc/dnsmasq.conf this is a really really long file with 99% of it commented out (has a # at the start) but you need to look for these lines, un-comment them (delete the #) and make sure their values match up to the list below.domain-needed
interface=wlan0
dhcp-range=192.168.1.5,192.168.1.254,254.255.255.255.0,12h

Restart hostapd with the command sudo service dnsmasq restart this will now let you log into the network and you should now be assigned a proper IP address.

You should now be able to start the Raspberry Pi and immediately log into the wi-fi network it is broadcasting. If not, then keep randomly changing things until it works 🙂

Step 2: SetUp PiUi

PiUi is a python based set of packages that essentially sets up a webpage with a range of controls that feedback to the Raspberry Pi. The read-me file for PiUi is pretty good and available here. However, for the sake of keeping everything together, I have also produced a quick-start step by step guide below.

Add mapping for PiUi to the hosts file load up in the nano editor with sudo nano /etc/hosts and add the line192.168.1.1 piui

Install the nginx package with the command sudo apt-get install nginx

Get the PiUi code from github with sudo git clone https://github.com/dps/piui.git

Copy the nginx file to from the PiUi code to the config directory with sudo cp /home/pi/piui/nginx-conf/nginx.conf /etc/nginx/

Run the PiUI setup script which installs any other required files with the command sudo python piui/setup.py install [Thanks to Adam for pointing out this additional step 24/07/13]

Reboot Raspberry Pi

Run the demo in the PiUi directory with python /piui/piui_demo.py

Using any device with a browser login to the wi-fi network broadcast by the Raspberry Pi and go to the 192.168.1.1

Enjoy god like Raspberry Pi powers at your finger tips!

Step 3: Make it dance

Now we’ve got it up and running the last step is to modify the code to run other scripts. This is pretty basic python stuff and depends on what you want to link it to. However, the following steps are a good place to start playing around for anyone a little un-sure of how to use it.

Using an editor load up the piui_demo.py code on the Raspberry Pi. This can either be done using Geany or using the nano editor we used before with the command sudo nano /piui/piui_demo.py

This file will be pretty long and full of def functions but the one you want to start playing with is def onupclick and def ondownclick these are the commands associated with the ‘Buttons’ page in the demo

You can then modify these commands by adding in your own lines of code which will run every time you press these buttons. The simplest way to get these buttons to run code is to have it call other pre-prepared python scripts. You can do these several ways but a very reliable way is to use the call function.

First add the line from subprocess import call to the very top of the piui_demo.py file with all the other import commands

In the def function (either up or down it doesn’t matter) add the linecall (["sudo python /home....location and name of your python file"],shell=True)
filling in the name and location of the python file you want to call

Now when you run the piui_demo.py file as at the end of step 2 pressing you chosen button in the browser will now execute the python file you’ve setup.

I hope this is of some help to anyone wanting to repeat what I’ve managed to do. If you have any problems, just post them in the comments section and I’ll do my best to answer them. then good luck fixing them, it’s been years and I’ve forgotten how all this works.

Like this:

Related

13 thoughts on “How to: use PiUi”

I am really interested in using the PIUI app to connect to the raspberry Pi for a project for university but i am fairly new to using the Raspberry Pi. I tried your step 1 and tried playing around with it but i cant seem to get the access point working or showing up on my phone. Are there any tips you can tell me about what i can do to get it to work. also i couln’t get iw installed could that have anything to do with it??:?

Hey there followed ur steps (with a few changes) and got my raspi to be an woreless AP and got the app on my phone to connect to the raspberry pi but stuck on step2.6. i keep getting an error message and cant figure out why the file wont open even if its there.

I’m having the same problem as “Mel” above. Got to step 1.6 and cannot see the SSID being broadcast. Any ideas?

Thanks to the author for the tutorial. Some corrections/additions:
1. Step 1.2.D has a misspelling “sudo apt-get install hastap-utils” should be “sudo apt-get install hostap-utils”.
2. Step 1.3 and 1.5 require the user to type “CTRL-O” to save what they edited before closing. That was not in the bottom menu and could be useful to others.

Drop it out the window?
Hit it with a hammer?
Pour a glass of water on it?

In all seriousness, this article is 2.5 years old I can’t remember any more. Also I note that PiUi development seems to have stopped about 3 years ago so I’m not even sure PiUi is supported anymore. Sorry I can’t be more help.