Skip to main content

WiFi quick start

1. Create the sketch​

#include <ThingsLinker.h>

ThingsLinker iot("YOUR_AUTH_TOKEN", "YOUR_BLUEPRINT_KEY");

#define RELAY_PIN 4

// App → device: a Switch widget on V8 turns the relay on and off
void onPump(bool on) {
digitalWrite(RELAY_PIN, on ? HIGH : LOW);
}

void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT);

iot.onSwitch("V8", onPump); // register callbacks before begin()
iot.begin();
}

void loop() {
iot.run(); // call on every loop; never block for long

// Device → app: send a temperature to the Chart widget on V1 every 5 s
static unsigned long last = 0;
if (millis() - last >= 5000) {
last = millis();
float temperature = 24.5; // replace with your sensor
iot.chart("V1", temperature);
}
}

Replace YOUR_AUTH_TOKEN and YOUR_BLUEPRINT_KEY with the device's values from the Organization Portal, and the pins with the ones its widgets use.

2. Upload it​

Select your ESP32 board and port in Arduino IDE and upload. If you plan to use firmware updates over the air, choose the partition scheme now: see OTA firmware updates.

3. Give the device your WiFi​

On first boot there is no WiFi saved, so the device starts Bluetooth setup mode. Add the device to an account in the app or the User Portal, which sends it the WiFi details; see Add a device. From then on the device connects by itself at every boot.

4. Check it works​

Open the Serial Monitor at 115200 baud. You should see the device join WiFi, connect to ThingsLinker, and log each value it sends, for example [MQTT] ✓ V1 = 24.50. The device shows Online in the portals, and the value appears on its dashboard.

Keep the loop free​

iot.run() receives commands and keeps the connection alive. If the loop is blocked, for example by a long delay(), commands arrive late or are missed. Use millis() timing as in the example instead of delay().

Optional: MQTT login​

The ThingsLinker broker accepts devices without an MQTT username or password, so iot.begin() takes no arguments. Pass a login only if you connect to a broker of your own that asks for one:

iot.begin("MQTT_USERNAME", "MQTT_PASSWORD");

The ThingsLinker broker needs no login, so leave both out. They are only for a broker of your own that asks for a username and password; passing "" also connects without a login.

Useful functions​

FunctionReturns
iot.mqttConnected()true while connected to ThingsLinker
iot.wifiConnected()true while connected to WiFi
iot.getIP()The device's IP address
iot.getChipID()The ESP32's unique chip ID