Diagnostics - a build configuration endpoint
Layer: L7 Application ยท Build flags: PROTOCORE_ENABLE_DIAG
What this example teaches
diag(slot_id) serves a JSON snapshot of which features are enabled and how the buffers are sized. It is handy while developing - one route tells you exactly what the firmware was built with - but because it exposes the build configuration, keep it off (or behind auth) in production.
One call renders the build snapshot:
@ HTTP_GET
Safe, idempotent read.
Every value in the document is a compile-time constant: each feature flag renders as true or false, each sizing constant as a decimal. Nothing is discovered at runtime, so the report cannot drift from the real configuration.
The document itself is a frame spec - a DIAG_DOC table of literal segments interleaved with the values - which diag() fills into 975 bytes borrowed from the plaintext arena, sends, and then releases. If the borrow or the fill fails the route answers 503 with an empty body, so no partial document reaches the wire.
Build and run
pio ci --board=esp32dev --project-option="framework=arduino" \
--project-option="build_flags=-DPROTOCORE_ENABLE_DIAG=1" \
--lib="." examples/L7-Application/Diagnostics/Diagnostics.ino
curl http://<ip>/diag # JSON: enabled features + buffer sizes
Annotated source
The complete sketch (Diagnostics.ino), reproduced verbatim with added explanatory comments:
#define PROTOCORE_ENABLE_DIAG 1
#include "protocore.h"
static const char *SSID = "YOUR_SSID";
static const char *PASSWORD = "YOUR_PASSWORD";
void setup()
{
Serial.begin(115200);
Serial.print("Connecting to WiFi");
{
delay(250);
Serial.print('.');
}
Serial.printf("\nIP: %u.%u.%u.%u\n", (unsigned)(ip & 0xFF), (unsigned)((ip >> 8) & 0xFF),
(unsigned)((ip >> 16) & 0xFF), (unsigned)((ip >> 24) & 0xFF));
begin_http(80);
}
void loop()
{
handle();
}
Layer 1 (Physical) - link bring-up, the interface registry, and live egress reporting.
EMBED_INLINE uint32_t protocore_physical_egress_ipv4(void)
Physical.egress_ip as an expression: the address a sketch prints once its link is up.
EMBED_INLINE embed_bool protocore_physical_wifi_up(void)
Physical.wifi_ready as an expression, for a bring-up loop to wait on.
PhysicalVars PhysicalV
The operands and the outcome.
uint8_t * protocore_physical_span(void)
The PROTOCORE_PHYSICAL_BORROW bytes this module's state lives in.