Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Wifi RSSI to API endpoint #739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions components/connect/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion components/connect/include/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 5 additions & 1 deletion main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading