Cloud functions

Particle.connect()

Particle.connect() connects the device to the Cloud. This will automatically activate the network connection and attempt to connect to the Particle cloud if the device is not already connected to the cloud.

void setup() {}

void loop() {
  if (Particle.connected() == false) {
    Particle.connect();
  }
}

In most cases, you do not need to call Particle.connect(); it is called automatically when the device boots. Typically you only need to call Particle.connect() when you change the system mode to SEMI_AUTOMATIC (or MANUAL).

Connecting to the cloud does not use Data Operation from your monthly or yearly quota. However, for cellular devices it does use cellular data, so unnecessary connection and disconnection can lead to increased data usage, which could result in hitting the monthly data limit for your account.

On Gen 3 devices (Argon, Boron, B-Series SoM, and Tracker), prior to Device OS 2.0.0, you needed to call WiFi.on() or Cellular.on() before calling Particle.connect(). This is not necessary on Gen 2 devices (any Device OS version) or with 2.0.0 and later.

Normally, Device OS automatically handles connecting to the network and cloud and retrying as necessary.

If you manually add a timeout, for example to put the device to sleep to conserve battery when it cannot connect to cellular, you should do so with care.

  • Even though a cellular connection can occur in as little as 10 seconds with LTE Cat 1, it can take significantly longer, especially with 3G and 2G. A minimum of 120 seconds is recommended for this reason.
  • You must also stay awake trying to connect for at least 5 minutes periodically. The SIM may switch between IMSI when failing to connect, and if you do not try for long enough, it may not cycle through them properly, causing the device to stay stuck on one that can't be used in your location.
  • After 10 minutes of failing to connect, Device OS will do a full shutdown of the cellular modem and restart it. This can help clear issues in some cases. It is recommended that you wait at least 11 minutes to be sure this can occur.
  • If you do not want to wait 11 minutes for battery life reasons, you should implement a variable backoff scheme were you at least do this periodically, say once every several hours, to be sure it will be done eventually. This will also assure that the 5 minute IMSI cycling time requirement is met.
  • The 11 minute shutdown of the cellular modem consists of sending it command to full reset, and also removing the power to the modem. This is more thorough than entering sleep mode, or using the reset button on the device.