Skip to main content

4G (GSM) quick start

Use the ThingsLinkerGSM class when a device must work without WiFi, for example in the field or in a vehicle. Every widget function is the same as on WiFi.

Hardware​

  • An ESP32 (any variant).
  • A Simcom A7672SA, A7672E, A7672S or SIM7672 4G LTE modem.
  • A SIM card with an active data plan.
  • A power supply for the modem that can deliver at least 500 mA; the ESP32's 3.3 V pin is not enough.

Typical wiring:

The 4G variant needs only the ArduinoJson library.

The sketch​

#include <ThingsLinkerGSM.h>

ThingsLinkerGSM iot(Serial2, "YOUR_AUTH_TOKEN", "YOUR_BLUEPRINT_KEY");

#define MODEM_PWR_PIN 4 // GPIO wired to PWRKEY, or TL_NO_PWRKEY

void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17); // RX = 16, TX = 17

iot.begin("airtelgprs.com", MODEM_PWR_PIN); // your SIM's APN
}

void loop() {
iot.run();

static unsigned long last = 0;
if (millis() - last >= 10000) {
last = millis();
iot.chart("V1", 24.5); // replace with your sensor
}
}

The library powers the modem on, registers on the network, opens the data connection, connects securely to ThingsLinker and reconnects after any drop.

APN​

The APN comes from your mobile operator. Some common ones:

OperatorAPN
Airtel Indiaairtelgprs.com
Jio Indiajionet
Vodafone Indiawww
AT&T USphone
T-Mobile USfast.t-mobile.com

If your operator needs an APN username and password, pass them after the PWRKEY pin: iot.begin(APN, MODEM_PWR_PIN, "user", "pass").

PWRKEY​

Your boardUse
PWRKEY wired to an ESP32 GPIO, for example 4#define MODEM_PWR_PIN 4
PWRKEY not connected, or tied so the modem starts when powered#define MODEM_PWR_PIN TL_NO_PWRKEY

If the ESP32 pin drives PWRKEY directly, with no transistor, the key is pressed by pulling the pin low. Tell the library before begin():

iot.setPowerKeyActiveLow(true);
iot.begin(APN, MODEM_PWR_PIN);

The key is only pressed when the modem is not answering, so restarting the ESP32 never switches off a modem that is already running.

Optional: MQTT login​

As on WiFi, no MQTT login is needed for the ThingsLinker broker. For a broker of your own that asks for one, put the username and password first:

iot.begin("MQTT_USERNAME", "MQTT_PASSWORD", "airtelgprs.com", MODEM_PWR_PIN);

Useful functions​

FunctionReturns
iot.networkConnected()true while the mobile data connection is up
iot.mqttConnected()true while connected to ThingsLinker
iot.signalQuality()Signal strength, 0 to 31 (99 means no signal)
iot.getIP()The modem's IP address

Every reading sent over 4G uses mobile data. Send only as often as you need.