Expose Wifi RSSI to API endpoint

This commit is contained in:
Erik Olof Gunnar Andersson 2025-02-24 17:39:31 +01:00
parent b92f70d871
commit 2870e336a2
3 changed files with 21 additions and 2 deletions

View File

@ -58,6 +58,20 @@ static bool is_scanning = false;
static uint16_t ap_number = 0;
static wifi_ap_record_t ap_info[MAX_AP_COUNT];
esp_err_t get_wifi_current_rssi(int8_t *rssi)
{
wifi_ap_record_t current_ap_info;
esp_err_t err = esp_wifi_sta_get_ap_info(&current_ap_info);
if (err == ESP_OK) {
*rssi = current_ap_info.rssi;
return ERR_OK;
}
return err;
}
// Function to scan for available WiFi networks
esp_err_t wifi_scan(wifi_ap_record_simple_t *ap_records, uint16_t *ap_count)
{

View File

@ -40,4 +40,5 @@ void wifi_softap_off(void);
void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname, char * ip_addr_str);
EventBits_t wifi_connect(void);
void generate_ssid(char * ssid);
esp_err_t wifi_scan(wifi_ap_record_simple_t *ap_records, uint16_t *ap_count);
esp_err_t wifi_scan(wifi_ap_record_simple_t *ap_records, uint16_t *ap_count);
esp_err_t get_wifi_current_rssi(int8_t *rssi);

View File

@ -534,7 +534,10 @@ static esp_err_t GET_system_info(httpd_req_t * req)
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();
int8_t wifi_rssi = -90;
get_wifi_current_rssi(&wifi_rssi);
cJSON * root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "power", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
cJSON_AddNumberToObject(root, "voltage", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.voltage);
cJSON_AddNumberToObject(root, "current", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.current);
@ -557,6 +560,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddStringToObject(root, "macAddr", formattedMac);
cJSON_AddStringToObject(root, "hostname", hostname);
cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status);
cJSON_AddNumberToObject(root, "wifiRSSI", wifi_rssi);
cJSON_AddNumberToObject(root, "apEnabled", GLOBAL_STATE->SYSTEM_MODULE.ap_enabled);
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected);