Cellular

prefer() [Cellular]

Cellular.prefer, prefer

Since 5.7.0:

You should normally let automatic connection management handle which network interface to use.

In some cases you may want to prefer cellular, Wi-Fi, or Ethernet, and this can be done using the API. Note however:

  • The automatic connection management rules still apply.
  • 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 Cellular.prefer() will clear WiFi.prefer() for example.
// PROTOTYPE
virtual NetworkClass& prefer(bool prefer = true);

// EXAMPLE - enable prefer cellular
Cellular.prefer();

// EXAMPLE - disable prefer cellular
Cellular.prefer(false);