Cellular
Every supported board except the ESP8266 can connect through a 2G or 4G modem, which is how boards without WiFi reach the cloud and how equipment far from any network stays online. Most modems work.
Check your modem
MaxwellTrack works with most 2G and 4G modems. Before you buy or wire one, check four things:
| Check | Why |
|---|---|
| Its model is on the TinyGSM list of supported modems (opens in a new tab) | The library talks to the modem through TinyGSM. |
| It can open secure connections (TLS 1.2) | Every connection to MaxwellTrack is encrypted. Some older 2G modems need a firmware update for this. |
| Your country still runs its network type | Some countries have switched off 2G or 3G. A 4G modem is the safe choice for new equipment. |
| Its power supply can deliver 2 A peaks | Most connection failures on cellular are power, not the modem. |
Not sure about yours? Write to MaxwellTrack support with the modem's model, and support confirms whether it works and how to connect it.
Connect through a modem
Declare your own MaxwellTrack instance with a secure TinyGSM client. It replaces the built-in WiFi instance, so the rest of the sketch is unchanged.
#define TINY_GSM_MODEM_SIM800 // replace with your modem's model
#include <TinyGsmClient.h>
#include <maxwelltrack.h>
#define DEVICE_ID "YOUR_DEVICE_ID"
#define AUTH_TOKEN "YOUR_ACCESS_TOKEN"
#define APN "internet"
#define SerialAT Serial1 // ESP32: pins 16/17 below; STM32 and Uno: see the example
TinyGsm modem(SerialAT);
TinyGsmClientSecure client(modem);
MaxwellTrackClass MaxwellTrack(client);
bool connectNetwork() {
if (!modem.waitForNetwork(60000L)) return false;
return modem.gprsConnect(APN, "", "");
}
void setup() {
Serial.begin(115200);
#if defined(ESP32)
SerialAT.begin(9600, SERIAL_8N1, 16, 17); // modem TX -> 16, modem RX -> 17
#else
SerialAT.begin(9600);
#endif
modem.restart();
while (!connectNetwork()) delay(10000);
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN);
}
void loop() {
if (!modem.isGprsConnected()) connectNetwork();
MaxwellTrack.run();
}On a board that also has WiFi through a separate WiFi library (UNO R4 WiFi, Pico W and Pico 2 W, MKR WiFi 1010, Nano 33 IoT), add #define MAXWELLTRACK_NO_WIFI above #include <maxwelltrack.h>, so the library leaves WiFi alone and uses your modem instance. ESP32 needs nothing extra.
Any other network client works the same way, such as Ethernet or a different modem library, as long as it opens a secure connection. To switch an existing instance to another client, call useTransport(client).
Report signal strength
On cellular the library cannot measure signal itself. Pass the modem's reading and it travels with the next heartbeat, so the console shows it beside the device.
MaxwellTrack.setSignal(modem.getSignalQuality());Wiring and power
- Modem TX to board RX, modem RX to board TX, and a common ground.
- ESP32 uses pins 16 and 17: its second serial port's default pins are wired to the flash chip on most modules.
- UNO R4 Minima and Nano R4 use pins 0 and 1 (
Serial1). - STM32 uses pins PA3 and PA2, Uno and Nano pins 7 and 8, through SoftwareSerial; the example sets this up for you.
- The modem needs its own supply that can deliver 2 A peaks, with a large capacitor close to it. Most connection failures on cellular are power.
Modem firmware
The modem must support TLS 1.2. If a modem that should work will not connect, update its firmware, then check the APN, the signal and the power supply.
Something unclear or out of date on this page? Tell support.
