mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-31 19:25:14 +02:00
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.
This commit is contained in:
@@ -6,6 +6,7 @@ target_compile_options(${COMPONENT_LIB} PUBLIC -fsanitize=address -fconcepts)
|
|||||||
target_link_options(${COMPONENT_LIB} PUBLIC -fsanitize=address)
|
target_link_options(${COMPONENT_LIB} PUBLIC -fsanitize=address)
|
||||||
|
|
||||||
idf_component_get_property(mqtt mqtt COMPONENT_LIB)
|
idf_component_get_property(mqtt mqtt COMPONENT_LIB)
|
||||||
|
target_compile_definitions(${mqtt} PRIVATE SOC_WIFI_SUPPORTED=1)
|
||||||
target_compile_options(${mqtt} PUBLIC -fsanitize=address -fconcepts)
|
target_compile_options(${mqtt} PUBLIC -fsanitize=address -fconcepts)
|
||||||
target_link_options(${mqtt} PUBLIC -fsanitize=address)
|
target_link_options(${mqtt} PUBLIC -fsanitize=address)
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_mac.h"
|
#include "esp_mac.h"
|
||||||
|
#include "soc/soc_caps.h"
|
||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
#include "esp_random.h"
|
#include "esp_random.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -12,12 +13,19 @@ static const char *TAG = "platform";
|
|||||||
|
|
||||||
#define MAX_ID_STRING (32)
|
#define MAX_ID_STRING (32)
|
||||||
|
|
||||||
|
#if defined SOC_WIFI_SUPPORTED
|
||||||
|
#define MAC_TYPE ESP_MAC_WIFI_STA
|
||||||
|
#elif defined SOC_EMAC_SUPPORTED
|
||||||
|
#define MAC_TYPE ESP_MAC_ETH
|
||||||
|
#elif defined SOC_IEEE802154_SUPPORTED
|
||||||
|
#define MAC_TYPE ESP_MAC_IEEE802154
|
||||||
|
#endif
|
||||||
char *platform_create_id_string(void)
|
char *platform_create_id_string(void)
|
||||||
{
|
{
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
char *id_string = calloc(1, MAX_ID_STRING);
|
char *id_string = calloc(1, MAX_ID_STRING);
|
||||||
ESP_MEM_CHECK(TAG, id_string, return NULL);
|
ESP_MEM_CHECK(TAG, id_string, return NULL);
|
||||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
esp_read_mac(mac, MAC_TYPE);
|
||||||
sprintf(id_string, "ESP32_%02x%02X%02X", mac[3], mac[4], mac[5]);
|
sprintf(id_string, "ESP32_%02x%02X%02X", mac[3], mac[4], mac[5]);
|
||||||
return id_string;
|
return id_string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user