Skip to content

Commit 657a2ae

Browse files
fix: Make automatic client_id soc dependent
When creating the client_id for user, the library uses the device MAC. For some of our devices WIFI isn't available and the library needs to select a different MAC to use.
1 parent fa88da5 commit 657a2ae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

host_test/main/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ target_compile_options(${COMPONENT_LIB} PUBLIC -fsanitize=address -fconcepts)
66
target_link_options(${COMPONENT_LIB} PUBLIC -fsanitize=address)
77

88
idf_component_get_property(mqtt mqtt COMPONENT_LIB)
9+
target_compile_definitions(${mqtt} PRIVATE SOC_WIFI_SUPPORTED=1)
910
target_compile_options(${mqtt} PUBLIC -fsanitize=address -fconcepts)
1011
target_link_options(${mqtt} PUBLIC -fsanitize=address)
1112

1213
if(CONFIG_GCOV_ENABLED)
1314
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
1415
target_link_options(${COMPONENT_LIB} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
15-
16+
1617
idf_component_get_property(mqtt mqtt COMPONENT_LIB)
1718
target_compile_options(${mqtt} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
1819
target_link_options(${mqtt} PUBLIC --coverage -fprofile-arcs -ftest-coverage)

lib/platform_esp32_idf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifdef ESP_PLATFORM
44
#include "esp_log.h"
55
#include "esp_mac.h"
6+
#include "soc/soc_caps.h"
67
#include "esp_timer.h"
78
#include "esp_random.h"
89
#include <stdlib.h>
@@ -12,12 +13,19 @@ static const char *TAG = "platform";
1213

1314
#define MAX_ID_STRING (32)
1415

16+
#if defined SOC_WIFI_SUPPORTED
17+
#define MAC_TYPE ESP_MAC_WIFI_STA
18+
#elif defined SOC_EMAC_SUPPORTED
19+
#define MAC_TYPE ESP_MAC_ETH
20+
#elif defined SOC_IEEE802154_SUPPORTED
21+
#define MAC_TYPE ESP_MAC_IEEE802154
22+
#endif
1523
char *platform_create_id_string(void)
1624
{
1725
uint8_t mac[6];
1826
char *id_string = calloc(1, MAX_ID_STRING);
1927
ESP_MEM_CHECK(TAG, id_string, return NULL);
20-
esp_read_mac(mac, ESP_MAC_WIFI_STA);
28+
esp_read_mac(mac, MAC_TYPE);
2129
sprintf(id_string, "ESP32_%02x%02X%02X", mac[3], mac[4], mac[5]);
2230
return id_string;
2331
}

0 commit comments

Comments
 (0)