attente-lte-nbiot.ino

Arduino MKR NB 1500 · File : attente-lte-nbiot.ino · Language : Arduino · Use case : Vérifier l'attachement LTE-M/NB-IoT et le mode réseau

The MKR NB 1500 can take a while to join an LTE-M or NB-IoT network: this attach loop waits up to two minutes, prints the state at each poll, then confirms operator and signal quality. The base of any reliable LPWA project.

Hardware

An Arduino MKR NB 1500 (SAMD21 microcontroller, u-blox LTE-M/NB-IoT modem, external antenna, LiPo power on J6 or USB). An IoT data SIM (LTE-M or NB1 depending on operator), the LTE antenna screwed on, a micro-USB cable.

Wiring

No external wiring: SIM inserted, antenna fitted, USB power; ensure good reception (basements are a classic failure).

How it works

nb.begin() starts the u-blox SARA-R4 modem. getStatus() returns the network stack state; the loop polls every 2 s for up to 60 tries. signalQuality() reports the module RSSI.

Running it

Install the Arduino SAMD Boards package and the MKRNB library, select the board, upload. Plan for an activated IoT SIM (LTE-M or NB1) and good reception: attaching to the network can take several minutes.

Variants

Force the radio with nb.setNetworkSettings("3") for NB-IoT only, or add a modem restart after five failed attach attempts.

attente-lte-nbiot.ino

// Attachement reseau LTE-M ou NB-IoT avec le MKR NB 1500 (MKRNB).
#include <MKRNB.h>

const char PIN_SIM[] = "0000";
const char APN[] = "iot.1nce.net"; // APN IoT de votre operateur

NB nb;
NBClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("Init modem NB..."));
  if (nb.begin(PIN_SIM) != NB_READY) {
    Serial.println(F("Modem KO : verif. SIM/antenne"));
    while (true);
  }
  // Attente longue : un module NB-IoT peut mettre 1-2 min a s'attacher
  int essai = 0;
  while (nb.getStatus() != NETWORK_JOINED && essai++ < 60) {
    Serial.print(F("Attente reseau... "));
    Serial.println(nb.getStatus());
    delay(2000);
  }
  Serial.print(F("Statut final : "));
  Serial.println(nb.getStatus() == NETWORK_JOINED ? "JOINT" : "ECHEC");
  Serial.print(F("Operateur : "));
  Serial.println(nb.getOperator());
  Serial.print(F("Signal (RSRP approx) : "));
  Serial.println(nb.signalQuality());
}

void loop() {}

← Back to the board