Network

prefer() [Network]

Since 5.7.0:

You should normally let automatic connection management handle which network interface to use. There are prefer() methods in the Cellular, WiFi, and Ethernet classes that can be used if you have a need to steer the connection management toward a specific interface.

  • The automatic connection management rules still apply when preferring an interface.
  • The preference only determines which to use if multiple interfaces are available. It will not force connection to a non-available interface.
  • Setting a preference does not affect an immediate change if the cloud is currently connected. It will only be consulted on the next automatic connection management which typically occurs after the cloud disconnects.
  • Only one network type can be preferred, setting WiFi.prefer() will clear Cellular.prefer() for example.
  • Setting Network as the preferred interface will clear other preferences such as WiFi and Cellular.
// PROTOTYPE
virtual NetworkClass& prefer(bool prefer = true);

// EXAMPLE - Enable automatic connection management (disable other preferences)
Network.prefer();