Saturday 11 August 2018

Tawny Owl NestBox Wifi Hotspot - setup the correct way...

Earlier this year I setup a Raspberry Pi v2 minicomputer as a wifi access point to use it as a 'Wifi Hub' so that two nestbox cams based on its smaller WiFi-only sibling, Rasp Pi Zero W could connect to my local network, described in 'Wireless access point bird box', this sort of worked but had issues.

This version is for the 2019 Tawny Owl nest box:
Owlbox 2019... work in progress

I'm trying the new Pi B+ to use as a remote, wifi access hub that will live in the box and allow other nearby/camera-enabled ZeroW's to connect via wifi. The PiB+ wifi hub will double up to stream a webcam & attached Raspi Camera module too.

My first attempt at this (Pi v2 no cameras + 2x Pi zero Ws, 1 camera module each) is all powered by one Power over ethernet (PoE connection).  The Pi B+ is described as having faster wired network (ethernet) connection, so I theorised that it could better act a video streaming hub for several Pi zero Ws.

Why not buy a commercial wifi access point you ask?
  • This build costs the price of a raspberry pi 3B+, case, SD card & power adapter - so not far off buying a commercial Wifi access point.
  • The access point will 'double up' to host/stream video for its own webcam and a RaspPi camera module - show me a commercial wifi access point that can do that...
  • Its more fun than just buying a commercial one.  Really.
  • You can re-task it as an arcade table (I made this one), Media server, Kodi box, weather station, etc, etc

My first attempt at this worked.  Mostly.  The problem was that the method that I used included adding a DHCP server.  Every network has a DHCP server on it somewhere. Domestic networks typically have one running on their Internet service provider-provided modem/router (BT/Virgin/Sky etc).  A DHCP server ' hands out' network addresses (called IP addresses) to local devices connected to the network (e.g. PC/tablet/smart TV).  Think of it as creating a 'map' so that network traffic can be routed between devices.

The presence of a second DHPC server on my Raspberry Pi v2  caused intermittent problems as there were two operating on my network, beavering away and assigning different IP addresses to the same devices.  Annoyingly the device they fought over the most was the TV, so understandably that was not well received.

So, plan B (+)

An upfront disclaimer, most of this method is not mine, and is reproduced from parts of this 'how to' , and credit to its author jamesh (Paspberry pi Foundation).  I re-jigged it a bit to make it flow better and added in my own comments.

The first bit deals with making an a standalone wifi network... which is what I did first without reading it properly....  You actually want to follow the second part of the section that deals with setting it up as an access point to an existing network. 

One common use of the Raspberry Pi is as an access point is to provide wireless connections to a wired Ethernet connection, so that anyone logged into the access point can access the internet, providing of course that the wired Ethernet on the Pi can connect to the internet via some sort of router.
To do this, a 'bridge' needs to put in place between the wireless device and the Ethernet device on the access point Raspberry Pi. This bridge will pass all traffic between the two interfaces.

Use the following to update your Raspbian installation:
sudo apt-get update
sudo apt-get upgrade

Install the following packages to enable the access point setup and bridging:
sudo apt-get install hostapd bridge-utils

Comment: reboot at this point, or the 'add bridge' bit below wont work.
Since the configuration files are not ready yet, turn the new software off as follows:
sudo systemctl stop hostapd

Bridging creates a higher-level construct over the two ports being bridged. It is the bridge that is the network device, so we need to stop the eth0 and wlan0 ports being allocated IP addresses by the DHCP client on the Raspberry Pi.
edit: May want to save a version of this text on the pi's desktop before doing the following as you'll lose the internet temporarily
sudo nano /etc/dhcpcd.conf

Add denyinterfaces wlan0 and denyinterfaces eth0 to the end of the file (but above any other added interface lines) and save the file.

Add a new bridge, which in this case is called br0.
sudo brctl addbr br0

Connect the network ports. In this case, connect eth0 to the bridge br0.
sudo brctl addif br0 eth0

Now the interfaces file needs to be edited to adjust the various devices to work with bridging.
sudo nano /etc/network/interfaces make the following edits.

Add the bridging information at the end of the file.
# Bridge setup
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0

edit the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your wireless network (SSID) and password (wpa_passphrase).
sudo nano /etc/hostapd/hostapd.conf


We now need to tell the system where to find this configuration file.
sudo nano /etc/default/hostapd

Find the line with #DAEMON_CONF, and replace it with this:

Now reboot the Raspberry Pi.
There should now be a functioning bridge between the wireless LAN and the Ethernet connection on the Raspberry Pi, and any device associated with the Raspberry Pi access point will act as if it is connected to the access point's wired Ethernet.

The ifconfig command will show the bridge, which will have been allocated an IP address via the wired Ethernet's DHCP server. 
A few more observations...

Raspberry Pi v2 has no built in wifi so I added a usb wifi dongle to the original version I did.  
The Pi 3B+ has built in Wifi (both have ethernet), so there's no need to add wifi dongle.  My Pi v2 version works fine over Power over Ethernet (PoE).  The version B+ most definitely does NOT, so 2019 Owl Box will need a better power supply (and better power cable) to the top of its tree than the optimistically planned PoE only solution.