From 28b8dc593ecc170278d372fc7a7fb8408253f155 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Fri, 8 Sep 2023 09:37:56 -0500 Subject: [PATCH 01/11] Example sketch prints MAC for different interfaces Interfaces described in documenation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#mac-address --- .../examples/MacAddress/GetMacAddress.ino | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress.ino new file mode 100644 index 00000000000..48f74539c4c --- /dev/null +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress.ino @@ -0,0 +1,85 @@ +/* + * GetMacAddress + * + * This sketch prints out the MAC addresses for different interfaces. + * + * Written by: Daniel Nebert + * + * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * which returns base MAC address which is factory-programmed by Espressif in EFUSE. + * + * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * and passing in the 'esp_mac_type_t' type. + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * + +enum esp_mac_type_t + + Values: + + enumerator ESP_MAC_WIFI_STA + MAC for WiFi Station (6 bytes) + + enumerator ESP_MAC_WIFI_SOFTAP + MAC for WiFi Soft-AP (6 bytes) + + enumerator ESP_MAC_BT + MAC for Bluetooth (6 bytes) + + enumerator ESP_MAC_ETH + MAC for Ethernet (6 bytes) + + enumerator ESP_MAC_IEEE802154 + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + + enumerator ESP_MAC_BASE + Base MAC for that used for other MAC types (6 bytes) + + enumerator ESP_MAC_EFUSE_FACTORY + MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + + enumerator ESP_MAC_EFUSE_CUSTOM + MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + + enumerator ESP_MAC_EFUSE_EXT + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +void setup() { + Serial.begin(115200); + vTaskDelay(250 / portTICK_PERIOD_MS ); + + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); +} + +void loop() { vTaskDelete(NULL); } + +std::string getDefaultMacAddress() { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} + +std::string getInterfaceMacAddress(esp_mac_type_t interface) { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_read_mac(mac_base, interface) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} From b9b46e2ef37bf02fa708e2a7c06eb078683f36e9 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Fri, 8 Sep 2023 09:43:25 -0500 Subject: [PATCH 02/11] Update README.md to include 'MacAddress' --- libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/README.md b/libraries/README.md index 5edeebba424..3b643ee2dbe 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -33,6 +33,7 @@ arduino-esp32 includes libraries for Arduino compatibility along with some objec * GPIO * HallSensor * I2S + * MacAddress * ResetReason * RMT * Time From de21f3739c2262ec130b05e8990ac800931869d2 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Thu, 14 Sep 2023 08:23:35 -0500 Subject: [PATCH 03/11] Add files via upload --- .../GetMacAddress/GetMacAddress.ino | 85 +++++++++++++++++++ .../MacAddress/GetMacAddress.ino | 85 +++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino create mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino new file mode 100644 index 00000000000..48f74539c4c --- /dev/null +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino @@ -0,0 +1,85 @@ +/* + * GetMacAddress + * + * This sketch prints out the MAC addresses for different interfaces. + * + * Written by: Daniel Nebert + * + * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * which returns base MAC address which is factory-programmed by Espressif in EFUSE. + * + * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * and passing in the 'esp_mac_type_t' type. + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * + +enum esp_mac_type_t + + Values: + + enumerator ESP_MAC_WIFI_STA + MAC for WiFi Station (6 bytes) + + enumerator ESP_MAC_WIFI_SOFTAP + MAC for WiFi Soft-AP (6 bytes) + + enumerator ESP_MAC_BT + MAC for Bluetooth (6 bytes) + + enumerator ESP_MAC_ETH + MAC for Ethernet (6 bytes) + + enumerator ESP_MAC_IEEE802154 + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + + enumerator ESP_MAC_BASE + Base MAC for that used for other MAC types (6 bytes) + + enumerator ESP_MAC_EFUSE_FACTORY + MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + + enumerator ESP_MAC_EFUSE_CUSTOM + MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + + enumerator ESP_MAC_EFUSE_EXT + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +void setup() { + Serial.begin(115200); + vTaskDelay(250 / portTICK_PERIOD_MS ); + + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); +} + +void loop() { vTaskDelete(NULL); } + +std::string getDefaultMacAddress() { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} + +std::string getInterfaceMacAddress(esp_mac_type_t interface) { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_read_mac(mac_base, interface) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino new file mode 100644 index 00000000000..48f74539c4c --- /dev/null +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino @@ -0,0 +1,85 @@ +/* + * GetMacAddress + * + * This sketch prints out the MAC addresses for different interfaces. + * + * Written by: Daniel Nebert + * + * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * which returns base MAC address which is factory-programmed by Espressif in EFUSE. + * + * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * and passing in the 'esp_mac_type_t' type. + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * + +enum esp_mac_type_t + + Values: + + enumerator ESP_MAC_WIFI_STA + MAC for WiFi Station (6 bytes) + + enumerator ESP_MAC_WIFI_SOFTAP + MAC for WiFi Soft-AP (6 bytes) + + enumerator ESP_MAC_BT + MAC for Bluetooth (6 bytes) + + enumerator ESP_MAC_ETH + MAC for Ethernet (6 bytes) + + enumerator ESP_MAC_IEEE802154 + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + + enumerator ESP_MAC_BASE + Base MAC for that used for other MAC types (6 bytes) + + enumerator ESP_MAC_EFUSE_FACTORY + MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + + enumerator ESP_MAC_EFUSE_CUSTOM + MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + + enumerator ESP_MAC_EFUSE_EXT + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +void setup() { + Serial.begin(115200); + vTaskDelay(250 / portTICK_PERIOD_MS ); + + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); +} + +void loop() { vTaskDelete(NULL); } + +std::string getDefaultMacAddress() { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} + +std::string getInterfaceMacAddress(esp_mac_type_t interface) { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_read_mac(mac_base, interface) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} From cb0da308735237bf9290768bc78c098c8a182b32 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Thu, 14 Sep 2023 08:24:00 -0500 Subject: [PATCH 04/11] Delete libraries/ESP32/examples/MacAddress/GetMacAddress.ino --- .../examples/MacAddress/GetMacAddress.ino | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress.ino deleted file mode 100644 index 48f74539c4c..00000000000 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - * GetMacAddress - * - * This sketch prints out the MAC addresses for different interfaces. - * - * Written by: Daniel Nebert - * - * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) - * which returns base MAC address which is factory-programmed by Espressif in EFUSE. - * - * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) - * and passing in the 'esp_mac_type_t' type. - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) - * - -enum esp_mac_type_t - - Values: - - enumerator ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) - - enumerator ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) - - enumerator ESP_MAC_BT - MAC for Bluetooth (6 bytes) - - enumerator ESP_MAC_ETH - MAC for Ethernet (6 bytes) - - enumerator ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) - - enumerator ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) - - enumerator ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) - - enumerator ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) - - enumerator ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) - -*/ - -void setup() { - Serial.begin(115200); - vTaskDelay(250 / portTICK_PERIOD_MS ); - - Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); - Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); - Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); - Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); - Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); -} - -void loop() { vTaskDelete(NULL); } - -std::string getDefaultMacAddress() { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} - -std::string getInterfaceMacAddress(esp_mac_type_t interface) { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_read_mac(mac_base, interface) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} From ed84ff825b3bd3d33b3cb111a04879cc96952259 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Thu, 14 Sep 2023 08:25:42 -0500 Subject: [PATCH 05/11] Delete libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino --- .../GetMacAddress/GetMacAddress.ino | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino deleted file mode 100644 index 48f74539c4c..00000000000 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - * GetMacAddress - * - * This sketch prints out the MAC addresses for different interfaces. - * - * Written by: Daniel Nebert - * - * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) - * which returns base MAC address which is factory-programmed by Espressif in EFUSE. - * - * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) - * and passing in the 'esp_mac_type_t' type. - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) - * - -enum esp_mac_type_t - - Values: - - enumerator ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) - - enumerator ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) - - enumerator ESP_MAC_BT - MAC for Bluetooth (6 bytes) - - enumerator ESP_MAC_ETH - MAC for Ethernet (6 bytes) - - enumerator ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) - - enumerator ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) - - enumerator ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) - - enumerator ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) - - enumerator ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) - -*/ - -void setup() { - Serial.begin(115200); - vTaskDelay(250 / portTICK_PERIOD_MS ); - - Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); - Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); - Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); - Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); - Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); -} - -void loop() { vTaskDelete(NULL); } - -std::string getDefaultMacAddress() { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} - -std::string getInterfaceMacAddress(esp_mac_type_t interface) { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_read_mac(mac_base, interface) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} From d0eac99439e44d653b5efce2acccec7b14c7443d Mon Sep 17 00:00:00 2001 From: dpnebert Date: Thu, 14 Sep 2023 08:26:07 -0500 Subject: [PATCH 06/11] Delete libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress directory --- .../MacAddress/GetMacAddress.ino | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino deleted file mode 100644 index 48f74539c4c..00000000000 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress/MacAddress/GetMacAddress.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - * GetMacAddress - * - * This sketch prints out the MAC addresses for different interfaces. - * - * Written by: Daniel Nebert - * - * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) - * which returns base MAC address which is factory-programmed by Espressif in EFUSE. - * - * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) - * and passing in the 'esp_mac_type_t' type. - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) - * - -enum esp_mac_type_t - - Values: - - enumerator ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) - - enumerator ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) - - enumerator ESP_MAC_BT - MAC for Bluetooth (6 bytes) - - enumerator ESP_MAC_ETH - MAC for Ethernet (6 bytes) - - enumerator ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) - - enumerator ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) - - enumerator ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) - - enumerator ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) - - enumerator ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) - -*/ - -void setup() { - Serial.begin(115200); - vTaskDelay(250 / portTICK_PERIOD_MS ); - - Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); - Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); - Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); - Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); - Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); -} - -void loop() { vTaskDelete(NULL); } - -std::string getDefaultMacAddress() { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} - -std::string getInterfaceMacAddress(esp_mac_type_t interface) { - std::string mac = ""; - unsigned char mac_base[6] = {0}; - if(esp_read_mac(mac_base, interface) == ESP_OK) { - char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator - sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); - mac = buffer; - } - return mac; -} From 3290c9a08df1bbdf100b97d67240ae553585ee64 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Thu, 14 Sep 2023 08:27:11 -0500 Subject: [PATCH 07/11] Add files via upload --- .../GetMacAddress/GetMacAddress.ino | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino new file mode 100644 index 00000000000..48f74539c4c --- /dev/null +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino @@ -0,0 +1,85 @@ +/* + * GetMacAddress + * + * This sketch prints out the MAC addresses for different interfaces. + * + * Written by: Daniel Nebert + * + * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * which returns base MAC address which is factory-programmed by Espressif in EFUSE. + * + * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * and passing in the 'esp_mac_type_t' type. + * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * + +enum esp_mac_type_t + + Values: + + enumerator ESP_MAC_WIFI_STA + MAC for WiFi Station (6 bytes) + + enumerator ESP_MAC_WIFI_SOFTAP + MAC for WiFi Soft-AP (6 bytes) + + enumerator ESP_MAC_BT + MAC for Bluetooth (6 bytes) + + enumerator ESP_MAC_ETH + MAC for Ethernet (6 bytes) + + enumerator ESP_MAC_IEEE802154 + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + + enumerator ESP_MAC_BASE + Base MAC for that used for other MAC types (6 bytes) + + enumerator ESP_MAC_EFUSE_FACTORY + MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + + enumerator ESP_MAC_EFUSE_CUSTOM + MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + + enumerator ESP_MAC_EFUSE_EXT + if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +void setup() { + Serial.begin(115200); + vTaskDelay(250 / portTICK_PERIOD_MS ); + + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); +} + +void loop() { vTaskDelete(NULL); } + +std::string getDefaultMacAddress() { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} + +std::string getInterfaceMacAddress(esp_mac_type_t interface) { + std::string mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_read_mac(mac_base, interface) == ESP_OK) { + char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator + sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); + mac = buffer; + } + return mac; +} From 9ba901d1bb3d10c413157fcd822f4fbfcab19669 Mon Sep 17 00:00:00 2001 From: dpnebert Date: Fri, 15 Sep 2023 15:40:37 -0500 Subject: [PATCH 08/11] Add files via upload --- .../GetMacAddress/GetMacAddress.ino | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino index 48f74539c4c..9741f204ca8 100644 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino @@ -6,80 +6,80 @@ * Written by: Daniel Nebert * * The first printed MAC address is obtained by calling 'esp_efuse_mac_get_default' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv425esp_efuse_mac_get_defaultP7uint8_t) * which returns base MAC address which is factory-programmed by Espressif in EFUSE. * * The remaining printed MAC addresses is obtained by calling 'esp_read_mac' - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t) * and passing in the 'esp_mac_type_t' type. - * (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) + * (https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32/api-reference/system/misc_system_api.html#esp__mac_8h_1a1b19aca597277a2179682869c140477a) * -enum esp_mac_type_t - - Values: - - enumerator ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) - - enumerator ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) +esp_mac_type_t values: - enumerator ESP_MAC_BT - MAC for Bluetooth (6 bytes) + ESP_MAC_WIFI_STA - MAC for WiFi Station (6 bytes) + ESP_MAC_WIFI_SOFTAP - MAC for WiFi Soft-AP (6 bytes) + ESP_MAC_BT - MAC for Bluetooth (6 bytes) + ESP_MAC_ETH - MAC for Ethernet (6 bytes) + ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) + ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) + +*/ + +void setup() { - enumerator ESP_MAC_ETH - MAC for Ethernet (6 bytes) + Serial.begin(115200); + while(!Serial) { delay( 100 ); } - enumerator ESP_MAC_IEEE802154 - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) + Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - enumerator ESP_MAC_BASE - Base MAC for that used for other MAC types (6 bytes) + Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); + Serial.println(getDefaultMacAddress()); - enumerator ESP_MAC_EFUSE_FACTORY - MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) + Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA)); - enumerator ESP_MAC_EFUSE_CUSTOM - MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) + Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP)); - enumerator ESP_MAC_EFUSE_EXT - if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) - -*/ - -void setup() { - Serial.begin(115200); - vTaskDelay(250 / portTICK_PERIOD_MS ); + Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_BT)); - Serial.println("Interface\t\t\t\t\t\tMAC address (6 bytes, 4 universally administered, default)"); - Serial.print("Wi-Fi Station (using 'esp_efuse_mac_get_default')\t"); Serial.println(getDefaultMacAddress().c_str()); - Serial.print("WiFi Station (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_STA).c_str()); - Serial.print("WiFi Soft-AP (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_WIFI_SOFTAP).c_str()); - Serial.print("Bluetooth (using 'esp_read_mac')\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_BT).c_str()); - Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); Serial.println(getInterfaceMacAddress(ESP_MAC_ETH).c_str()); + Serial.print("Ethernet (using 'esp_read_mac')\t\t\t\t"); + Serial.println(getInterfaceMacAddress(ESP_MAC_ETH)); } -void loop() { vTaskDelete(NULL); } +void loop() { /* Nothing in loop */ } -std::string getDefaultMacAddress() { - std::string mac = ""; +String getDefaultMacAddress() { + + String mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_efuse_mac_get_default(mac_base) == ESP_OK) { char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); mac = buffer; } + return mac; } -std::string getInterfaceMacAddress(esp_mac_type_t interface) { - std::string mac = ""; +String getInterfaceMacAddress(esp_mac_type_t interface) { + + String mac = ""; + unsigned char mac_base[6] = {0}; + if(esp_read_mac(mac_base, interface) == ESP_OK) { char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]); mac = buffer; } + return mac; } From 469f9a85e41b595b78a4594e5a0fa1183cddd15e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Nov 2023 13:13:59 -0300 Subject: [PATCH 09/11] Adds necessary MAC header file --- cores/esp32/Arduino.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index 0b0996885af..acff14fbd55 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -40,6 +40,7 @@ #include "stdlib_noniso.h" #include "binary.h" #include "extra_attr.h" +#include "esp_mac.h" // required for "get mac addr" example and code #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 From 2e03b0fdf0e30bf9f8bc67ddfe150683cf0dcb89 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Nov 2023 13:45:57 -0300 Subject: [PATCH 10/11] Reverting - moving to the sketch --- cores/esp32/Arduino.h | 1 - 1 file changed, 1 deletion(-) diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index acff14fbd55..0b0996885af 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -40,7 +40,6 @@ #include "stdlib_noniso.h" #include "binary.h" #include "extra_attr.h" -#include "esp_mac.h" // required for "get mac addr" example and code #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 From 82fbb886e082d4e8eea070ce6304a523298c1397 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Nov 2023 13:47:07 -0300 Subject: [PATCH 11/11] Adds include with esp_mac_type_t values --- .../ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino index 9741f204ca8..b19efca844b 100644 --- a/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino +++ b/libraries/ESP32/examples/MacAddress/GetMacAddress/GetMacAddress.ino @@ -29,6 +29,8 @@ esp_mac_type_t values: */ +#include "esp_mac.h" // required - exposes esp_mac_type_t values + void setup() { Serial.begin(115200);