Feature #580


Change net config to work like ESP8266 at boot

Added by Hammel almost 5 years ago. Updated about 4 years ago.

Target version:
Start date:
28 Jul 2017
Due date:
% Done:


Estimated time:
01 - Critical


Write to work like ESP8266 where boot mode can set up AP to allow configuration via mobile device.
Handles both Internet wifi setup and sensor network AP config.

    if (pair_button)
        enable ap only
        enable wifi config in web server
        enable ap
        enable internet wifi connection
        disable wifi config in web server


IMG_20180318_165735.jpg (1.19 MB) IMG_20180318_165735.jpg PAIR LED lit on boot Hammel, 18 Mar 2018 17:00
Actions #1

Updated by Hammel almost 5 years ago

  • Project changed from Sensors to Monitor
  • Category deleted (Software)
Actions #2

Updated by Hammel almost 5 years ago

  • Category set to Software
  • Priority changed from Normal to Immediate
  • Severity changed from 03 - Medium to 01 - Critical
Actions #3

Updated by Hammel almost 5 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10
This requires:
  1. Modified S40network script at boot time.
  2. Modified version of piboxwww.
  3. Modified network config UI to allow both AP AND wifi config.

Modified S40network script

This should replace the S40network script in the core. It works like this.
  • If pair_button enabled
    • enable AP in configuration mode. This is a default configuration that allows user to quickly connect with a mobile device without having to know the monitor's configuration.
    • enable mobile wifi config mode. This is a REST interface in the web server that the mobile app can use to configure the AP and the monitor's wifi internet connection.
    • The boot script only sets a file stamp so the www environment knows that the modes are enabled.
  • else
    • Disable AP configuration mode.
    • If configured, bring up AP sensor mode.
    • If configured, bring up wifi internet connection.

Modified piboxwww

This provides the REST interface for mobile app configuration of the AP and wifi internet connection for the monitor. It must check that the appropriate mode (pair mode) is set by the boot process or else this REST interface will be disabled.

AP AND wifi config

The default network configuration utility is very klunky. The web UI needs to come out in favor of the REST interface, leaving the remote side to supply the UI. A new web UI could be created that simply calls that REST API, thereby reusing the API with UI's in either the mobile app or in the web UI.

This is also a modification to piboxwww.


  1. Ironman core package needs a modified S40network script. It also needs a default AP configuration to use when the pair button is pressed at boot time.
  2. piboxwww needs to fork to ironmanwww and be modified as described.
Actions #4

Updated by Hammel almost 5 years ago

Modification to the network init script required the following specifically to support PAIR mode.
  1. Custom interfaces file
  2. Custom hostapd* files
  3. Custom dhcpd file

These have been added to the monitor core package.

Actions #5

Updated by Hammel almost 5 years ago

  • % Done changed from 10 to 20

I've got a mostly working Pair Mode UI created in imwww, ported from piboxwww. I'm actually able to test the web server right from the source on my desktop and run piboxd there too, in test mode (-T). I found that when I did this the API for the web server doesn't support the now-required base-address for the AP, which had been added to the native UI (pibox-network-config). In other words, piboxwww is broken when setting hostap because it doesn't support specification of the base address.

So now I need to
  1. Add support in piboxd:net.c:_setAP_() for a new field in the inbound message that specifies the base-address. This means specifying the format of the message in the comment block and then using the defined field names from piboxnet/pnc.h instead of just assuming the "idx" just increments when calling pncSetHostAPField().
  2. Add support to settings-write.php:saveAccessPoint() to accept the base address in the inbound POST body for normal (non-pair) mode.
  3. Add support to settings-write.php:saveAccessPoint() to hard code the base address so users don't have to set it themselves.

After I fix this I'll need to fix piboxwww too.


I've updated piboxwww with the relevant changes made to imwww, such as the init class, log class use of init class, base address support in AP configuration, etc.

Actions #6

