WebThingsIO / gateway

WebThings Gateway - a self-hosted web application for monitoring and controlling a building over the web
http://webthings.io/gateway
Mozilla Public License 2.0
2.62k stars 339 forks source link

[Snap] Implement Wi-Fi hotspot on first boot #3156

Open benfrancis opened 3 months ago

benfrancis commented 3 months ago

As a user I want to connect to the gateway as a Wi-Fi hotspot when it first boots, so that I can connect the gateway to a network of my choosing.

Currently with Raspbian-based images when the gateway first boots it acts as a Wi-Fi hotspot with a captive portal which a user can connect to from another device (e.g. smartphone/tablet/laptop) in order to connect the gateway to a Wi-Fi network.

This will need implementing separately for the snap package when bundled with a custom Ubuntu Core OS image. This could be part of the gateway snap, or possibly a separate one.

For inspiration see:

benfrancis commented 1 month ago

See wifi-setup.ts for the Wi-Fi hotspot implementation used when running on Raspbian.

ogra1 commented 4 weeks ago

Have you yet tried to simply turn on this feature as-is and capture all errors/denials from the snap env. ? As long as it uses standard features in the backend it should work similar to the examples you listed in the initial post, we'd just need a list of interfaces (from snappy-debug) and add potentially missing binaries to the snap as long as it uses standard features and tools at least.

benfrancis commented 4 weeks ago

@ogra1 wrote:

Have you yet tried to simply turn on this feature as-is and capture all errors/denials from the snap env. ?

No I haven't tried that to be honest, I just know it doesn't currently work.

Looking at the source code in a bit more detail, wifi-setup.ts calls the same Platform implementation as Network Settings on the back end, which I've been porting to use Network Manager via DBus in https://github.com/WebThingsIO/gateway/pull/3168 *. Whilst the Raspbian implementation does use some command line tools like wpa_cli and systemctl, it does also manually read and write config files in /etc/, which I assumed wouldn't work in snap confinement.

I will play with this and try to figure out what doesn't work. There are some platform features (like ap mode) which weren't needed for network settings but are needed for first time setup.

* In retrospect it may have been easier to use nmcli rather than consume the DBus API, but I hadnt realised that was an option.