Secure Data Sharing: Raspberry Pi WiFi PirateBox

Create Your Own Local WiFi Hotspot

Raspberry Pi WiFi PirateBox By tjgamer1987

Assembly Time: 2-3 hours
Difficulty: Intermediate

This electronics project creates a Raspberry Pi PirateBox that can be operated as a local Wi-Fi hotspot, separate from the internet with its own Wi-Fi network where you can store files, share digital content, chat and other things all anonymously.

Required Tools and components:

(1) NPN Optoisolator
(1) Heat Shrink Tubing
(1) Rocker Switch
(1) USB Connector
(1) Enclosure
(1) Prototyping Board
(1) Red Hook Up Wire
(1) USB 2.0 Cable
(10) 47Ω Resistors, 1/4 Watt, 5%
(10) 120Ω Resistors, 1/4 Watt, 5%
(10) 470Ω Resistors, 1/4 Watt, 5%
(10) Green LEDs
(1) USB-A to Micro-B cable
(1) Jumper Wire Kit

Raspberry Pi Model B+
Wi-Fi USB adapter
16GB microSD (Recommended: Sandisk Ultra)
2-12W USB Power Adapter (Recommended: 12 Watt Slim Wall-Mount USB Power Adapter)
Pirate Box enclosure (Optional, as seen in picture), this kit includes an enclosure.
Soldering iron and solder
Heat gun
Wire strippers
Drill & Bits
Building the Circuit

Building the Circuit

Solder the 120Ω resistor on the board along with the three 47Ω resistors, USB connector and three LEDs. Now solder the negative side of the LEDs to each of the 47Ω resistors and solder the positive sides of the LEDs to the 5V pin of the USB Connector.

Place and solder the NPN Optoisolator on the board and solder the bottom of the 120Ω resistor to pin one of the Optoisolator and the top of the 120Ω resistor to a jumper wire.

Lastly, solder a hookup wire to pin 2 of the Optoisolator, solder pin 3 to the ground pin of the USB connector and solder pin 4 to the 47Ω resistor group and then solder them all together. See Fig. 1.

Wiring the Switch

Cut four lengths of heat shrink tubing as shown in Fig. 2. Get four jumper wires, one red, one black and two of the same, but different color. Cut off the male ends of the jumper wires, strip the ends off the wires then slide the heat shrink tubing onto the wires.

Solder the 470Ω resistor to the positive terminal then solder a wire (preferably red) to the resistor and cut off the excess wire on the resistor. Attach and solder a black wire to the negative terminal and attach and solder the remaining wires to the remaining terminals.

Slide the heat shrink tubing over the resistor and over the exposed wires soldered to the terminals then take your heat gun, lighter, or match to shrink the tubing.

Wiring the Switch

Preparing the Raspberry Pi

Load Raspbian onto the SD card. Info on how to write Raspbian on the SD Card is on the Raspberry Pi website. Insert the SD card with the Raspbian image to the slot on the Raspberry Pi.

Connect the Raspberry Pi to a monitor. Make sure to have a USB Keyboard and mouse, LAN with access to the internet, and to a 5 volt USB power adapter. Boot the Raspberry Pi and perform first time configuration. When configuring Raspbian, do not configure the graphical user interface to start automatically, and it is a good idea to change the password for the Raspberry Pi at this time.

The next step will be used to install and configure the PirateBox software. Boot the Raspberry Pi again and log in. Issue the following commands:

sudo apt-get update
sudo apt-get -y install lighttpd
sudo /etc/init.d/lighttpd stop
sudo update-rc.d lighttpd remove
sudo apt-get -y install dnsmasq
sudo /etc/init.d/dnsmasq stop
sudo update-rc.d dnsmasq remove
sudo apt-get -y install hostapd
sudo /etc/init.d/hostapd stop
sudo update-rc.d hostapd remove
sudo apt-get -y install iw
wget "https://s3-us-west-1.amazonaws.com/talk2bruce/instructables/piratebox/piratebox-ws_current.tar.gz"
tar xzf piratebox-ws_current.tar.gz
cd piratebox
sudo mkdir -p /opt
sudo cp -rv piratebox /opt
sudo ln -s /opt/piratebox/init.d/piratebox /etc/init.d/piratebox
sudo update-rc.d piratebox defaults
sudo /etc/init.d/piratebox start

