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.
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.8Drop 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"src/credentials.h to .gitignore before this ever sees a commit.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.Build, upload, watch
Plug in the ESP32 and run:
pio run --target upload
pio device monitorYou should see WiFi connect, MQTT connect, and the publish line. Open the dashboard — under Devices, dev1 shows a temperature of 23.5.
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.
