diff --git a/examples/esp-idf/ota-demo/main/main.c b/examples/esp-idf/ota-demo/main/main.c index 8992a69..98eac4e 100644 --- a/examples/esp-idf/ota-demo/main/main.c +++ b/examples/esp-idf/ota-demo/main/main.c @@ -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)); @@ -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); diff --git a/examples/esp-idf/ota-demo/partitions.csv b/examples/esp-idf/ota-demo/partitions.csv index 49f98a9..3def8c8 100644 --- a/examples/esp-idf/ota-demo/partitions.csv +++ b/examples/esp-idf/ota-demo/partitions.csv @@ -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, diff --git a/examples/esp-idf/ota-demo/sdkconfig.defaults b/examples/esp-idf/ota-demo/sdkconfig.defaults index 789aa72..f382ba8 100644 --- a/examples/esp-idf/ota-demo/sdkconfig.defaults +++ b/examples/esp-idf/ota-demo/sdkconfig.defaults @@ -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 diff --git a/examples/posix/ota-demo/ota_demo.c b/examples/posix/ota-demo/ota_demo.c index 7bf7158..69ef604 100644 --- a/examples/posix/ota-demo/ota_demo.c +++ b/examples/posix/ota-demo/ota_demo.c @@ -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); @@ -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); @@ -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); @@ -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]; diff --git a/modules/iot-client/include/iot_client.h b/modules/iot-client/include/iot_client.h index f5e4085..d29d662 100644 --- a/modules/iot-client/include/iot_client.h +++ b/modules/iot-client/include/iot_client.h @@ -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; /** @@ -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; diff --git a/modules/iot-client/include/iot_ota.h b/modules/iot-client/include/iot_ota.h index 2bd557c..4b376b4 100644 --- a/modules/iot-client/include/iot_ota.h +++ b/modules/iot-client/include/iot_ota.h @@ -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); /** diff --git a/modules/iot-client/src/atop.c b/modules/iot-client/src/atop.c index 8e0fb27..35f8a22 100644 --- a/modules/iot-client/src/atop.c +++ b/modules/iot-client/src/atop.c @@ -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); diff --git a/modules/iot-client/src/atop.h b/modules/iot-client/src/atop.h index 6e4a157..a375ba4 100644 --- a/modules/iot-client/src/atop.h +++ b/modules/iot-client/src/atop.h @@ -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; diff --git a/modules/iot-client/src/iot_client.c b/modules/iot-client/src/iot_client.c index 4be2685..513cd57 100644 --- a/modules/iot-client/src/iot_client.c +++ b/modules/iot-client/src/iot_client.c @@ -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); } @@ -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); @@ -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. */ @@ -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); @@ -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. */ diff --git a/modules/iot-client/src/iot_config_defaults.h b/modules/iot-client/src/iot_config_defaults.h index 49b9405..76507a4 100644 --- a/modules/iot-client/src/iot_config_defaults.h +++ b/modules/iot-client/src/iot_config_defaults.h @@ -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" /** diff --git a/modules/iot-client/src/iot_ota.c b/modules/iot-client/src/iot_ota.c index 6307682..6f81d76 100644 --- a/modules/iot-client/src/iot_ota.c +++ b/modules/iot-client/src/iot_ota.c @@ -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) { @@ -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, diff --git a/modules/iot-client/test/iot_ota_test.c b/modules/iot-client/test/iot_ota_test.c index fd3700c..e60b040 100644 --- a/modules/iot-client/test/iot_ota_test.c +++ b/modules/iot-client/test/iot_ota_test.c @@ -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,