WiFi
ESP32, ESP8266, Raspberry Pi Pico W, Arduino UNO R4 WiFi, MKR WiFi 1010 and Nano 33 IoT boards connect over WiFi, either with the network in the sketch or with your own WiFi code.
The library manages WiFi
Pass the network name and password to begin(). The library joins the network, keeps it joined and opens the cloud connection.
#include <maxwelltrack.h>
#define DEVICE_ID "YOUR_DEVICE_ID"
#define AUTH_TOKEN "YOUR_ACCESS_TOKEN"
#define WIFI_SSID "YOUR_WIFI_NAME"
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
void setup() {
Serial.begin(115200);
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN, WIFI_SSID, WIFI_PASS);
}
void loop() {
MaxwellTrack.run(); // keep this in loop() at all times
}Open the Serial Monitor at 115200 baud. You should see [MaxwellTrack] Connecting... connected, and the device turns to Reporting in the console.
Your sketch manages WiFi
Call begin() without a network, and the library handles only the cloud connection. Use this when your code chooses between networks, as in the MultiWiFiFailover example, or already manages WiFi for something else. Call run() once WiFi is up.
void setup() {
Serial.begin(115200);
connectToWiFi(); // your own WiFi code
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN); // cloud connection only
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
MaxwellTrack.run();
}
}The cloud's certificate is checked
The connection is always encrypted, and over WiFi the device also checks that it is talking to the MaxwellTrack cloud and nothing in between, before it sends anything. The cloud's public root certificates are built into the library, so there is nothing to set up, and the device keeps connecting when the cloud renews its certificate. The update download is checked the same way.
- ESP8266 and Pico W set their clock from the internet first, because certificate dates are checked against it. Their network must allow time requests (UDP port 123); on a network that blocks them the device does not connect, rather than connect unchecked.
- UNO R4 WiFi, MKR WiFi 1010 and Nano 33 IoT check the certificate inside their WiFi module, with its own list of trusted roots.
- ESP32 needs no clock.
Your own root certificates
Only for a private MaxwellTrack deployment with its own certificates: pass its roots, in PEM, before begin(). They replace the built-in ones. Works on ESP32, ESP8266, UNO R4 WiFi and Pico W; the SecureConnection example shows it.
static const char ROOT_CA[] = R"PEM(
-----BEGIN CERTIFICATE-----
...your deployment's root...
-----END CERTIFICATE-----
)PEM";
void setup() {
MaxwellTrack.setRootCA(ROOT_CA);
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN, WIFI_SSID, WIFI_PASS);
}5 GHz networks
These boards join 2.4 GHz networks only. Network names and passwords are case-sensitive. Open networks without a password work too.
Pass strings that last
Strings you pass to the library (device ID, token, network name and password, certificate) are used in place, not copied. Pass string literals or global variables, never a temporary String.
Something unclear or out of date on this page? Tell support.
