Reliable and updatable access point

Hi Zahari,

Thank you for your response.
I saw that you’ve tried the AP+STA mode before in another topic. I was happy to find that out, but after some investigation I saw that this has some downsides. Like only being able connect to Wi-Fi networks on the same channel. And I’m not really sure if it’s reliable enough.

I’ve put some work into creating a native dbus library in Node.js, which works great. But thanks for the heads-up about the libnm library.

If you’ve some suggestions, I’m happy to hear them!
The next challenge is determining if the device is online or not in a reliable way, so that the Access Point can be started when the device is offline.

I’ll keep posting updates about my progress.

Awesome, good luck!

1 Like

Thanks!

Because I don’t want to be misinformed, is it true that using AP+STA can cause some problems? Because I’ve read that it can cause some problems like different channels. I don’t know how good you’ve tested it, but I’d like to know if it’s stable and can be used in any situation. So if it still can connect to any 2.4GHz and 5GHz network. Because it’s obviously the best solution to have the AP+STA on the onboard Wi-Fi chip all of the time!

I have not done much testing yet. I initially ignored the AP+STA mode mainly because it was a known issue that it cannot work with NetworkManager, until I was able to run it successfully recently.

AP+STA could have the issues with the channels indeed from what I have read as well. I have not looked at the actual implementation of the mode inside the kernel. My guess is that this would depend on the capabilities of the particular chip/driver/firmware. Since the RPi 4 has a relatively newer chip probably it would behave better and may not have those limitations. With a fairly recent Atheros chip I was doing my testing with on my laptop I did not run into the channel issue at all.

Hereby an update with my progress:

Device online/offline
I’ve written a function that checks if the device is online or not. It executes the following steps:

  1. Check if device is in AP mode. If true, device is offline. If false, continue
  2. Check device state, if disconnected, device is offline. If not, continue
  3. If device state is not ‘connected’, wait for this state
  4. Ping a couple of hosts (like Google’s DNS / CloudFlare’s DNS, both IPv4 and IPv6). If one ping succeeded, device is online. If not, continue
  5. If ping didn’t succeed (could be firewall issues), execute a HTTP(s) ping to our own server. If completed, device is offline. Else device is offline.

If this check determines that the device is offline, it’ll scan all Wi-Fi networks and saved it in a variable. Then it starts the AP.

Connect to configured access points
I’ve also created a function that tries to connect to networks that are already configured. This function does the following:

  1. Check if device is online (see above). If it is, return that it’s connected. If not, continue
  2. Get all configured connections, filtered by Wi-Fi connections. If none found, stop. If not, continue
  3. Scan Access Points
  4. If an access point is found that has a configured connection (based by SSID) OR if a config is found with hidden: true, continue. Else, stop
  5. Try connecting to configured access points that are found (or hidden). If succeeded, awesome. If not, return that it’s not awesome.

After this function, based on the response, the access point can be started again.
I had to create this function, because the built-in function of NetworkManager didn’t work as expected. If I activate the connection "/" on a specific device, according to the documentation, it should automatically connect to the best configuration found. But, according to NetworkManager, the best configuration is the AP configuration :sweat_smile:, even with autoconnect: false.

I’ve also improved my NetworkManager library. The scan function handles the errors well. And when activating a connection, the library waits for the device state to change to connected. Or failed, if it fails, and throws an error. So you’re certain that when activating a network, it’s really activated and not failed connecting.

If someone has any suggestions about the functions I’ve created, please let me know!
I’m planning on publishing the NetworkManager library (when it’s mature enough), so more people can work on it and can improve it.