Add debugging. Scanning doesn't crash but returns no results. Need to config station.
This commit is contained in:
parent
1a6f4e0fe0
commit
ddcff85fa2
5
main.c
5
main.c
@ -436,11 +436,12 @@ int run_repl(void) {
|
||||
}
|
||||
|
||||
int __attribute__((used)) main(void) {
|
||||
memory_init();
|
||||
|
||||
// initialise the cpu and peripherals
|
||||
safe_mode_t safe_mode = port_init();
|
||||
|
||||
// Init memory after the port in case the port needs to set aside memory.
|
||||
memory_init();
|
||||
|
||||
// Turn on LEDs
|
||||
init_status_leds();
|
||||
rgb_led_status_init();
|
||||
|
@ -31,18 +31,41 @@
|
||||
|
||||
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "cp radio";
|
||||
|
||||
static void start_station(wifi_radio_obj_t *self) {
|
||||
if (self->sta_mode) {
|
||||
return;
|
||||
}
|
||||
wifi_mode_t next_mode;
|
||||
if (self->ap_mode) {
|
||||
next_mode = WIFI_MODE_APSTA;
|
||||
} else {
|
||||
next_mode = WIFI_MODE_STA;
|
||||
}
|
||||
esp_wifi_set_mode(next_mode);
|
||||
|
||||
esp_wifi_set_config(WIFI_MODE_STA, &self->sta_config);
|
||||
}
|
||||
|
||||
bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) {
|
||||
return self->started;
|
||||
}
|
||||
|
||||
void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
|
||||
if (self->started && !enabled) {
|
||||
esp_wifi_stop();
|
||||
ESP_LOGI(TAG, "stop");
|
||||
if (self->current_scan != NULL) {
|
||||
common_hal_wifi_radio_stop_scanning_networks(self);
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
self->started = false;
|
||||
return;
|
||||
}
|
||||
if (!self->started && enabled) {
|
||||
esp_wifi_start();
|
||||
ESP_LOGI(TAG, "start");
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
self->started = true;
|
||||
return;
|
||||
}
|
||||
@ -59,7 +82,9 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
|
||||
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
|
||||
}
|
||||
// check enabled
|
||||
start_station(self);
|
||||
|
||||
ESP_LOGI(TAG, "start scan");
|
||||
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
|
||||
self->current_scan = scan;
|
||||
scan->base.type = &wifi_scannednetworks_type;
|
||||
@ -72,8 +97,10 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
|
||||
|
||||
void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) {
|
||||
// Free the memory used to store the found aps.
|
||||
ESP_EARLY_LOGI(TAG, "stop scan");
|
||||
wifi_scannednetworks_deinit(self->current_scan);
|
||||
self->current_scan = NULL;
|
||||
ESP_EARLY_LOGI(TAG, "stop scan done");
|
||||
}
|
||||
|
||||
bool common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t ssid_len, uint8_t* password, size_t password_len, mp_float_t timeout) {
|
||||
|
@ -43,7 +43,11 @@ typedef struct {
|
||||
wifi_scannednetworks_obj_t *current_scan;
|
||||
StaticEventGroup_t event_group;
|
||||
EventGroupHandle_t event_group_handle;
|
||||
wifi_config_t sta_config;
|
||||
esp_netif_t *netif;
|
||||
bool started;
|
||||
bool ap_mode;
|
||||
bool sta_mode;
|
||||
} wifi_radio_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H
|
||||
|
@ -38,10 +38,16 @@
|
||||
|
||||
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "cp scannednetworks";
|
||||
|
||||
static void wifi_scannednetworks_done(wifi_scannednetworks_obj_t *self) {
|
||||
self->done = true;
|
||||
free(self->results);
|
||||
self->results = NULL;
|
||||
ESP_EARLY_LOGI(TAG, "free %x", self->results);
|
||||
if (self->results != NULL) {
|
||||
m_free(self->results);
|
||||
self->results = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool wifi_scannednetworks_wait_for_scan(wifi_scannednetworks_obj_t *self) {
|
||||
@ -75,6 +81,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
|
||||
}
|
||||
|
||||
esp_wifi_scan_get_ap_num(&self->total_results);
|
||||
self->scanning = false;
|
||||
if (self->total_results > 0) {
|
||||
break;
|
||||
}
|
||||
@ -83,6 +90,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
|
||||
}
|
||||
// We not have found any more results so we're done.
|
||||
if (self->done) {
|
||||
ESP_LOGI(TAG, "return done");
|
||||
return mp_const_none;
|
||||
}
|
||||
// If we need more space than we have, realloc.
|
||||
@ -92,6 +100,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
|
||||
self->max_results,
|
||||
self->total_results,
|
||||
true /* allow move */);
|
||||
ESP_EARLY_LOGI(TAG, "alloc %x", results);
|
||||
if (results != NULL) {
|
||||
self->results = results;
|
||||
self->max_results = self->total_results;
|
||||
@ -128,7 +137,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
|
||||
static uint8_t scan_pattern[] = {6, 1, 11, 3, 9, 13, 2, 4, 8, 12, 5, 7, 10, 14};
|
||||
|
||||
void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) {
|
||||
wifi_scan_config_t config;
|
||||
|
||||
uint8_t next_channel = sizeof(scan_pattern);
|
||||
while (self->current_channel_index < sizeof(scan_pattern)) {
|
||||
next_channel = scan_pattern[self->current_channel_index];
|
||||
@ -137,11 +146,19 @@ void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (next_channel == sizeof(scan_pattern) ||
|
||||
esp_wifi_scan_start(&config, false) != ESP_OK) {
|
||||
wifi_scan_config_t config = { 0 };
|
||||
config.channel = next_channel;
|
||||
if (next_channel == sizeof(scan_pattern)) {
|
||||
ESP_LOGI(TAG, "scan done");
|
||||
wifi_scannednetworks_done(self);
|
||||
} else {
|
||||
self->scanning = true;
|
||||
esp_err_t result = esp_wifi_scan_start(&config, false);
|
||||
if (result != ESP_OK) {
|
||||
ESP_LOGI(TAG, "start failed 0x%x", result);
|
||||
wifi_scannednetworks_done(self);
|
||||
} else {
|
||||
self->scanning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,13 @@ static const char *TAG = "cp wifi";
|
||||
|
||||
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
|
||||
|
||||
#include "esp-idf/components/heap/include/esp_heap_caps.h"
|
||||
|
||||
wifi_radio_obj_t common_hal_wifi_radio_obj;
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data) {
|
||||
ESP_LOGI(TAG, "event");
|
||||
ESP_LOGI(TAG, "event %x", event_id);
|
||||
wifi_radio_obj_t* radio = arg;
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) {
|
||||
xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT);
|
||||
@ -65,16 +67,20 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
static bool wifi_inited;
|
||||
|
||||
void common_hal_wifi_init(void) {
|
||||
ESP_LOGI(TAG, "init");
|
||||
ESP_EARLY_LOGI(TAG, "init");
|
||||
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
|
||||
wifi_inited = true;
|
||||
common_hal_wifi_radio_obj.base.type = &wifi_radio_type;
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "create event loop");
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "create wifi sta");
|
||||
wifi_radio_obj_t* self = &common_hal_wifi_radio_obj;
|
||||
self->netif = esp_netif_create_default_wifi_sta();
|
||||
|
||||
self->event_group_handle = xEventGroupCreateStatic(&self->event_group);
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
@ -88,6 +94,7 @@ void common_hal_wifi_init(void) {
|
||||
self->handler_instance_got_ip));
|
||||
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "wifi init");
|
||||
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_err_t result = esp_wifi_init(&config);
|
||||
if (result == ESP_ERR_NO_MEM) {
|
||||
@ -95,6 +102,7 @@ void common_hal_wifi_init(void) {
|
||||
} else if (result != ESP_OK) {
|
||||
// handle this
|
||||
}
|
||||
ESP_EARLY_LOGI(TAG, "enable radio");
|
||||
common_hal_wifi_radio_set_enabled(self, true);
|
||||
}
|
||||
|
||||
@ -111,5 +119,8 @@ void wifi_reset(void) {
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
radio->handler_instance_got_ip));
|
||||
esp_wifi_deinit();
|
||||
ESP_ERROR_CHECK(esp_wifi_deinit());
|
||||
esp_netif_destroy(radio->netif);
|
||||
radio->netif = NULL;
|
||||
ESP_ERROR_CHECK(esp_netif_deinit());
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "cp port";
|
||||
|
||||
#define HEAP_SIZE (96 * 1024)
|
||||
#define HEAP_SIZE (64 * 1024)
|
||||
|
||||
STATIC esp_timer_handle_t _tick_timer;
|
||||
|
||||
@ -92,6 +92,7 @@ void reset_port(void) {
|
||||
#if CIRCUITPY_WIFI
|
||||
wifi_reset();
|
||||
#endif
|
||||
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
|
||||
}
|
||||
|
||||
void reset_to_bootloader(void) {
|
||||
|
@ -32,6 +32,9 @@
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/wifi/ScannedNetworks.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "cp iternext";
|
||||
|
||||
//| class ScannedNetworks:
|
||||
//| """Iterates over wifi `Network`s found while scanning. This object is always created
|
||||
//| by a `wifi.Radio`: it has no user-visible constructor."""
|
||||
@ -43,6 +46,8 @@ STATIC mp_obj_t scannednetworks_iternext(mp_obj_t self_in) {
|
||||
if (network != mp_const_none) {
|
||||
return network;
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "stop iteration");
|
||||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
|
||||
#include "supervisor/shared/display.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "memory";
|
||||
|
||||
#define CIRCUITPY_SUPERVISOR_ALLOC_COUNT (12)
|
||||
|
||||
static supervisor_allocation allocations[CIRCUITPY_SUPERVISOR_ALLOC_COUNT];
|
||||
@ -39,6 +42,7 @@ uint32_t* low_address;
|
||||
uint32_t* high_address;
|
||||
|
||||
void memory_init(void) {
|
||||
ESP_LOGE(TAG, "memory init");
|
||||
low_address = port_heap_get_bottom();
|
||||
high_address = port_heap_get_top();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user