Menu

PlatformIO Quickstart

The same smallest-possible publish sketch as the Arduino quickstart — different toolchain. Confirm PlatformIO reaches the broker, then move on to the SDK.

This is a smoke test, not a starting point. It proves your PlatformIO setup can talk to the broker. It has no reconnect logic, no real certificate verification, and a hardcoded device ID. Once you've seen it work, move to the Minimalist SDK.
Prerequisites: PlatformIO installed (the VS Code extension or the CLI), an ESP32 board, and MQTT credentials from the dashboard Settings page. The Getting Started — PlatformIO page covers the install if you need it.
1

Configure platformio.ini

Create a project and set the environment to your ESP32 board. Declare the MQTT client in lib_deps so PlatformIO fetches it on the first build:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

lib_deps =
    knolleary/PubSubClient @ ^2.8
2

Drop in your credentials

Add a header at src/credentials.h with your values from the dashboard:

#define WIFI_SSID   "YourWiFiName"
#define WIFI_PASS   "YourWiFiPassword"

#define MQTT_HOST   "mqtt.ohioiot.com"
#define MQTT_PORT   8883
#define MQTT_USER   "larry"
#define MQTT_PASS   "your_mqtt_password"
Add src/credentials.h to .gitignore before this ever sees a commit.
3

The publish program

Put this in src/main.cpp. It connects to WiFi, connects to MQTT, publishes one value, and idles:

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>
#include "credentials.h"

WiFiClientSecure wifi;
PubSubClient mqtt(wifi);

void setup() {

    Serial.begin(115200);
    Serial.println();

    WiFi.begin(WIFI_SSID, WIFI_PASS);
    Serial.print("wifi");
    while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); }
    Serial.println(" connected");

    wifi.setInsecure();              // quickstart only — see warning below
    mqtt.setServer(MQTT_HOST, MQTT_PORT);

    Serial.print("mqtt");
    while (!mqtt.connected()) {
        Serial.print(".");
        if (mqtt.connect("quickstart-pio", MQTT_USER, MQTT_PASS)) break;
        delay(2000);
    }
    Serial.println(" connected");

    String topic = String(MQTT_USER) + "/dev1/numb/temperature/celsius";
    mqtt.publish(topic.c_str(), "23.5");
    Serial.println("published 23.5 to " + topic);
}

void loop() {
    mqtt.loop();
}
wifi.setInsecure() encrypts the connection but skips verifying the broker's certificate — fine for a smoke test, not fine for production. The Minimalist SDK ships the OhioIoT CA cert and verifies properly with no extra code.
4

Build, upload, watch

Plug in the ESP32 and run:

pio run --target upload
pio device monitor

You should see WiFi connect, MQTT connect, and the publish line. Open the dashboard — under Devices, dev1 shows a temperature of 23.5.

Your PlatformIO toolchain works. Credentials are right and the broker is reachable. This is identical to where the Arduino quickstart lands — same broker, same topic, different IDE.

Now what

Like the Arduino version, this is the smallest possible demonstration and approximately the worst code you'd ship: blocking connect, no reconnect, no certificate verification, a hardcoded ID. The Minimalist SDK fixes all of that in barely more code. Build on that from here.