🛠 Se connecter à un réseau GPRS (APN, signal, enregistrement)
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
- Arduino MKR GSM 1400 board
- External GSM antenna with U.FL connector (mandatory: never power on without an antenna)
- Activated micro-SIM card, without PIN code, with a data plan >
- LiPo battery ≥ 1500 mAh permanently connected (official requirement: transmission peaks exceed what USB provides)
- MKRGSM library (Library Manager); Arduino SAMD Boards core
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
- SIM with PIN code not disabled:
beginfails in a loop; disable the PIN on a phone or provide the correctSECRET_PINNUMBER. - Incorrect APN: GPRS attach fails even though the network is found; check the APN, login, and password with the operator (some require an "IoT" APN type).
- Powering on without an antenna: risk of module damage and no signal.
- Insufficient power supply: the board resets as soon as it transmits (Class 4 current peaks, peak order around 2 A); connect the LiPo ≥ 1500 mAh.
- Forgetting that 3G is being phased out by many operators: the SARA-U201 falls back to 2G/GPRS, which itself is being shut down in some countries — test local 2G coverage.
- Network: incoming connections are often blocked by the operator (CGNAT), so it is useless to try to make a
GSMServeraccessible from the Internet.
Other tutorials for this board
Code examples for this board
gsm-connexion.inoArduinoenvoi-sms.inoArduinohttp-get.inoArduinohttp-post-capteur.inoArduinoheure-gsm.inoArduinoappels.inoArduino