Updated by Hammel almost 5 years ago

The AP setting is mostly done. Now pncSaveHostAP() in pnc:save.c needs to use the interface field provided instead of hard coding "wlan0" when saving the interface configuration to /etc/network/interfaces (or the test equivalent). It should also create the interface if it isn't found in the list of existing interfaces. Note that in IronMan the interface (uap0) will be in the default interfaces file so it shouldn't fail to find the named interface (which is hard coded in the settings-save.php file as uap0).

Actions #7

Updated by Hammel almost 5 years ago

I ran into a problem today in testing setting up an AP on the same physical phy as the wifi client. Turns out the RTL8188 dongle I got from Amazon doesn't support doing both at the same time. You can tell this if you run iw list. You'll see something like this on devices that support both.

        valid interface combinations:
                 * #{ AP, mesh point } <= 8,
                   total <= 8, #channels <= 1

or maybe this (from the Arch Wiki)

        valid interface combinations:
                 * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,
                   total <= 2048, #channels <= 1, STA/AP BI must match

But on devices that don't support both you you see something like this.

        interface combinations are not supported

Switching to a Panda Wireless dongle allowed me to setup a virtual interface for use as an AP. But note that because of this setting

#channels <= 1

I am limited to using the same channel for the AP as I use for the wifi client. Not a horrible thing, unless you have lots of IoT devices that will report to the monitor frequently. But it does mean that if I need to check the Wifi hat I intend to use to make sure it supports both types simultaneously and whether or not it supports more than one channel. If it doesn't support both then I can't use it. If it doesn't support more than one channel then I need to remove the channel selection from the web UI net configuration for the sensor network as it will have to use whatever channel the wifi is on. The only way I'll be able to do that is bring up the wifi, find it's channel, and modify the hostap config at boot time. Unless hostapd supports dynamic channel selection based on the wifi channel.


I can find the channel used for the wifi with this command:

iwlist wlan0 channel | grep "Current Frequency" 

I then parse out the channel number from that output. Now I just have to figure out how to use that at boot time to set the channel in the hostapd.conf, probably with sed or similar.

Actions #8

Updated by Hammel almost 5 years ago

  • % Done changed from 20 to 50

It looks like everything is working under test. I've added a reboot option that will allow the user to reboot on demand after configuring the network.

The S40network modification sets


if we're in pair mode. This is only for use by the WWW but it turns out that the UI code can check the gpio pin on its own. So we don't need this stamp file. However, without the user is required to hold the pair button down while they work. So it's probably better to change the init class in the PHP to check for the stamp file, and then clean it up when reboot is selected. That way the user only has to hold the pair button while the monitor boots, but then can release it to use their mobile device to do the configuration.

Note that this implementation does not use a REST API. It's completely implemented in the PHP/JS code, just as it was for piboxwww. This is a better solution because I really don't want remote users being able to make these changes - only someone who is standing next to the device and holding in the pair button.

What's left?
  1. Testing the code on hardware. I'll need to implement the pair button hardware.
  2. Testing the code with the Wifi hat. I need to investigate that it will run in both AP and client mode at the same time.
  3. Fix the S40network script to update the channel field in hostapd.conf based on the channel being used by the wifi client. This won't be necessary if the wifi hat allows multiple channels in combined mode but is necessary if the hat only supports 1 channel in combined AP/client mode.
Actions #9

Updated by Hammel about 4 years ago

The project has changed a little bit. I've found that the Pi Zero doesn't have enough juice to run the UI, so I'm using a Pi 3 on a Pi 7" display as the monitor/server.

The code for getting the network config via an AP at boot time is implemented as is a simple hardware setup on a breadboard. When the slide switch is on the system boots into PAIR mode. When it is off it runs normally. I've attached a picture with the PAIR led lit.

This means this issue can be closed, although the feature does not work quite right just yet. I'll open bugs against the implementation to track them separately.

Closing issue.


Also available in: Atom PDF