examples: Remove legacy code for esp-idf versions < 5.1

This commit is contained in:
Piyush Shah
2025-08-25 19:11:07 +05:30
parent 5536af3487
commit 15922cf7c0
6 changed files with 3 additions and 80 deletions

View File

@@ -7,7 +7,7 @@ variables:
MAKEFLAGS: "-j8 --no-keep-going"
APP_BUILD: "all"
GIT_SUBMODULE_STRATEGY: recursive
ESP_DOCS_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-2"
ESP_DOCS_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.4:1-1"
ESP_DOCS_PATH: "$CI_PROJECT_DIR"
before_script:
@@ -58,11 +58,7 @@ before_script:
- tar -zcvf esp-rainmaker-bins-${CI_JOB_ID}.zip esp-rainmaker-bins-${CI_JOB_ID}/
.build_all_examples: &build_all_examples
- if [[ "$COMPONENT_MGR_142" == "1" ]]; then
- pip install idf-component-manager==1.4.2
- else
- pip install --upgrade idf-component-manager
- fi
- for EXAMPLE in $EXAMPLES; do
- cd $CI_PROJECT_DIR/examples/$EXAMPLE
- echo Building $EXAMPLE
@@ -109,17 +105,9 @@ before_script:
EXTRA_CXXFLAGS: "${PEDANTIC_FLAGS}"
EXAMPLE_TARGETS: "esp32"
EXAMPLES: "switch led_light fan temperature_sensor multi_device gpio homekit_switch"
COMPONENT_MGR_142: "0" # Fix component manager version to 1.4.2
script:
- *build_all_examples
build_idf_v5.0:
extends: .build_template
image: espressif/idf:release-v5.0
variables:
EXAMPLE_TARGETS: "esp32 esp32s2 esp32c3 esp32s3"
COMPONENT_MGR_142: "1"
build_idf_v5.1:
extends: .build_template
image: espressif/idf:release-v5.1

View File

@@ -4,4 +4,4 @@ dependencies:
version: ">=1.0"
override_path: '../../../components/esp_rainmaker/'
espressif/esp_insights:
version: "~1.2.2"
version: "~1.3.0"

View File

@@ -15,7 +15,6 @@ menu "ESP RainMaker App Wi-Fi Provisioning"
Set the maximum wrong pop attempts allowed before stopping provisioning.
Set 0 for the feature to be disabled.
This safeguards the device from brute-force attempt by limiting the wrong pop allowed.
Needs IDF version >= 5.1.3
choice APP_NETWORK_PROV_TRANSPORT
bool "Provisioning Transport method"

View File

