🛠 Se connecter à un réseau GPRS (APN, signal, enregistrement)

Arduino MKR GSM 1400 · intermediaire · Schéma : IMG-mkr-gsm-1400-intermediaire-1-mkrgsm-reseau-gprs.svg — MKR GSM 1400 avec antenne externe déployée sur connecteur U.FL, carte micro-SIM insérée, et à l'écran l'opérateur détecté avec la puissance du signal.

Objectives

Network the MKR GSM 1400: initialize the u-blox SARA-U201 module (note: not a TOBY, the community rumor is false), unlock the SIM, register on the network, measure signal strength, and open a GPRS packet-switched connection with the operator's APN. This is the prerequisite for all SMS, HTTP, and MQTT tutorials.

Hardware

Complete Code

#include <MKRGSM.h>
#include "arduino_secrets.h"   // onglet Secret de l'IDE
const char PINNUMBER[] = SECRET_PINNUMBER;  // "" si aucun code PIN
const char GPRS_APN[]  = SECRET_GPRS_APN;   // ex. "orange.fr", "sl2sfr", "free"

GSM          gsmAccess;
GPRS         gprs;
GSMScanner   scanner;

void setup {
  Serial.begin(9600);
  while (!Serial) {}

  // 1) Radio + deblocage SIM + enregistrement reseau
  while (gsmAccess.begin(PINNUMBER) != GSM_READY) {
    Serial.println("Enregistrement reseau en cours...");
    delay(2000);
  }
  Serial.println("GSM_READY : enregistre sur le reseau");

  // 2) Operateur et puissance du signal
  char op[50];
  if (scanner.getOperator(op) == GSM_ERROR) strcpy(op, "inconnu");
  Serial.print("Operateur : "); Serial.println(op);
  long rssi = scanner.signalStrength;
  Serial.print("RSSI (dBm) : "); Serial.println(rssi);

  // 3) Attache GPRS (contexte de donnees PDP)
  while (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) != GPRS_READY) {
    Serial.println("Attach GPRS echoue, retry...");
    delay(3000);
  }
  Serial.println("GPRS_READY : connexion donnees etablie");
}

void loop { delay(1000); }

Expected Verification

The console displays "GSM_READY" (registration may take several tens of seconds on a cold start), then the operator and a realistic negative RSSI (for example -65 to -107 dBm; 99 or -1000 = no SIM card or no antenna), finally "GPRS_READY". The antenna must be deployed and oriented, never placed on metal (Arduino recommendation).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials