CropPath for developers

All guides

C++ SDK

Available

A C++ wrapper over the C device SDK.

A header-only C++17 wrapper over the C SDK, for device firmware and gateway software written in C++. The C SDK still produces every byte that is signed and sent, so a C++ device's frames are the C SDK's frames. The wrapper adds owning types, C++ interfaces in place of C function pointers, and Status / Result<T> errors; unlike the C SDK, it allocates. It works with and without exceptions (-fno-exceptions, the ESP-IDF default). It builds and sends device envelopes; it is not a client of the HTTP API.

Download both source archives, croppath-cpp-0.3.0.tar.gz (the C++ wrapper) and croppath-c-0.3.0.tar.gz (the C SDK it links), with their .sha256 files from this portal's Downloads page (/developers/downloads), check their SHA-256 and unpack them as below. CropPath distributes its SDKs only through this portal, not through public package registries. Add the C SDK's core files (and its mbedTLS backend for MbedtlsKey, which needs mbedTLS 3.6 or later, so ESP-IDF 5.3 or later) and both include directories to your build, with C++17 or later.

for f in croppath-cpp-0.3.0.tar.gz croppath-c-0.3.0.tar.gz; do
  curl -fLO https://txng.theio.vn/developers/downloads/sdk/$f && curl -fLO https://txng.theio.vn/developers/downloads/sdk/$f.sha256 && sha256sum -c $f.sha256 && tar xzf $f
done                                            # macOS: shasum -a 256 -c instead of sha256sum -c
#include "agritrace/agritrace.hpp"
#include "agritrace/agritrace_mbedtls.hpp"

using namespace agritrace;

MbedtlsKey key(platform_rng, nullptr);   // at_rng_fn of the platform
// key.load(private_key) from secure storage, or key.generate() on first boot and register key.public_key()

ClientConfig cfg;
cfg.tenant = "coop-1";
cfg.site = "ph-1";
cfg.device_id = "knk-1";
cfg.profile = "vn.agritrace.durian-knocker@1.3.0";
cfg.kid = "knk-1-key";
cfg.signer = &key;                       // not owned: must outlive the client
cfg.storage = &storage;                  // a Storage, e.g. CStorage over the C port of your flash
cfg.transport = [&](std::string_view route, std::string_view frame) -> Status {
    int http = post("/v1/ingest/" + std::string(route), frame);
    if ((http >= 200 && http < 300) || http == 409) return {};       // stored, or already stored
    if (http == 0 || http == 408 || http == 429 || http >= 500) return Errc::retry;
    return Errc::rejected;
};
Result<Client> client = Client::open(cfg);
if (!client) return client.status();     // or client.value(), which throws agritrace::Error

Message m;
m.kind(Kind::event)
    .event_type("inspect")
    .context("lot", lot_id)
    .reading(Reading("produce.maturity_index", Value::decimal(825, 1)).unit("%"));
Result<Emitted> e = client->emit(m);     // signed and stored in the outbox; nothing is sent yet
Result<Flushed> f = client->flush();     // f->retry_later: the link failed, the frame stays queued

Your Signer, Storage, transport, clock and on_rejected may throw: the exception never crosses the C code; the C SDK sees a failure code and keeps its state consistent, and the exception is rethrown when the C call returns. A Client is not thread-safe. Not verified yet: a build with a device toolchain (ESP-IDF, STM32Cube) and a 32-bit build; the tests run on a 64-bit Linux host.

In the API reference