Feature #580

Change net config to work like ESP8266 at boot

Added by Hammel 11 months ago. Updated 3 months ago.

Status:ClosedStart date:28 Jul 2017
Priority:ImmediateDue date:
Assignee:Hammel% Done:

100%

Category:Software
Target version:Iron Man - 002 - MVP
Severity:01 - Critical

Description

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
    }
    else
    {   
        enable ap
        enable internet wifi connection
        disable wifi config in web server
    }

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

111

Associated revisions

Revision 992b295e
Added by Hammel 11 months ago

RM #580: Initial import of build system for IronMan core updates package.

Revision 992b295e
Added by Hammel 11 months ago

RM #580: Initial import of build system for IronMan core updates package.

Revision 031cdf6f
Added by Hammel 11 months ago

RM #580: New files supporting booting into default AP mode for configuring networking via a mobile device (ala ESP8266) when PAIR Button is pressed. Returns to normal networking on subsequent boot as long as button is released.

Revision 031cdf6f
Added by Hammel 11 months ago

RM #580: New files supporting booting into default AP mode for configuring networking via a mobile device (ala ESP8266) when PAIR Button is pressed. Returns to normal networking on subsequent boot as long as button is released.

Revision 7788af68
Added by Hammel 11 months ago

RM #580: Initial import of IronMan web services. This is just a basic port from PiBox Media Server but slightly
modified to allow easier testing from directly within the source tree.

Revision 7788af68
Added by Hammel 11 months ago

RM #580: Initial import of IronMan web services. This is just a basic port from PiBox Media Server but slightly
modified to allow easier testing from directly within the source tree.

Revision f6287368
Added by Hammel 11 months ago

RM #580: Ignore data directory created by test scripts. Update runserver.sh test script to support getopt, creating data directory and cleaning up of data directory on web server exit.

Revision f6287368
Added by Hammel 11 months ago

RM #580: Ignore data directory created by test scripts. Update runserver.sh test script to support getopt, creating data directory and cleaning up of data directory on web server exit.

Revision 633b5e9b
Added by Hammel 11 months ago

RM #580: Implemented initial version of pair mode network configuration page. Cleaned up CSS a bit so block elements don't have so much white space between them.

Revision 633b5e9b
Added by Hammel 11 months ago

RM #580: Implemented initial version of pair mode network configuration page. Cleaned up CSS a bit so block elements don't have so much white space between them.

Revision cd58dfa7
Added by Hammel 11 months ago

RM #580: Clean up handling of AP submission. This includes splitting the old settings.php into multiple files to make it easier find the
functions that need updating. Dropped macfields.tmpl because IronMan won't allow setting MAC addresses manually.

Revision cd58dfa7
Added by Hammel 11 months ago

RM #580: Clean up handling of AP submission. This includes splitting the old settings.php into multiple files to make it easier find the
functions that need updating. Dropped macfields.tmpl because IronMan won't allow setting MAC addresses manually.

Revision fdf50ec3
Added by Hammel 11 months ago

RM #580: Added uap0 to network/interfaces test file.

Revision 76e05faa
Added by Hammel 11 months ago

RM #580: Load the network device names and the network interfaces file before continuing in saveAP().

Revision 9423f9e2
Added by Hammel 11 months ago

RM #580: Check socket return code and exit gracefully on error.

Revision 9423f9e2
Added by Hammel 11 months ago

RM #580: Check socket return code and exit gracefully on error.

Revision 6442db78
Added by Hammel 11 months ago

RM #580: Change "errMsg" to "$errMsg" so error message is properly printed in javascript dialog.

Revision 6442db78
Added by Hammel 11 months ago

RM #580: Change "errMsg" to "$errMsg" so error message is properly printed in javascript dialog.

Revision 1e879f80
Added by Hammel 11 months ago

RM #580: Fix setWireless to write out the correct fields instead of just iterating over them and assuming inbound
data was in the specified order.

Revision 75addbce
Added by Hammel 11 months ago

RM #580: Add support for a new message type, MT_SYS with a single action, MA_REBOOT. This allows the web UI to request a system reboot via piboxd.

Revision 305432a7
Added by Hammel 11 months ago

RM #580: remove test code that forced us into Pair Mode processing.

Revision 305432a7
Added by Hammel 11 months ago

RM #580: remove test code that forced us into Pair Mode processing.

Revision 6acd662d
Added by Hammel 11 months ago

RM #580: Add support for allowing the user to request a reboot after configuring the networks.

Revision 6acd662d
Added by Hammel 11 months ago

RM #580: Add support for allowing the user to request a reboot after configuring the networks.

Revision d21cf992
Added by Hammel 11 months ago

RM #580: Switch from calling imgpio directly to testing for S40network-generated stamp file so the user doesn't have to keep holding the pair button while configuring the monitor.

Revision d21cf992
Added by Hammel 11 months ago

RM #580: Switch from calling imgpio directly to testing for S40network-generated stamp file so the user doesn't have to keep holding the pair button while configuring the monitor.

Revision f0b59163
Added by Hammel 4 months ago

RM #580: Clean up PHP code used to setup monitor wifi configurations, removing cruft.

Revision f0b59163
Added by Hammel 4 months ago

RM #580: Clean up PHP code used to setup monitor wifi configurations, removing cruft.

Revision d91ea521
Added by Hammel 4 months ago

RM #580: Clean up test script for php web service since it can be used at boot time too.

Revision d91ea521
Added by Hammel 4 months ago

RM #580: Clean up test script for php web service since it can be used at boot time too.

Revision 6ee2fe61
Added by Hammel 4 months ago

RM #580: Fix up runserver to work if called from init script.

Revision 6ee2fe61
Added by Hammel 4 months ago

RM #580: Fix up runserver to work if called from init script.

History

#1 Updated by Hammel 11 months ago

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

#2 Updated by Hammel 11 months ago

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

#3 Updated by Hammel 11 months 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.

Summary

  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.

#4 Updated by Hammel 11 months 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.

#5 Updated by Hammel 11 months 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.

update

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.

#6 Updated by Hammel 11 months 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).

#7 Updated by Hammel 11 months 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.

Update

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.

#8 Updated by Hammel 11 months 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

WWWNETCFG=/etc/imnetconfig

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.

#9 Updated by Hammel 3 months 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