wifi web interface scan implemented
This commit is contained in:
parent
111839f329
commit
82a2328571
|
|
@ -50,6 +50,8 @@ QueueHandle_t MQTT1MessagesQueueHandle;
|
||||||
QueueHandle_t MQTT2MessagesQueueHandle;
|
QueueHandle_t MQTT2MessagesQueueHandle;
|
||||||
EventGroupHandle_t transport_event_group;
|
EventGroupHandle_t transport_event_group;
|
||||||
|
|
||||||
|
wifi_ap_record_t* GetWiFiAPRecord(uint8_t n);
|
||||||
|
|
||||||
void StartTimeGet(void);
|
void StartTimeGet(void);
|
||||||
|
|
||||||
void WiFiAPStart(void);
|
void WiFiAPStart(void);
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,14 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (httpd_query_key_value(PostData, "wifisc", tmp, 4) == ESP_OK)
|
||||||
|
{
|
||||||
|
if (!strcmp(tmp, (const char*) "prs"))
|
||||||
|
{
|
||||||
|
WiFiScan();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK ||
|
if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK ||
|
||||||
httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
|
httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -182,15 +182,14 @@ static void HTTPPrint_fver(char *VarData, void *arg)
|
||||||
|
|
||||||
static void HTTPPrint_fverav(char *VarData, void *arg)
|
static void HTTPPrint_fverav(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetAvailVersion());
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetAvailVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HTTPPrint_updstat(char *VarData, void *arg)
|
static void HTTPPrint_updstat(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetUpdateStatus());
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetUpdateStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void HTTPPrint_idfver(char *VarData, void *arg)
|
static void HTTPPrint_idfver(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
esp_app_desc_t cur_app_info;
|
esp_app_desc_t cur_app_info;
|
||||||
|
|
@ -347,6 +346,15 @@ static void HTTPPrint_apmacadr(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
PrintMACFromInterface(VarData, arg, GetAPNetifAdapter());
|
PrintMACFromInterface(VarData, arg, GetAPNetifAdapter());
|
||||||
}
|
}
|
||||||
|
static void HTTPPrint_wifisc(char *VarData, void *arg)
|
||||||
|
{
|
||||||
|
wifi_ap_record_t *R = GetWiFiAPRecord(*(uint8_t*) (arg));
|
||||||
|
if (!R)
|
||||||
|
return;
|
||||||
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "{\"ssid\":\"%s\",\"rssi\":%i,\"ch\":%d}", R->ssid, R->rssi,
|
||||||
|
R->primary);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
||||||
|
|
@ -481,7 +489,6 @@ void HTTPPrint_gsmmac(char *VarData, void *arg)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_WEBGUIAPP_LORAWAN_ENABLE
|
#ifdef CONFIG_WEBGUIAPP_LORAWAN_ENABLE
|
||||||
/*LORAWAN settings*/
|
/*LORAWAN settings*/
|
||||||
void HTTPPrint_lren(char *VarData, void *arg)
|
void HTTPPrint_lren(char *VarData, void *arg)
|
||||||
|
|
@ -639,7 +646,7 @@ static void HTTPPrint_hide_mqtt2(char *VarData, void *arg)
|
||||||
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
|
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, " ");
|
snprintf(VarData, MAX_DYNVAR_LENGTH, " ");
|
||||||
#else
|
#else
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "hide");
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "hide");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -695,7 +702,6 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
|
||||||
{ "fverav", sizeof("fverav") - 1, &HTTPPrint_fverav },
|
{ "fverav", sizeof("fverav") - 1, &HTTPPrint_fverav },
|
||||||
{ "updstat", sizeof("updstat") - 1, &HTTPPrint_updstat },
|
{ "updstat", sizeof("updstat") - 1, &HTTPPrint_updstat },
|
||||||
|
|
||||||
|
|
||||||
{ "idfver", sizeof("idfver") - 1, &HTTPPrint_idfver },
|
{ "idfver", sizeof("idfver") - 1, &HTTPPrint_idfver },
|
||||||
{ "builddate", sizeof("builddate") - 1, &HTTPPrint_builddate },
|
{ "builddate", sizeof("builddate") - 1, &HTTPPrint_builddate },
|
||||||
{ "serial", sizeof("serial") - 1, &HTTPPrint_serial },
|
{ "serial", sizeof("serial") - 1, &HTTPPrint_serial },
|
||||||
|
|
@ -730,6 +736,7 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
|
||||||
{ "dns3", sizeof("dns3") - 1, &HTTPPrint_dns3 },
|
{ "dns3", sizeof("dns3") - 1, &HTTPPrint_dns3 },
|
||||||
{ "macadr", sizeof("macadr") - 1, &HTTPPrint_macadr },
|
{ "macadr", sizeof("macadr") - 1, &HTTPPrint_macadr },
|
||||||
{ "apmacadr", sizeof("apmacadr") - 1, &HTTPPrint_apmacadr },
|
{ "apmacadr", sizeof("apmacadr") - 1, &HTTPPrint_apmacadr },
|
||||||
|
{ "wifisc", sizeof("wifisc") - 1, &HTTPPrint_wifisc },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
|
||||||
|
|
@ -746,8 +753,6 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
|
||||||
{ "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr },
|
{ "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_WEBGUIAPP_GPRS_ENABLE
|
#if CONFIG_WEBGUIAPP_GPRS_ENABLE
|
||||||
/*GSM modem*/
|
/*GSM modem*/
|
||||||
{ "gsmen", sizeof("gsmen") - 1, &HTTPPrint_gsmen },
|
{ "gsmen", sizeof("gsmen") - 1, &HTTPPrint_gsmen },
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,19 @@ static EventGroupHandle_t s_wifi_event_group;
|
||||||
static int s_retry_num = 0;
|
static int s_retry_num = 0;
|
||||||
static bool isWiFiGotIp = false;
|
static bool isWiFiGotIp = false;
|
||||||
|
|
||||||
|
#define DEFAULT_SCAN_LIST_SIZE 20
|
||||||
|
static wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
|
||||||
|
static bool isScanReady = false;
|
||||||
|
|
||||||
|
wifi_ap_record_t* GetWiFiAPRecord(uint8_t n)
|
||||||
|
{
|
||||||
|
if (n < DEFAULT_SCAN_LIST_SIZE)
|
||||||
|
{
|
||||||
|
return &ap_info[n];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
esp_netif_t* GetSTANetifAdapter(void)
|
esp_netif_t* GetSTANetifAdapter(void)
|
||||||
{
|
{
|
||||||
return sta_netif;
|
return sta_netif;
|
||||||
|
|
@ -484,23 +497,21 @@ void WiFiSTAStart(void)
|
||||||
xTaskCreate(wifi_init_sta, "InitStationTask", 1024 * 4, (void*) 0, 3, NULL);
|
xTaskCreate(wifi_init_sta, "InitStationTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFAULT_SCAN_LIST_SIZE 20
|
static void wifi_scan(void *arg)
|
||||||
|
|
||||||
void WiFiScan(void)
|
|
||||||
{
|
{
|
||||||
uint16_t number = DEFAULT_SCAN_LIST_SIZE;
|
uint16_t number = DEFAULT_SCAN_LIST_SIZE;
|
||||||
wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
|
|
||||||
uint16_t ap_count = 0;
|
uint16_t ap_count = 0;
|
||||||
memset(ap_info, 0, sizeof(ap_info));
|
memset(ap_info, 0, sizeof(ap_info));
|
||||||
|
|
||||||
esp_wifi_scan_start(NULL, true);
|
esp_wifi_scan_start(NULL, true);
|
||||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
|
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
|
||||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
|
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
|
||||||
ESP_LOGI(TAG, "Total APs scanned = %u", ap_count);
|
ESP_LOGI(TAG, "Total APs scanned = %u", ap_count);
|
||||||
for (int i = 0; (i < DEFAULT_SCAN_LIST_SIZE) && (i < ap_count); i++)
|
isScanReady = true;
|
||||||
{
|
vTaskDelete(NULL);
|
||||||
ESP_LOGI(TAG, "SSID \t\t%s", ap_info[i].ssid);
|
}
|
||||||
ESP_LOGI(TAG, "RSSI \t\t%d", ap_info[i].rssi);
|
|
||||||
ESP_LOGI(TAG, "Channel \t\t%d\n", ap_info[i].primary);
|
void WiFiScan(void)
|
||||||
}
|
{
|
||||||
|
isScanReady = false;
|
||||||
|
xTaskCreate(wifi_scan, "ScanWiFiTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user