Menu

Connect Your ESP32 | Arduino IDE

Attach a device to the OhioIoT MQTT broker with a secure TLS connection.

Using PlatformIO instead? Switch to the PlatformIO version of this page.
Prerequisites:
  • You should have completed the previous step: Create Your Account
  • You will need an ESP32 development board (or similar)
  • Arduino IDE should already be installed
1

Add ESP32 board support

If you've never flashed an ESP32 from the Arduino IDE before, you need to add Espressif's board package first.

In the Arduino IDE, open File → Preferences and add this URL to the Additional Board Manager URLs field:

https://espressif.github.io/arduino-esp32/package_esp32_index.json

Then open Tools → Board → Boards Manager, search for esp32, and install the esp32 package by Espressif Systems.

Once it finishes, select your board under Tools → Board → esp32. If you're not sure, ESP32 Dev Module is a safe default.

2

Install PubSubClient

Open Tools → Manage Libraries, search for PubSubClient, and install the one by Nick O'Leary (version 2.8 or later).

3

Install the Minimalist SDK

Download the SDK and unzip it.

Copy the unzipped folder into your Arduino/libraries folder, wherever you may have set that folder location in your Arduino IDE.

Defaults
macOS / Linux:  ~/Documents/Arduino/libraries/
Windows:        Documents\Arduino\libraries\

Restart the Arduino IDE so it picks up the new libraries.

4

Create your sketch

In the Arduino IDE, File → New Sketch, then File → Save As and give it a name. Arduino will create a folder with a matching .ino file inside.

5

Add your credentials

In the top of your sketch, you see the four credentials you need to provide:

#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASS "your_wifi_password"
#define MQTT_USER "your_mqtt_username"    <-- from the Settings page in the app
#define MQTT_PASS "your_mqtt_password"    <-- from the Settings page in the app

You know your WiFi credentials. Your MQTT credentials are on the Settings page in your OhioIoT app.

6

Flash and watch

Plug in your ESP32, pick the correct port under Tools → Port, and click the Upload button (→ arrow) in the toolbar.

When it finishes uploading, open Tools → Serial Monitor and set the baud rate to 115200. You should see:

  booting...

	existing deviceID: a8f3k2m1

	wifi connecting...
	wifi connected...

	mqtt connecting...
	mqtt connected...
You're connected. Your ESP32 has a TLS-encrypted MQTT connection to OhioIoT.

What just happened

device_id.get_or_set(DEVICE_ID) checked the ESP32's non-volatile storage for a saved device ID. Since this is the first boot, it generated a random 8-character string, stored it, and returned it. Next boot, it returns the same ID.

wifi_tools.begin() connected to WiFi and set up an event handler that tracks connection state automatically.

mqtt.setup() configured the MQTT client with TLS. The SDK ships with the OhioIoT broker's CA certificate built in — you didn't need to configure it. That's why the connection just worked over port 8883.

mqtt.maintain() handles everything in the loop: reconnecting if dropped, processing incoming messages, keeping the heartbeat alive.

What's handling TLS?

The SDK ships with the CA certificate for Let's Encrypt's ISRG Root X1 — the certificate authority that signs the OhioIoT broker's TLS certificate. When your ESP32 connects to port 8883, it uses this CA cert to verify that it's talking to the real mqtt.ohioiot.com.

Troubleshooting

Libraries aren't found when compiling — make sure you restarted the Arduino IDE after copying the SDK folders into libraries/. The IDE only scans that directory at startup.

"failed to connect" in the Serial Monitor — double-check your MQTT username and password in credentials.h. They must match the Settings page in the dashboard exactly.

WiFi connects but MQTT doesn't — some networks block port 8883. Try a mobile hotspot. If it works there, your network is blocking outbound TLS-MQTT.

No port shows up under Tools → Port — you may need a USB-to-UART driver (CP210x or CH340, depending on your board). Unplug, install the driver, and plug back in.

Device keeps reconnecting — two devices with the same device ID will kick each other off the broker. Unplug one and see if the other stabilizes.