Layer: L7 Application ยท Build flags: PROTOCORE_ENABLE_PARTITION_MONITOR
What this example teaches
The ESP32's flash is carved into partitions (factory app, OTA slots, NVS, LittleFS, ...). protocore_partition_monitor_begin() serves that table as JSON at /partitions: each entry's label, kind, type/subtype, flash offset, and size, plus which app slot is currently running. It is a one-call diagnostics endpoint that pairs well with OTA dashboards, and it needs no special hardware.
One call mounts the endpoint:
protocore_partition_monitor_begin(server, "/partitions");
The handler reads the partition table from the ESP-IDF API and serializes it directly into the response (no heap).
Build and run
pio ci --board=esp32dev --project-option="framework=arduino" \
--project-option="build_flags=-DPROTOCORE_ENABLE_PARTITION_MONITOR=1" \
--lib="." examples/L7-Application/PartitionMonitor/PartitionMonitor.ino
curl http://<ip>/partitions # JSON: labels, offsets, sizes, running slot
Annotated source
The complete sketch (PartitionMonitor.ino), reproduced verbatim with added explanatory comments:
#define PROTOCORE_ENABLE_PARTITION_MONITOR 1
#include "protocore.h"
static const char *SSID = "YOUR_SSID";
static const char *PASSWORD = "YOUR_PASSWORD";
PC server;
void setup()
{
Serial.begin(115200);
Physical.wifi->init(SSID, PASSWORD);
Serial.print("Connecting to WiFi");
while (!Physical.wifi->ready())
{
delay(250);
Serial.print('.');
}
uint32_t ip = Physical.link->egress_ip();
Serial.printf("IP: %u.%u.%u.%u\n", (unsigned)(ip & 0xFF), (unsigned)((ip >> 8) & 0xFF),
(unsigned)((ip >> 16) & 0xFF), (unsigned)((ip >> 24) & 0xFF));
protocore_partition_monitor_begin(server, "/partitions");
server.begin(80);
}
void loop()
{
server.handle();
}
Flash partition-map monitor (PROTOCORE_ENABLE_PARTITION_MONITOR).
Layer 1 (Physical) - link bring-up, the interface registry, and live egress reporting.