Efficient and reliable to switch to wifi when it is available


I am installing and running OpenWrt on devices where it has both LTE and WiFi (may use wpa_supplicant), the LTE will be a default network connection but if the WiFi is available, it'll switch to the WiFi immediately if the WiFi is available just like a mobile phone. There will have many different ways to do it, anyone knows the efficient and reliable way? Or any open source for reference? C++, bash, python ...

Thank you.

Kind regards.


You might want to look at the multi-WAN package ("mwan", I believe).

Thanks Jeff. I looked at it briefly, it is a very comprehensive routing procedure, if I understand it correctly the mwan3 is to be designed targeting to route devices.

My device is an IoT device, more like a mobile phone for running TCP/IP applications but requiring the network connection reliable and high available.

Correct me if I am wrong, I don't think mobile phone is using complicated routing for switching between 3G/4G and WiFi, but it is so reliable whenever there is a WiFi connected, it immediately switches the data connection to the WiFi.

I've done lots of googling search, but could not find any clue about how that connection switch in mobile phone is implemented. Looks to me that connection switch in mobile phone uses some kind of simple mechanism, still try to figure it out.

Thank you very much.

The Android implementation is visible in the AOSP code base. As a starting point

Basically, you look to see what networks are available to you, then "pick the best" (or only) based on some rules.

There is a significant "challenge" with switching connectivity when you have persistent connections, as you change your own IP and the TCP/IP connection itself can't be "moved" automatically to the new IP. With web browsing and other short-duration connections, the client makes a new connection and the user typically doesn't notice. With streaming, the buffering portion of the application determines that connection has been lost and establishes a new connection before the buffer runs out. MQTT and similar have the concept of a "session ID" that allows the client and server to "carry on as if nothing has happened" once a new TCP/IP connection is established.

Where users will notice is with things like VOIP or FaceTime, here you'll likely have a drop unless the "other" media is ready for connections. Often, a cellular connection will be "ready" at all times, even if it is not in use. These details are hidden in the "RIL" (Radio Interface Layer), which is typically vendor-proprietary code for cell phones and similar devices.

1 Like

Thank you Jeff, I've been thinking that nmcli could be a useful tool, but I cannot be seriously about it as you have to install the whole NetworkManager package in about 10 MB which just not feasible in an embedded system. Seems AOSP reinvented the wheel, I am going to search if there is any light weight open source similar to the nmcli or should I design my own in C++.

Thank you so much.

NetworkManager is definitely not something I would want to emulate! It does far more than detect potential wireless connections and bring them up.

Android (and iOS, and Symbian, and ...) didn't really reinvent the wheel, they worked to resolve a more complex problem, as outlined above.

Most of what you want to do can be handled by shell scripting and "hotplug" events (net up / down).

Thanks Jeff, you are right. Thank you so much.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.