ClavdaClavda

Remote Serial Monitor for an ESP32 with the Arduino IDE

Read an Arduino sketch's serial output in your browser and type commands back to the ESP32, from anywhere, by printing to ClavdaSerial instead of Serial. In C++ or C.

Updated 2 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

Add the Serial Monitor to your sketch

Start the Serial Monitor

In C++, call ClavdaSerial.begin(&Serial) in setup(). Passing &Serial copies everything to the USB port too, so a cable still works when you have one. In C, clavda_serial_begin(115200, 0) does the same, and starts Serial at 115200 baud as well.

Print with ClavdaSerial.print, println and printf wherever you would use Serial. In C, use clavda_serial_printf() and clavda_serial_println().

Handle typed lines

A line typed into the console's Serial Monitor arrives in the callback you give ClavdaSerial.onMessage(), or clavda_serial_on_message() in C.

This program does all three. It prints its uptime every five seconds, and answers status with its free memory:

MySketch.ino
#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. The library's examples include this as cpp/SerialMonitor and c/SerialMonitor.

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.

Next steps