my-wifi-setup

This repo is an Express server that handles the first-time setup required to get the device working.

Since the device is not on the local wifi network when it is first turned on, the device broadcasts its own wifi access point and runs the server on that. The user then connects their phone or laptop to that wifi network and uses a web browser (not a native app!) to connect to the device at the URL my.adblockradio.com. The user can select then their home wifi network and enter the password on a web page and transfer it to the web server running on the device. At this point, the device can turn off its private network and connect to the internet using the credentials the user provided.

The code is Linux-specific, depends on systemd, and has so far only been tested on a Raspberry Pi 3. It requires hostapd and dnsmasq to be installed and properly configured. Here are the steps I followed to configure and run this server. Note that the steps include instructions for Raspberry Pi.

If you intend to modify this code and need to test your changes in a real device, please refer to: https://github.com/mozilla-iot/gateway-wifi-setup/wiki/Testing-on-WoT-Base-Image

Step 1: clone and install

First, clone this repo and download its dependencies from npm:

$ git clone https://github.com/adblockradio/my-wifi-setup
$ cd my-wifi-setup
$ npm install

Step 2: AP mode setup

Install software we need to host an access point, but make sure it does not run by default each time we boot. For Raspberry Pi, we need to do:

$ sudo apt-get install hostapd
$ sudo apt-get install dnsmasq
$ sudo systemctl disable hostapd
$ sudo systemctl disable dnsmasq

Step 3: configuration files

Next, configure the software:

  • Edit /etc/default/hostapd to add the line:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
  • Copy config/hostapd.conf to /etc/hostapd/hostapd.conf. This config file defines the access point name "MyAdblockRadio". Edit it if you want to use a different name.

  • Copy config/dnsmasq.conf to /etc/dnsmasq.conf.

Step 4: run the server

If you have a keyboard and monitor hooked up to your device, or have a serial connection to the device, then you can try out the server at this point:

sudo node index.js

If you want to run the server on a device that has no network connection and no keyboard or monitor, you probably want to set it up to run automatically when the device boots up. To do this, copy config/my-wifi-setup.service to /lib/systemd/system, edit it to set the correct paths for node and for the server code, and then enable the service with systemd:

$ sudo cp config/my-wifi-setup.service /lib/systemd/system
$ sudo vi /lib/systemd/system/my-wifi-setup.service
$ sudo systemctl enable my-wifi-setup

At this point, the server will run each time you reboot. If you want to run it manually without rebooting, do this:

$ sudo systemctl start my-wifi-setup

Any output from the server is sent to the systemd journal, and you can review it with:

$ sudo journalctl -u my-wifi-setup

Add the -b option to the line above if you just want to view output from the current boot. Add -f if you want to watch the output live as you interact with the server.

If you want these journals to persist across reboots (you probably do) then ensure that the /var/log/journal/ directory exists:

$ sudo mkdir /var/log/journal
S
Description
Initial WiFi setup for connected devices
Readme MPL-2.0 6.7 MiB
Languages
JavaScript 59.3%
Handlebars 36.6%
Python 3.8%
Shell 0.3%