|
ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
|
Layer: L7 Application ยท Build flags: PROTOCORE_ENABLE_HTTP_CLIENT
So far the device has been a server; here it is a client. http_get(url, &r) performs a blocking GET over raw lwIP (with client-side mbedTLS for https://), for webhooks, telemetry push, or REST calls out to a remote service. The host is resolved via DNS (or used directly if it is a dotted-quad IP) and the response status and body land in a fixed static buffer (no heap).
One blocking call, result in a static struct:
The return value is negative on a transport-level failure; on success r.status holds the HTTP status code and r.body/r.body_len the (bounded) body.
TLS trust. https:// is encrypt-only by default - the device has no trust store, so the peer is unauthenticated. To authenticate the server, install a CA trust anchor with http_client_set_ca(pem, len) (verifies chain + hostname) and/or a SHA-256 certificate pin with http_client_set_pin(hash32); call once before issuing requests, and a verification failure aborts the request.
http:// only - an https:// URL is refused with HTTP_CLIENT_ERR_TLS, because the library ships no client-side TLS engine. The sketch fetches URL once at boot and prints the result to Serial @ 115200.
The complete sketch (HttpClient.ino), reproduced verbatim with added explanatory comments: