From c2f34aa823c0c1c1e068b8bf1430ba7c63740e51 Mon Sep 17 00:00:00 2001 From: Brett Rowan <121075405+b-rowan@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:12:08 -0600 Subject: [PATCH] Add MAC address to API. (#295) --- main/http_server/http_server.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index 7c589608..f49de69d 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -7,6 +7,7 @@ #include "esp_random.h" #include "esp_spiffs.h" #include "esp_timer.h" +#include "esp_wifi.h" #include "esp_vfs.h" #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" @@ -365,12 +366,18 @@ static esp_err_t GET_system_info(httpd_req_t * req) return ESP_FAIL; } + char * ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, CONFIG_ESP_WIFI_SSID); char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, CONFIG_LWIP_LOCAL_HOSTNAME); + uint8_t mac[6]; + char formattedMac[18]; char * stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL); char * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER); char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "unknown"); + esp_wifi_get_mac(WIFI_IF_STA, mac); + snprintf(formattedMac, 18, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + cJSON * root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "power", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power); cJSON_AddNumberToObject(root, "voltage", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.voltage); @@ -386,6 +393,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "coreVoltageActual", VCORE_get_voltage_mv(GLOBAL_STATE)); cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); cJSON_AddStringToObject(root, "ssid", ssid); + cJSON_AddStringToObject(root, "macAddr", formattedMac); cJSON_AddStringToObject(root, "hostname", hostname); cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status); cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);