Cellular

clearCredentials()

Cellular.clearCredentials, clearCredentials

Gen 3 cellular devices only use one set of credentials, and they must be correctly matched to the SIM card that's used. If using a Particle SIM, using Cellular.setCredentials() is not necessary as the default APN will be used. If you have set a different APN to use a 3rd-party SIM card, you can restore the use of the Particle SIM by using Cellular.clearCredentials().


Gen 2 Devices:

On the Electron 2G, U260, U270, and ELC314, there is only a 4FF nano SIM card slot. There is no internal SIM so you must always have a SIM card in the SIM card holder on the bottom of the device for normal operation.

The Electron LTE (ELC402 and ELC404) and E Series (E310, E314, E402, and E404), have a built-in MFF2 SMD SIM. Since you cannot use a 3rd-party SIM card, you do not have to set the APN as the Particle SIM APN is built-in.

  • The APN must be set in all user firmware as it is only saved in the modem memory and the setting is erased when powered down.
  • The keep-alive must be set from your user firmware.
  • The Electron LTE (ELC402) does not have a SIM card slot and cannot be used with a 3rd-party SIM card.

On Gen 2 devices, cellular credentials are not added to the device's non-volatile memory and need to be set every time from the user application. You may set credentials in 3 different ways:

  • APN only
  • USERNAME & PASSWORD only
  • APN, USERNAME & PASSWORD

Note: When using the default SYSTEM_MODE(AUTOMATIC) connection behavior, it is necessary to call cellular_credentials_set() with the STARTUP() macro outside of setup() and loop() so that the system will have the correct credentials before it tries to connect to the cellular network (see EXAMPLE).

The following examples can be copied to a file called setcreds.ino and compiled and flashed to your device over USB via the Particle CLI. With your device in DFU mode, the command for this is:

particle compile electron setcreds.ino --saveTo firmware.bin && particle flash --usb firmware.bin

Note: Your device only uses one set of credentials, and they must be correctly matched to the SIM card that's used. If using a Particle SIM, using cellular_credentials_set() is not necessary as the default APN of "spark.telefonica.com" with no username or password will be used by Device OS. To switch back to using a Particle SIM after successfully connecting with a 3rd Party SIM, just flash any app that does not include cellular_credentials_set(). Then disconnect the battery and external power (such as USB) for 20 seconds to remove the settings from the modem’s volatile memory.

// SYNTAX
// Connects to a cellular network by APN only
STARTUP(cellular_credentials_set(APN, "", "", NULL));

// Connects to a cellular network with USERNAME and PASSWORD only
STARTUP(cellular_credentials_set("", USERNAME, PASSWORD, NULL));

// Connects to a cellular network with a specified APN, USERNAME and PASSWORD
#include “cellular_hal.h”
STARTUP(cellular_credentials_set(APN, USERNAME, PASSWORD, NULL));
// EXAMPLE - an AT&T APN with no username or password in AUTOMATIC mode

#include "cellular_hal.h"
STARTUP(cellular_credentials_set("broadband", "", "", NULL));

void setup() {
  // your setup code
}

void loop() {
  // your loop code
}