From 0f35e48fe52f51ae60f105b3af292247db54add8 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Tue, 6 May 2025 11:32:11 +0300 Subject: [PATCH] feat: added get mac address --- README.md | 5 ++++- include/zh_espnow.h | 11 ++++++++++- version.txt | 2 +- zh_espnow.c | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c9a617..0b218e0 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,11 @@ void app_main(void) strcpy(send_message.char_value, "THIS IS A CHAR"); send_message.float_value = 1.234; send_message.bool_value = false; - printf("Used ESP-NOW version %d.\n", zh_espnow_get_version()); + printf("ESP-NOW version %d.\n", zh_espnow_get_version()); printf("ESP-NOW channel %d. \n", zh_espnow_get_channel()); + uint8_t node_mac[6] = {0}; + zh_espnow_get_mac(node_mac); + printf("ESP-NOW MAC %02X:%02X:%02X:%02X:%02X:%02X.\n", MAC2STR(node_mac)); uint8_t counter = 0; for (;;) { diff --git a/include/zh_espnow.h b/include/zh_espnow.h index 32c1aba..672bf81 100644 --- a/include/zh_espnow.h +++ b/include/zh_espnow.h @@ -171,13 +171,22 @@ extern "C" * @brief Set battery mode. * * @param[in] battery_mode True to enable the mode false to disable it. - * + * * @note If true the node does not receive messages. * * @return ESP_OK if success or an error code otherwise. */ esp_err_t zh_espnow_set_battery_mode(bool battery_mode); + /** + * @brief Get MAC address of the node. + * + * @param[out] mac_addr Pointer to a buffer containing an eight-byte MAC. + * + * @return ESP_OK if success or an error code otherwise. + */ + esp_err_t zh_espnow_get_mac(uint8_t *mac_addr); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/version.txt b/version.txt index ce6a70b..9dbb0c0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.6.0 \ No newline at end of file +1.7.0 \ No newline at end of file diff --git a/zh_espnow.c b/zh_espnow.c index d17030a..91fa574 100755 --- a/zh_espnow.c +++ b/zh_espnow.c @@ -592,4 +592,9 @@ esp_err_t zh_espnow_set_battery_mode(bool battery_mode) _init_config.battery_mode = battery_mode; ZH_ESPNOW_LOGI("Battery mode set successfully."); return ESP_OK; +} + +esp_err_t zh_espnow_get_mac(uint8_t *mac_addr) +{ + return esp_wifi_get_mac(_init_config.wifi_interface, mac_addr); } \ No newline at end of file