Device library
The MaxwellTrack library for Arduino takes care of the secure connection, reconnects, online status, buffering while offline, remote updates and the message format. Your sketch sends readings and reacts to commands.
#include <maxwelltrack.h>
#define DEVICE_ID "YOUR_DEVICE_ID"
#define AUTH_TOKEN "YOUR_ACCESS_TOKEN"
void setup() {
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN, "WiFi name", "WiFi password");
}
void loop() {
MaxwellTrack.run();
static unsigned long last = 0;
if (millis() - last >= 10000) {
last = millis();
MaxwellTrack.write("tank_level", analogRead(A0)); // datastream key
}
}The Device ID and access token come from the device's Settings tab in the console. The examples call the token AUTH_TOKEN.
Install
Tools > Manage Libraries
Search for "MaxwellTrack" and click Install.
For a 2G or 4G modem, install "TinyGSM" as well.
Examples: File > Examples > MaxwellTrackYou can also add the release ZIP from the releases page (opens in a new tab) with Sketch > Include Library > Add .ZIP Library. In the MCode IDE there is nothing to install: the library is always included.
What it handles
- Per-device sign-in over an encrypted connection, with the device's own ID and access token. Over WiFi the device also checks that it is talking to the MaxwellTrack cloud before sending anything.
- Staying connected: WiFi (when the library manages it) and the cloud connection reconnect on their own, waiting from 2 to 60 seconds between attempts with a random spread, so a thousand devices do not all reconnect in the same second after an outage.
- Online status: heartbeats carry signal strength, uptime and code version to the console.
- Readings survive outages: messages written while offline are kept on the device and sent in order after reconnecting, each with the time it was measured.
- Commands from dashboards, automations and the assistant, to one handler or one per key.
- Remote updates on ESP32, ESP8266 and Raspberry Pi Pico, signed by MaxwellTrack so a board installs nothing else.
- Local rules and equipment: rules that run on the board with or without network, and Modbus meters and drives on an RS-485 port, all set up in the console.
- Cameras: pictures and live view from an ESP32 camera board over the same connection.
Examples
| Example | Shows |
|---|---|
| 01.Basics/HelloCloud | The smallest working sketch |
| 01.Basics/SendSensorData | Readings as numbers and text |
| 01.Basics/ControlFromDashboard | Switches and sliders driving outputs, one handler per key |
| 02.WiFi/MultiWiFiFailover | Several networks tried in order |
| 03.Cellular | A 2G or 4G modem on STM32, Pico, Zero, Mega, Uno or ESP32 |
| 04.Advanced/OfflineBuffering | Storing readings while offline, connection events |
| 04.Advanced/MultipleSensors | Several readings in one message with one timestamp |
| 04.Advanced/SecureConnection | Your own root certificates, for a private deployment |
| 05.Controller/ModbusController | Local rules and Modbus equipment on an RS-485 port |
| 06.Camera/Camera | Pictures and live view from an ESP32 camera board |
Something unclear or out of date on this page? Tell support.
