Zelta/Documentation

Embedded SDK Configuration

Configure the Zelta SDK for your specific requirements.

Configuration Structure

typedef struct {
    // Server connection
    const char *server_url;      // Supabase Edge Function URL
    const char *api_key;         // Your API key
    
    // Device identification
    const char *device_id;       // Unique device identifier
    const char *product_id;      // Product UUID (optional)
    const char *hardware_id;     // Hardware identifier (optional)
    const char *current_version; // Current firmware version
    
    // Callbacks (optional)
    zelta_progress_cb progress_cb;   // Download progress
    zelta_status_cb status_cb;       // Status changes
    
    // Timeouts (milliseconds)
    uint32_t connect_timeout;    // Connection timeout (default: 10000)
    uint32_t download_timeout;   // Per-chunk timeout (default: 30000)
    
    // Buffer sizes
    size_t download_buffer_size; // Download buffer (default: 4096)
    
    // Security
    const uint8_t *public_key_der;  // Public key for signature verification
    size_t public_key_der_len;      // Public key length
} zelta_config_t;

Basic Configuration

#include <zelta/zelta.h>

// Public key from Dashboard (Key Manager → Copy C Array)
static const uint8_t public_key_der[] = {
    0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86,
    // ... rest of key bytes
};

void init_ota(void) {
    zelta_config_t config = {
        .server_url = "https://your-project.supabase.co/functions/v1",
        .api_key = "zk_live_xxxxxxxxxxxx",
        .device_id = get_device_id(),  // Your device ID function
        .current_version = FIRMWARE_VERSION,
        .public_key_der = public_key_der,
        .public_key_der_len = sizeof(public_key_der),
    };
    
    int ret = zelta_init(&config);
    if (ret != ZELTA_OK) {
        LOG_ERR("Failed to init Zelta: %d", ret);
    }
}

Callbacks

Progress Callback

Track download progress:

void on_progress(size_t downloaded, size_t total) {
    int percent = (downloaded * 100) / total;
    LOG_INF("Download progress: %d%%", percent);
    
    // Update LED or display
    update_progress_indicator(percent);
}

// Set callback
config.progress_cb = on_progress;

Status Callback

React to status changes:

void on_status(zelta_status_t status) {
    switch (status) {
        case ZELTA_STATUS_CHECKING:
            LOG_INF("Checking for updates...");
            break;
        case ZELTA_STATUS_DOWNLOADING:
            LOG_INF("Downloading update...");
            break;
        case ZELTA_STATUS_VERIFYING:
            LOG_INF("Verifying firmware...");
            break;
        case ZELTA_STATUS_APPLYING:
            LOG_INF("Applying update...");
            break;
        case ZELTA_STATUS_COMPLETE:
            LOG_INF("Update complete, rebooting...");
            break;
        case ZELTA_STATUS_ERROR:
            LOG_ERR("Update failed!");
            break;
    }
}

// Set callback
config.status_cb = on_status;

Kconfig Options (Zephyr)

# Enable Zelta
CONFIG_ZELTA=y

# Logging level
CONFIG_ZELTA_LOG_LEVEL_DBG=y   # Debug
CONFIG_ZELTA_LOG_LEVEL_INF=y   # Info
CONFIG_ZELTA_LOG_LEVEL_WRN=y   # Warning
CONFIG_ZELTA_LOG_LEVEL_ERR=y   # Error only

# Buffer sizes
CONFIG_ZELTA_DOWNLOAD_BUFFER_SIZE=4096
CONFIG_ZELTA_URL_MAX_LEN=512

# Timeouts
CONFIG_ZELTA_CONNECT_TIMEOUT_MS=10000
CONFIG_ZELTA_DOWNLOAD_TIMEOUT_MS=30000

# Features
CONFIG_ZELTA_SIGNATURE_VERIFICATION=y
CONFIG_ZELTA_AUTOMATIC_ROLLBACK=y

# Thread settings
CONFIG_ZELTA_STACK_SIZE=4096
CONFIG_ZELTA_PRIORITY=10

Device ID Strategies

Choose a unique, persistent device identifier:

Option 1: Hardware ID (Recommended)

#include <zephyr/drivers/hwinfo.h>

char device_id[32];

void get_device_id(void) {
    uint8_t hw_id[16];
    ssize_t len = hwinfo_get_device_id(hw_id, sizeof(hw_id));
    
    // Convert to hex string
    for (int i = 0; i < len && i < 8; i++) {
        sprintf(&device_id[i*2], "%02x", hw_id[i]);
    }
}

Option 2: MAC Address

char device_id[18];

void get_device_id(void) {
    struct net_if *iface = net_if_get_default();
    struct net_linkaddr *link = net_if_get_link_addr(iface);
    
    snprintf(device_id, sizeof(device_id),
             "%02x:%02x:%02x:%02x:%02x:%02x",
             link->addr[0], link->addr[1], link->addr[2],
             link->addr[3], link->addr[4], link->addr[5]);
}

Option 3: Custom Serial Number

// Stored in flash during manufacturing
extern const char serial_number[];

const char *get_device_id(void) {
    return serial_number;
}

TLS Configuration

For secure connections, configure TLS certificates:

# Use system certificates
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_TLS_CREDENTIAL_FILENAMES=y

# Or embed CA certificate
CONFIG_ZELTA_CA_CERT_EMBEDDED=y

Embed CA certificate:

static const char ca_cert[] = 
    "-----BEGIN CERTIFICATE-----\\n"
    "MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhki...\\n"
    "-----END CERTIFICATE-----\\n";

config.ca_cert = ca_cert;
config.ca_cert_len = sizeof(ca_cert);

Next Steps