Connection status
Read the connection state in code, react when it changes, and understand the serial log.
In code
void onLink(bool online) {
digitalWrite(STATUS_LED, online ? HIGH : LOW);
}
void setup() {
MaxwellTrack.onConnectionChange(onLink);
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN, WIFI_SSID, WIFI_PASS);
}
void loop() {
MaxwellTrack.run();
if (!MaxwellTrack.connected()) {
int state = MaxwellTrack.connectionState(); // see the table below
}
}connectionState()
| Value | Meaning | What to check |
|---|---|---|
0 | Connected | |
-1 | Disconnected | The network |
-2 | The secure connection could not be opened | Internet access; on cellular the APN, signal and data plan |
-3 | Connection lost | Signal and power |
-4 | Timed out | Signal, or a busy network |
5 | Device ID or access token refused | Copy both again from the device's Settings tab |
The serial log prints the same values as failed, rc=<value>.
Heartbeats
While connected, run() sends a heartbeat every 10 seconds with signal strength, uptime and code version. The console marks a device as not reporting after 30 seconds without hearing from it. To change the interval, call setHeartbeatInterval(ms) before begin() and keep it well under 30 seconds.
Questions developers ask
Does run() block? No. It does a little work each call, so call it on every pass of loop() and use millis() timers instead of long delay() calls.
Can I use FreeRTOS tasks on the ESP32? Yes, but call every MaxwellTrack function from the same task.
Why is there no .cpp source? The library ships compiled for each supported processor. The Arduino IDE and PlatformIO link it for you.
For anything else, write to MaxwellTrack support with the board, the library version and the serial log.
Something unclear or out of date on this page? Tell support.
