Added wifi network scanning
This commit is contained in:
parent
3284bdd0be
commit
4a88b0ecda
|
@ -9,6 +9,52 @@
|
|||
#include <lwip/api.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "network.h"
|
||||
|
||||
SemaphoreHandle_t semNetworks;
|
||||
|
||||
struct network_info networks[MAX_NETWORKS];
|
||||
|
||||
static void scan_done_cb(void *arg, sdk_scan_status_t status) {
|
||||
int i;
|
||||
|
||||
if (xSemaphoreTake(semNetworks, TIME_MS(50)) == pdTRUE) {
|
||||
if (status != SCAN_OK) {
|
||||
networks[0].channel = networks[0].rssi = 0;
|
||||
} else {
|
||||
struct sdk_bss_info *bss = (struct sdk_bss_info *)arg;
|
||||
// first one is invalid
|
||||
bss = bss->next.stqe_next;
|
||||
|
||||
for (i=0; NULL != bss && i<MAX_NETWORKS; i++) {
|
||||
memcpy(networks[i].bssid, bss->bssid, sizeof(networks[i].bssid));
|
||||
memcpy(networks[i].ssid, bss->ssid, sizeof(networks[i].ssid));
|
||||
networks[i].channel = bss->channel;
|
||||
networks[i].rssi= bss->rssi;
|
||||
networks[i].authmode = bss->authmode;
|
||||
networks[i].is_hidden = bss->is_hidden;
|
||||
|
||||
bss = bss->next.stqe_next;
|
||||
}
|
||||
if (i < MAX_NETWORKS) {
|
||||
networks[i].channel = networks[i].rssi = 0;
|
||||
}
|
||||
}
|
||||
|
||||
xSemaphoreGive(semNetworks);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkScanTask(void *p) {
|
||||
networks[0].channel = networks[0].rssi = 0;
|
||||
semNetworks = xSemaphoreCreateMutex();
|
||||
|
||||
for (;;) {
|
||||
sdk_wifi_station_scan(NULL, scan_done_cb);
|
||||
vTaskDelay(TIME_MS(5000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* This task ensures the network connection is up.
|
||||
* If the network has not been configured yet,
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
#ifndef _NETWORK_H_
|
||||
#define _NETWORK_H_
|
||||
|
||||
#include <semphr.h>
|
||||
|
||||
extern SemaphoreHandle_t semNetworks;
|
||||
|
||||
struct network_info {
|
||||
uint8_t bssid[6];
|
||||
uint8_t ssid[32];
|
||||
uint8_t channel;
|
||||
int8_t rssi;
|
||||
AUTH_MODE authmode;
|
||||
uint8_t is_hidden;
|
||||
};
|
||||
|
||||
#define MAX_NETWORKS 20
|
||||
extern struct network_info networks[MAX_NETWORKS];
|
||||
|
||||
void NetworkConnectionTask(void *p);
|
||||
void NetworkScanTask(void *p);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue