Remote Serial Monitor for ESP32 over Wi-Fi
Read an ESP32's serial output in your browser and type commands back to it, from anywhere, by printing to ClavdaSerial instead of Serial.
Updated 1 min read
The Arduino Serial Monitor needs a USB cable. With the ClavdaOTA library, anything the sketch prints to ClavdaSerial shows up live in the Clavda console instead, wherever the board is, and lines you type there arrive back in the sketch.
What you need
- An ESP32 already connected to Clavda.
Add the Serial Monitor to your sketch
Start ClavdaSerial
Call ClavdaSerial.begin(&Serial) in setup(). Passing &Serial copies everything to the USB port too, so a cable still works when you have one.
Print to ClavdaSerial
Use ClavdaSerial.print, println and printf wherever you would use Serial.
Handle typed lines
A line typed into the console's Serial Monitor arrives in the callback you give ClavdaSerial.onMessage().
This sketch does all three. It prints its uptime every five seconds, and answers status with its free memory:
#include <Arduino.h>
#include <WiFi.h>
// Your firmware version. Change it for every build you upload: the
// console counts an update done once the board reports it.
#define CLAVDA_FIRMWARE_VERSION "1.0.0"
// The library, then this board's credentials from the console.
#include <ClavdaOTA.h>
#include "clavda_device.h"
const char *ssid = "your-wifi";
const char *password = "your-wifi-password";
unsigned long lastReport = 0;
void setup() {
Serial.begin(115200);
// Start the Serial Monitor; &Serial copies everything to USB too.
ClavdaSerial.begin(&Serial);
// A line typed in the console's Serial Monitor arrives here.
ClavdaSerial.onMessage([](const String &msg) {
if (msg == "status") {
ClavdaSerial.printf("Free heap: %u\n", (unsigned)ESP.getFreeHeap());
} else {
ClavdaSerial.printf("Unknown: %s (try \"status\")\n", msg.c_str());
}
});
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
ClavdaOTA.begin(CLAVDA_DEVICE);
}
void loop() {
ClavdaOTA.loop();
// Print to ClavdaSerial wherever you would print to Serial.
if (millis() - lastReport >= 5000) {
lastReport = millis();
ClavdaSerial.printf("Uptime: %lu s\n", millis() / 1000);
}
}
Flash it, over USB or over the air.
Open the Serial Monitor
In Clavda, open the device's Connect sheet and press Serial Monitor. Output appears as the board prints it. Type status and press Enter to see the reply.
Good to know
- Boot messages are kept. The last 2 KB of output stays on the board, so a monitor you open late still starts with what the board printed when it booted.
- It is end-to-end encrypted. Output and typed lines are encrypted between the board and your browser.
- Permissions. Anyone who can see the device can watch the output. Typing into it needs permission to edit devices.