I’m essentially trying to re-create the network setup flow of the wifi-connect snap on Ubuntu Core, but in Node.js. In other words:
- Start a Wi-Fi access point on my IoT device on boot
- Allow clients to connect to that access point
- Host a web interface which allows clients to get a list of nearby Wi-Fi networks
- Allow a client to connect the IoT device to one of those networks
I’ve got steps 1, 3 and 4 working, but I’m a bit stuck on step 2 because clients which connect to the Wi-Fi access point don’t get assigned an IP address and so can’t access the web server hosted on the IoT device. I assume this is because I need to enable a DHCP server on the IoT device at step 2 and then disable it again at step 4?
The wifi-connect snap appears to use dnsmasq for this, but I don’t really understand how it works.
My work-in-progress PR which creates a Wi-Fi access point is here.
Can anyone point me in the right direction as to how I configure a DHCP server and dynamically turn it on and off? Can this be done using NetworkManager via D-Bus, or do I need to use some other approach? Crucially, is this possible without root? My snap gets switched over to the snap_daemon user shortly after startup.
There’s some brief documentation which says the NetworkManager snap can be used to create a Wi-Fi access point, but it doesn’t mention DHCP.
I know there have been several previous threads related to this topic but I couldn’t quite find the answer I was looking for.