Skip to content

Using it

Add the module to the application’s west.yml, then:

# CMakeLists.txt: generates the tables from the package's files at build time
pkz_manifest(DEVICE package/device.json COMMANDS package/commands.json)
/* The store: the partition labelled pkz_store_partition, or a chosen one. */
/ { chosen { parkeze,store-partition = &pkz_store_partition; }; };
#include <parkeze/pkz.h>
#include "pkz_manifest_gen.h"
static enum pkz_reason mode_set(struct pkz_cmd *cmd, const struct pkz_val *params,
struct pkz_writer *data)
{
char mode[8];
pkz_get_str(params, "mode", mode, sizeof(mode));
/* ... */
pkz_w_str(data, "mode", mode);
return PKZ_OK;
}
PKZ_COMMAND_DEFINE("mode.set", &pkz_schema_cmd_mode_set, mode_set);
int main(void)
{
static const struct pkz_config cfg = { .fw_version = "1.0.0" };
settings_subsys_init();
settings_load();
pkz_init(&cfg);
for (;;) {
pkz_report("cham.t", read_temperature());
k_sleep(K_SECONDS(5));
}
}

Give mbedTLS a heap of 65536 bytes (CONFIG_MBEDTLS_ENABLE_HEAP, CONFIG_MBEDTLS_HEAP_SIZE) with 4096-byte records each way (CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN, _OUT_CONTENT_LEN): the session and a firmware download over HTTPS beside it. 32768 is the least that builds; it covers the session alone.

On the settings file backend (LittleFS), compacting the settings file holds two files open, and enrollment writes enough to compact. Zephyr sizes LittleFS’s file-cache heap as CONFIG_FS_LITTLEFS_NUM_FILES caches of CONFIG_FS_LITTLEFS_CACHE_SIZE (64) bytes, so an fstab cache-size larger than that leaves fewer files than configured, and the compaction fails with -ENOMEM. Set CONFIG_FS_LITTLEFS_CACHE_SIZE to the fstab’s cache size, or CONFIG_FS_LITTLEFS_FC_HEAP_SIZE explicitly.

west pkz manifest runs the generator by hand. Params checks cover the part of JSON Schema the device models (types, string enums, bounds, maxLength, required, nested objects, arrays’ items, minItems and maxItems); the network checks the whole schema before it sends a command.