@@ -25,11 +25,7 @@
#include <app_thread_internal.h>
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
#include <esp_mac.h>
#else
#include <esp_wifi.h>
#endif
#include <network_provisioning/manager.h>
#ifdef CONFIG_APP_NETWORK_PROV_TRANSPORT_BLE
@@ -70,7 +66,7 @@ static uint64_t prov_timeout_period = (APP_NETWORK_PROV_TIMEOUT_PERIOD * 60 * 10
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 3)
#define APP_PROV_STOP_ON_CREDS_MISMATCH
#elif (CONFIG_APP_NETWOKR_PROV_MAX_RETRY_CNT > 0)
#elif (CONFIG_APP_NETWORK_PROV_MAX_RETRY_CNT > 0)
#warning "Provisioning window stop on max credentials failures, needs IDF version >= 5.1.3"
#endif
@@ -230,11 +226,7 @@ static esp_err_t get_device_service_name(char *service_name, size_t max)
size_t nvs_random_size = 0;
if ((read_random_bytes_from_nvs(&nvs_random, &nvs_random_size) != ESP_OK) || nvs_random_size < 3) {
uint8_t mac_addr[6];
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
esp_read_mac(mac_addr, ESP_MAC_BASE);
#else
esp_wifi_get_mac(WIFI_IF_STA, mac_addr);
#endif
snprintf(service_name, max, "%s_%02x%02x%02x", ssid_prefix, mac_addr[3], mac_addr[4], mac_addr[5]);
} else {
snprintf(service_name, max, "%s_%02x%02x%02x", ssid_prefix, nvs_random[nvs_random_size - 3],
@@ -266,11 +258,7 @@ static char *get_device_pop(app_network_pop_type_t pop_type)
if (pop_type == POP_TYPE_MAC) {
uint8_t mac_addr[6];
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
esp_err_t err = esp_read_mac(mac_addr, ESP_MAC_BASE);
#else
esp_err_t err = esp_wifi_get_mac(WIFI_IF_STA, mac_addr);
#endif
if (err == ESP_OK) {
snprintf(pop, POP_STR_SIZE, "%02x%02x%02x%02x", mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
return pop;

View File

@@ -16,16 +16,7 @@
#include <esp_rmaker_utils.h>
#include <app_network.h>
#include <app_wifi_internal.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
// Features supported in 4.1+
#define ESP_NETIF_SUPPORTED
#endif
#ifdef ESP_NETIF_SUPPORTED
#include <esp_netif.h>
#else
#include <tcpip_adapter.h>
#endif
#include <network_provisioning/manager.h>
#ifdef CONFIG_APP_NETWORK_PROV_TRANSPORT_BLE
@@ -37,11 +28,7 @@
#include <app_wifi_internal.h>
#include <app_network.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 3)
#define APP_PROV_STOP_ON_CREDS_MISMATCH
#elif (CONFIG_APP_NETWORK_PROV_MAX_RETRY_CNT > 0)
#warning "Provisioning window stop on max credentials failures, needs IDF version >= 5.1.3"
#endif
#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI
static const char* TAG = "app_wifi";
@@ -75,13 +62,9 @@ static void event_handler(void* arg, esp_event_base_t event_base,
#ifdef CONFIG_APP_NETWORK_RESET_PROV_ON_FAILURE
retries++;
if (retries >= CONFIG_APP_NETWORK_PROV_MAX_RETRY_CNT) {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 1)
ESP_LOGI(TAG, "Failed to connect with provisioned AP, reseting provisioned credentials");
network_prov_mgr_reset_wifi_sm_state_on_failure();
esp_event_post(APP_NETWORK_EVENT, APP_NETWORK_EVENT_PROV_RESTART, NULL, 0, portMAX_DELAY);
#else
ESP_LOGW(TAG, "Failed to connect with provisioned AP, please reset to provisioning manually");
#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 1)
retries = 0;
}
#endif // CONFIG_APP_NETWORK_RESET_PROV_ON_FAILURE
@@ -115,19 +98,13 @@ esp_err_t wifi_init(void)
{
#ifdef CONFIG_ESP_RMAKER_NETWORK_OVER_WIFI
/* Initialize TCP/IP */
#ifdef ESP_NETIF_SUPPORTED
esp_netif_init();
#else
tcpip_adapter_init();
#endif
/* Register our event handler for Wi-Fi, IP and Provisioning related events */
ESP_ERROR_CHECK(esp_event_handler_register(NETWORK_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
/* Initialize Wi-Fi including netif with default config */
#ifdef ESP_NETIF_SUPPORTED
esp_netif_create_default_wifi_sta();
#endif
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
return ESP_OK;
@@ -173,10 +150,8 @@ esp_err_t wifi_start(const char *pop, const char *service_name, const char *serv
/* If device is not yet provisioned start provisioning service */
if (!(*provisioned)) {
ESP_LOGI(TAG, "Starting provisioning");
#ifdef ESP_NETIF_SUPPORTED
#if CONFIG_ESP_WIFI_SOFTAP_SUPPORT
esp_netif_create_default_wifi_ap();
#endif
#endif
/* What is the security level that we want (0 or 1):
* - NETWORK_PROV_SECURITY_0/WIFI_PROV_SECURITY_0 is simply plain text communication.
@@ -207,7 +182,6 @@ esp_err_t wifi_start(const char *pop, const char *service_name, const char *serv
ESP_LOGE(TAG, "wifi_prov_scheme_ble_set_service_uuid failed %d", err);
return err;
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
if (mfg_data) {
err = network_prov_scheme_ble_set_mfg_data(mfg_data, mfg_data_len);
if (err != ESP_OK) {
@@ -215,7 +189,6 @@ esp_err_t wifi_start(const char *pop, const char *service_name, const char *serv
return err;
}
}
#endif
#endif /* CONFIG_APP_NETWORK_PROV_TRANSPORT_BLE */
/* Start provisioning service */

View File

@@ -13,16 +13,7 @@
#include <esp_event.h>
#include <esp_log.h>
#include <esp_idf_version.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
// Features supported in 4.1+
#define ESP_NETIF_SUPPORTED
#endif
#ifdef ESP_NETIF_SUPPORTED
#include <esp_netif.h>
#else
#include <tcpip_adapter.h>
#endif
#include <wifi_provisioning/manager.h>
#ifdef CONFIG_APP_WIFI_PROV_TRANSPORT_BLE
@@ -216,11 +207,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) {
#ifdef ESP_NETIF_SUPPORTED
esp_netif_create_ip6_linklocal((esp_netif_t *)arg);
#else
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
#endif
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "Connected with IP Address:" IPSTR, IP2STR(&event->ip_info.ip));
@@ -352,27 +339,17 @@ pop_err:
void app_wifi_with_homekit_init(void)
{
/* Initialize TCP/IP */
#ifdef ESP_NETIF_SUPPORTED
esp_netif_init();
#else
tcpip_adapter_init();
#endif
/* Initialize the event loop */
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_event_group = xEventGroupCreate();
/* Initialize Wi-Fi including netif with default config */
#ifdef ESP_NETIF_SUPPORTED
esp_netif_t *wifi_netif = esp_netif_create_default_wifi_sta();
#endif
/* Register our event handler for Wi-Fi, IP and Provisioning related events */
#ifdef ESP_NETIF_SUPPORTED
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, wifi_netif));
#else
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
#endif
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
#ifdef APP_PROV_STOP_ON_CREDS_MISMATCH
ESP_ERROR_CHECK(esp_event_handler_register(PROTOCOMM_SECURITY_SESSION_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
@@ -451,9 +428,7 @@ esp_err_t app_wifi_with_homekit_start(app_wifi_pop_type_t pop_type)
/* If device is not yet provisioned start provisioning service */
if (!provisioned) {
ESP_LOGI(TAG, "Starting provisioning");
#ifdef ESP_NETIF_SUPPORTED
esp_netif_create_default_wifi_ap();
#endif
/* What is the Device Service Name that we want
* This translates to :
* - Wi-Fi SSID when scheme is wifi_prov_scheme_softap