A Node application which makes connecting your RaspberryPi to your home wifi easier
When unable to connect to a wifi network, this service will turn the RPI into a wireless AP. This allows us to connect to it via a phone or other device and configure our home wifi network (for example).
Once configured, it prompts the PI to reboot with the appropriate wifi credentials. If this process fails, it immediately re-enables the PI as an AP which can be configurable again.
This project broadly follows these instructions in setting up a RaspberryPi as a wireless AP.
The NodeJS modules required are pretty much just underscore
, async
, and express
.
The web application requires angular
and font-awesome
to render correctly. To make the deployment of this easy, one of the other requirements is bower
.
If you do not have node js
installed already, there are special instructions for doing so on the Pi Zero W. These instructions are from https://blog.miniarray.com/installing-node-js-on-a-raspberry-pi-zero-21a1522db2bb.
We need an earlier version of node (v4.2.4) built specifically for armv6l:
cd ~
wget http://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-armv6l.tar.gz
cd /usr/local
sudo tar xzvf ~/node-v4.2.4-linux-armv6l.tar.gz --strip=1
sudo apt-get remove --purge npm node nodejs
Verify the install with node -v
Then upgrade npm with sudo npm install -g npm
If you do not have bower
installed already, you can install it globally by running: sudo npm install bower -g
.
Bower might take a very long time to complete install on Pi Zero.
$git clone https://github.com/WilliamLiska/raspberry-wifi-conf.git
$sudo chown -R mumble ./raspberry-wifi-conf
$cd raspberry-wifi-conf
$npm update
$su mumble
$bower install
$exit
$sudo npm run-script provision
$sudo npm start
There is a startup script included to make the server starting and stopping easier. Do remember that the application is assumed to be installed under /home/pi/raspberry-wifi-conf
. Feel free to change this in the assets/init.d/raspberry-wifi-conf
file.
$sudo cp assets/init.d/raspberry-wifi-conf /etc/init.d/raspberry-wifi-conf
$sudo chmod +x /etc/init.d/raspberry-wifi-conf
$sudo update-rc.d raspberry-wifi-conf defaults
The script can be executed with the ForceChange
parameter to force the Pi to switch to AP mode, allowing you to select a new network. Works well in coordination with https://github.com/WilliamLiska/supertalkie-buttons.
The hostapd
application does not like to behave itself on some wifi adapters (RTL8192CU et al). This link does a good job explaining the issue and the remedy: Edimax Wifi Issues. The gist of what you need to do is as follows:
# run iw to detect if you have a rtl871xdrv or nl80211 driver
$iw list
If the above says nl80211 not found.
it means you are running the rtl871xdrv
driver and probably need to update the hostapd
binary as follows:
$cd raspberry-wifi-conf
$sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.OLD
$sudo mv assets/bin/hostapd.rtl871xdrv /usr/sbin/hostapd
$sudo chmod 755 /usr/sbin/hostapd
Note that the wifi_driver_type
config variable is defaulted to the nl80211
driver. However, if iw list
fails on the app startup, it will automatically set the driver type of rtl871xdrv
. Remember that even though you do not need to update the config / default value - you will need to use the updated hostapd
binary bundled with this app.
TODO: Automatically maintain the correct version of hostapd
based on the wifi_driver_type
.
This is approximately what occurs when we run this app:
- Check to see if we are connected to a wifi AP
- If connected to a wifi, do nothing -> exit
- (if not wifi, then) Convert RPI to act as an AP (with a configurable SSID)
- Host a lightweight HTTP server which allows for the user to connect and configure the RPIs wifi connection. The interfaces exposed are RESTy so other applications can similarly implement their own UIs around the data returned.
- Once the RPI is successfully configured, reset it to act as a wifi device (not AP anymore), and setup it's wifi network based on what the user selected.
- At this stage, the RPI is named, and has a valid wifi connection which it is now bound to.
Typically, I have the following line in my /etc/rc.local
file:
cd /home/pi/raspberry-wifi-conf
sudo /usr/bin/node server.js
Note that this is run in a blocking fashion, in that this script will have to exit before we can proceed with others defined in rc.local
. This way I can guarantee that other services which might rely on wifi will have said connection before being run. If this is not the case for you, and you just want this to run (if needed) in the background, then you can do:
cd /home/pi/raspberry-wifi-conf
sudo /usr/bin/node server.js < /dev/null &
In my config file, I have set up the static ip for my PI when in AP mode to 192.168.44.1
and the AP's broadcast SSID to rpi-config-ap
. These are images captured from my osx dev box.
Step 1: Power on Pi which runs this app on startup (assume it is not configured for a wifi connection). Once it boots up, you will see rpi-config-ap
among the wifi connections. The password is configured in config.json.
Step 2: Join the above network, and navigate to the static IP and port we set in config.json (http://192.168.44.1:88
), you will see:
Step 3: Select your home (or whatever) network, punch in the wifi passcode if any, and click Submit
. You are done! Your Pi is now on your home wifi!!
TODO
- Automate the deployment of alternate
hostapd
application - Automate provisioning of the application dependencies
- Make the running of scripts cleaner and more easy to read
- ifup should never be allowed to fail... same w/ the "start" pieces of various services. Perhaps we need to tease the restart into stop and start and allow the stop to fail.
- Add tests
- Add travis ci / coveralls hook(s)