There will be an error message after the last command that indicates that the network interface could not be started: this error occurs because the Wi-Fi USB adapter is not plugged in. This error is OK at this point - it will not adversely affect the PirateBox. It will work correctly when the Raspberry Pi is rebooted with the Wi-Fi adapter plugged in.

Install the Python program that will illuminate the LEDs when the Wi-Fi is up and running and to install the Python program that will shut down the Raspberry Pi when the push button is pressed. Create the directory where the Python programs will reside by issuing the following commands at the command prompt:

cd /home/pi
mkdir python_programs
cd python_programs

Issue the following two commands to get the Python programs:

wget "https://s3-us-west-1.amazonaws.com/talk2bruce/instructables/piratebox/rpi_halt_btn.py"
wget "https://s3-us-west-1.amazonaws.com/talk2bruce/instructables/piratebox/illuminate_leds.py"

Using a text editor, edit the "/etc/rc.local" file and add the line below to the bottom of the file before the line with "exit 0". Since "/etc/rc.local" is a system file you will need to use the sudo command when you start your editor - for example "sudo nano /etc/rc.local". The line of code you are adding will automatically start the Python program that monitors the shutdown button. Make sure to put the ampersand ("&") at the end of the line.

python /home/pi/python_programs/rpi_halt_btn.py&

Lastly, use sudo and a text editor to edit "/etc/network/interfaces" to make the contents look like exactly like this:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
#allow-hotplug wlan0
iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
post-up python /home/pi/python_programs/illuminate_leds.py

The last line runs the Python program that illuminates the blue LEDs when the WiFi is up and running.

Shut down the Raspberry Pi using the command:

sudo halt

Remove all the cables

Wiring the SPIO Pins

Wiring the SPIO Pins on the Raspberry Pi B+

Connect the wires from the LED circuit board to the GPIO pins of the Raspberry Pi (Fig. 3). The hookup pin from the 120Ω resistor on the circuit board will go to pin 1 and the other hookup wire from pin 2 of the Optocoupler to pin 16. A Python program running on the Raspberry Pi will use these GPIO pins to illuminate the LEDs when the Wi-Fi is up and running.

Next, connect the red and black wires from the switch to the GPIO pins. The red wire to pin 17 and the black wire to pin 5. These wires will provide power to the LED in the push button switch. The LED illuminates when the Raspberry Pi is powered on.

Mounting Into Enclosure Lastly, connect the blue and green wires from the switch to the GPIO pins (Fig. 4). The green wire to pin 22 and the blue wire to pin 23. These GPIO pins will be monitored by a Python program in the Raspberry Pi: when the button is pressed, the program will issue a "halt" command to shut down the Raspberry Pi.

Mounting the RPi, LED Circuit Board and Switch into Enclosure

The RPi and the LED Circuit Board will be mounted inside the case. First, drill two holes on one side of the enclosure and make one of the holes big enough for the USB and Ethernet ports of the RPI, the other should be just the right size for the push button. Drill two more holes on the other side across from the holes you just made, these will be for the USB Connector of the board and the 5V input of the RPi. USB Power Cables

Place the RPi inside the enclosure and make sure the ports are out of the hole. Place the LED board inside as well in the middle of the enclosure and with the USB Connector vertical to one of the holes on the other side of the case. Lastly, install the shutdown switch through the hole next to the hole where the USB and Ethernet ports of the RPI are through.

Installing the USB Power Cables

Insert the USB cables through the side holes you drilled out. Attach the USB cables to the RPi and the LED circuit board. To save space, you may want to clamp the power cables together with a tie (Fig. 5).

Attaching the WiFi Antenna and Test

Attaching the WiFi Antenna First, in one of the RPi USB ports, attach the WiFi adapter antenna (Fig. 6). Plug both of the USB cables into the USB power adapters and plug the adapters into an outlet strip or into wall outlets, the shutdown switch should illuminate. After a few minutes, the LEDs should illuminate as well. This indicates that the WiFi is up and running on the RPi. Wait a minute to be sure the PirateBox software is up and running.

Connect to the PirateBox software using a laptop or tablet and doing as followed: Go into your wireless settings on the laptop or tablet and connect to the SSID named "PirateBox - Share Freely". When connected, open a web browser and go to "http://192.168.77.1". You should see the PirateBox home page.

Press the shutdown switch and after a minute or two, the LEDs should turn off which will indicate that the Raspberry Pi has shutdown and it's safe to remove the power.

Lastly, unplug the power adapters from the outlets. The LED in the shutdown switch should turn off.
If you have an electronics story or project you'd like to share, please email [email protected].