Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/esp-idf/ota-demo/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void app_main(void)
.schema = NULL,
.schema_id = NULL,
.dp_state = NULL,
.sw_ver = desc->version,
};
memcpy((char *)iot_cfg.devid, DEFAULT_DEVID, strlen(DEFAULT_DEVID));
memcpy((char *)iot_cfg.secret_key, DEFAULT_SECRET_KEY, strlen(DEFAULT_SECRET_KEY));
Expand All @@ -317,7 +318,7 @@ void app_main(void)

/* 3. Check cloud for firmware upgrade */
iot_ota_upgrade_info_t info = {0};
int rc = iot_ota_check_upgrade(iot, 0, desc->version, &info);
int rc = iot_ota_check_upgrade(iot, 0, &info);
if (rc != OPRT_OK) {
ESP_LOGE(TAG, "iot_ota_check_upgrade failed: %d", rc);
iot_ota_upgrade_info_free(iot, &info);
Expand Down
4 changes: 2 additions & 2 deletions examples/esp-idf/ota-demo/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
otadata, data, ota, 0x10000, 0x2000,
ota_0, app, ota_0, 0x20000, 1500K,
ota_1, app, ota_1, , 1500K,
ota_0, app, ota_0, 0x20000, 4M,
ota_1, app, ota_1, , 4M,
2 changes: 1 addition & 1 deletion examples/esp-idf/ota-demo/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OTA needs enough stack for TLS + HTTP + esp_ota writes
CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384
CONFIG_MBEDTLS_HKDF_C=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_SPIRAM=y
Expand Down
23 changes: 7 additions & 16 deletions examples/posix/ota-demo/ota_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int demo_ota_run(const char *devid, const char *secret_key, const char *local_ke
.env = PROD,
.mqtt_disable_tls = false,
.mqtt_auto_connect = false,
.sw_ver = sw_ver,
};
strncpy(cfg.devid, devid, sizeof(cfg.devid) - 1);
strncpy(cfg.secret_key, secret_key, sizeof(cfg.secret_key) - 1);
Expand All @@ -108,22 +109,12 @@ int demo_ota_run(const char *devid, const char *secret_key, const char *local_ke
fprintf(stderr, "[%s] iot_client_init failed\n", TAG);
return -1;
}
printf("[%s] client initialized (devid=%s)\n", TAG, client->devid);
printf("[%s] client initialized (devid=%s, sw_ver=%s)\n", TAG, client->devid, sw_ver);

/* 2. Report current firmware version */
printf("[%s] reporting firmware version: %s\n", TAG, sw_ver);
int rc = iot_ota_report_version(client, sw_ver);
if (rc != OPRT_OK) {
fprintf(stderr, "[%s] iot_ota_report_version failed: %d\n", TAG, rc);
/* non-fatal — continue to upgrade check */
} else {
printf("[%s] version reported successfully\n", TAG);
}

/* 3. Check for firmware upgrade */
/* 2. Check for firmware upgrade */
printf("[%s] checking cloud for firmware upgrade...\n", TAG);
iot_ota_upgrade_info_t info = {0};
rc = iot_ota_check_upgrade(client, 0, sw_ver, &info);
int rc = iot_ota_check_upgrade(client, 0, &info);
if (rc != OPRT_OK) {
fprintf(stderr, "[%s] iot_ota_check_upgrade failed: %d\n", TAG, rc);
iot_ota_upgrade_info_free(client, &info);
Expand All @@ -138,7 +129,7 @@ int demo_ota_run(const char *devid, const char *secret_key, const char *local_ke
return 0;
}

/* 4. Print upgrade info */
/* 3. Print upgrade info */
printf("[%s] ===== firmware upgrade available =====\n", TAG);
printf("[%s] version : %s\n", TAG, info.version ? info.version : "?");
printf("[%s] url : %s\n", TAG, info.url);
Expand All @@ -147,14 +138,14 @@ int demo_ota_run(const char *devid, const char *secret_key, const char *local_ke
printf("[%s] md5 : %s\n", TAG, info.md5 ? info.md5 : "(none)");
printf("[%s] hmac : %s\n", TAG, info.hmac ? info.hmac : "(none)");

/* 5. Report UPGRADING status */
/* 4. Report UPGRADING status */
printf("[%s] reporting UPGRADING status...\n", TAG);
rc = iot_ota_report_status(client, info.channel, OTA_STATUS_UPGRADING);
if (rc != OPRT_OK) {
fprintf(stderr, "[%s] failed to report UPGRADING: %d\n", TAG, rc);
}

/* 6. Optionally download the firmware image */
/* 5. Optionally download the firmware image */
int result = 0;
if (auto_download && info.url) {
char out_path[256];
Expand Down
2 changes: 2 additions & 0 deletions modules/iot-client/include/iot_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef struct {
const char *schema; // Persisted DP schema JSON to restore on restart (NULL = none / loose mode)
const char *schema_id; // Persisted schema id (stable key for schema upgrade query)
const char *dp_state; // Persisted DP current state {"dps":{...}} to restore (no dirty, no report)
const char *sw_ver; // Application firmware version (e.g. "1.2.3"); NULL = use SDK default IOT_SDK_SW_VER
} iot_client_config_t;

/**
Expand All @@ -121,6 +122,7 @@ typedef struct {
const char *cacert; // CA cert for all TLS (MQTT/HTTPS/IoT-DNS) (PEM, caller-owned, must outlive client)
tls_cert_bundle_attach_fn cert_bundle_attach; // Platform cert-bundle callback (NULL = none)
iot_message_callback_t message_callback; // MQTT message callback
const char *sw_ver; // Application firmware version (e.g. "1.2.3"); NULL = use SDK default IOT_SDK_SW_VER
} iot_on_boarding_config_t;


Expand Down
3 changes: 0 additions & 3 deletions modules/iot-client/include/iot_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,11 @@ OTA_API int iot_ota_report_version(iot_client_t *client, const char *sw_ver);
*
* @param[in] client IoT client instance (must be initialized)
* @param[in] channel Firmware channel (0 = main MCU firmware)
* @param[in] sw_ver Current firmware version string sent to cloud for
* comparison (e.g. "1.0.0"); pass NULL to omit
* @param[out] info Output: upgrade info (caller must free with
* iot_ota_upgrade_info_free())
* @return OPRT_OK on success (including no-upgrade case), error code on failure
*/
OTA_API int iot_ota_check_upgrade(iot_client_t *client, int channel,
const char *sw_ver,
iot_ota_upgrade_info_t *info);

/**
Expand Down
3 changes: 0 additions & 3 deletions modules/iot-client/src/atop.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,6 @@ int atop_upgrade_get(const pal_t *pal, const ota_upgrade_request_t *request, ota
return OPRT_MALLOC_FAILED;
}
cJSON_AddNumberToObject(root, "type", request->channel);
if (request->sw_ver && request->sw_ver[0] != '\0') {
cJSON_AddStringToObject(root, "softVer", request->sw_ver);
}
cJSON_AddNumberToObject(root, "t", (double)timestamp);

char *post_data = cJSON_PrintUnformatted(root);
Expand Down
1 change: 0 additions & 1 deletion modules/iot-client/src/atop.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ typedef struct {
const char *devid;
const char *key;
int channel; /**< firmware type/channel (0 = main MCU) */
const char *sw_ver; /**< current firmware version (sent as softVer for server-side comparison) */
const char *host;
uint16_t port;
const char *cacert;
Expand Down
17 changes: 14 additions & 3 deletions modules/iot-client/src/iot_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ IOT_API iot_client_t *iot_client_init(const iot_client_config_t *config)

/* Report firmware version to cloud (enables OTA upgrade checks) */
{
int ret = iot_ota_report_version(client, IOT_SDK_SW_VER);
const char *fw_ver = (config->sw_ver && config->sw_ver[0])
? config->sw_ver
: IOT_SDK_SW_VER;
int ret = iot_ota_report_version(client, fw_ver);
if (ret != OPRT_OK) {
log_warn("iot_ota_report_version failed: %d (non-fatal)", ret);
}
Expand Down Expand Up @@ -325,7 +328,10 @@ IOT_API iot_client_t *iot_client_init_on_boarding(const iot_on_boarding_config_t
strncpy(ob_cfg.authkey, config->authkey, sizeof(ob_cfg.authkey) - 1);
strncpy(ob_cfg.product_key, config->product_key, sizeof(ob_cfg.product_key) - 1);

strncpy(ob_cfg.sw_ver, IOT_SDK_SW_VER, sizeof(ob_cfg.sw_ver) - 1);
const char *sw_ver = (config->sw_ver && config->sw_ver[0])
? config->sw_ver
: IOT_SDK_SW_VER;
strncpy(ob_cfg.sw_ver, sw_ver, sizeof(ob_cfg.sw_ver) - 1);
strncpy(ob_cfg.pv, IOT_SDK_PV, sizeof(ob_cfg.pv) - 1);
strncpy(ob_cfg.bv, IOT_SDK_BV, sizeof(ob_cfg.bv) - 1);

Expand Down Expand Up @@ -365,6 +371,7 @@ IOT_API iot_client_t *iot_client_init_on_boarding(const iot_on_boarding_config_t
client_config.cacert = config->cacert;
client_config.cert_bundle_attach = config->cert_bundle_attach;
client_config.message_callback = config->message_callback;
client_config.sw_ver = sw_ver;
/* schema / schema_id come from the activation response. iot_client_init()
* copies them and rebuilds the DP registry from the schema (dp_state is then
* initialized from the schema); first activation has no persisted DP values. */
Expand Down Expand Up @@ -416,7 +423,10 @@ IOT_API iot_client_t *iot_client_init_on_boarding_with_token(const iot_on_boardi
strncpy(ob_cfg.authkey, config->authkey, sizeof(ob_cfg.authkey) - 1);
strncpy(ob_cfg.product_key, config->product_key, sizeof(ob_cfg.product_key) - 1);

strncpy(ob_cfg.sw_ver, IOT_SDK_SW_VER, sizeof(ob_cfg.sw_ver) - 1);
const char *sw_ver = (config->sw_ver && config->sw_ver[0])
? config->sw_ver
: IOT_SDK_SW_VER;
strncpy(ob_cfg.sw_ver, sw_ver, sizeof(ob_cfg.sw_ver) - 1);
strncpy(ob_cfg.pv, IOT_SDK_PV, sizeof(ob_cfg.pv) - 1);
strncpy(ob_cfg.bv, IOT_SDK_BV, sizeof(ob_cfg.bv) - 1);

Expand Down Expand Up @@ -453,6 +463,7 @@ IOT_API iot_client_t *iot_client_init_on_boarding_with_token(const iot_on_boardi
client_config.cacert = config->cacert;
client_config.cert_bundle_attach = config->cert_bundle_attach;
client_config.message_callback = config->message_callback;
client_config.sw_ver = sw_ver;
/* schema / schema_id come from the activation response. iot_client_init()
* copies them and rebuilds the DP registry from the schema (dp_state is then
* initialized from the schema); first activation has no persisted DP values. */
Expand Down
6 changes: 6 additions & 0 deletions modules/iot-client/src/iot_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@

#define IOT_DEFAULT_PORT 443

#ifndef IOT_SDK_SW_VER
#define IOT_SDK_SW_VER "1.0.0"
#endif
#ifndef IOT_SDK_PV
#define IOT_SDK_PV "2.3"
#endif
#ifndef IOT_SDK_BV
#define IOT_SDK_BV "2.0"
#endif
#define SDK_VERSION "agentic-kit_0.1.0"

/**
Expand Down
3 changes: 1 addition & 2 deletions modules/iot-client/src/iot_ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int iot_ota_report_version(iot_client_t *client, const char *sw_ver)
return atop_version_update(client->pal, &req);
}

int iot_ota_check_upgrade(iot_client_t *client, int channel, const char *sw_ver,
int iot_ota_check_upgrade(iot_client_t *client, int channel,
iot_ota_upgrade_info_t *info)
{
if (client == NULL || info == NULL) {
Expand All @@ -58,7 +58,6 @@ int iot_ota_check_upgrade(iot_client_t *client, int channel, const char *sw_ver,
.devid = client->devid,
.key = client->secret_key,
.channel = channel,
.sw_ver = sw_ver,
.host = host[0] ? host : NULL,
.port = port,
.cacert = client->cacert,
Expand Down
1 change: 0 additions & 1 deletion modules/iot-client/test/iot_ota_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ static int test_upgrade_get_with_upgrade(void)
.devid = TEST_DEVID,
.key = TEST_SEC_KEY,
.channel = 0,
.sw_ver = "1.0.0",
.host = MOCK_HOST,
.port = MOCK_PORT,
.cacert = g_cacert,
Expand Down
Loading