Remove debug prints
This commit is contained in:
parent
1034cc1217
commit
dcc42f6281
@ -26,9 +26,6 @@
|
||||
|
||||
#include "shared-bindings/socketpool/Socket.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "socket";
|
||||
|
||||
void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t* self, mp_uint_t timeout_ms) {
|
||||
self->timeout_ms = timeout_ms;
|
||||
}
|
||||
@ -38,20 +35,17 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c
|
||||
// NULL and should still work. This makes regular TCP connections more memory expensive but TLS
|
||||
// should become more and more common. Therefore, we optimize for the TLS case.
|
||||
|
||||
ESP_LOGI(TAG, "connecting to %s:%d %p", host, port, self->ssl_context);
|
||||
esp_tls_cfg_t* tls_config = NULL;
|
||||
if (self->ssl_context != NULL) {
|
||||
tls_config = &self->ssl_context->ssl_config;
|
||||
}
|
||||
int result = esp_tls_conn_new_sync(host, hostlen, port, tls_config, self->tcp);
|
||||
ESP_LOGI(TAG, "result %d", result);
|
||||
return result >= 0;
|
||||
}
|
||||
|
||||
mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len) {
|
||||
size_t sent = esp_tls_conn_write(self->tcp, buf, len);
|
||||
|
||||
ESP_LOGI(TAG, "sent %d bytes", sent);
|
||||
if (sent < 0) {
|
||||
// raise an error
|
||||
}
|
||||
@ -61,7 +55,6 @@ mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const
|
||||
mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len) {
|
||||
size_t received = esp_tls_conn_read(self->tcp, (void*) buf, len);
|
||||
|
||||
ESP_LOGI(TAG, "received %d bytes", received);
|
||||
if (received == 0) {
|
||||
// socket closed
|
||||
}
|
||||
|
@ -38,99 +38,84 @@
|
||||
#include "esp-idf/components/esp_wifi/include/esp_wifi.h"
|
||||
#include "esp-idf/components/lwip/include/apps/ping/ping_sock.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);
|
||||
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);
|
||||
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;
|
||||
return self->started;
|
||||
}
|
||||
|
||||
void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) {
|
||||
if (self->started && !enabled) {
|
||||
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_LOGI(TAG, "start");
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
self->started = true;
|
||||
return;
|
||||
}
|
||||
if (self->started && !enabled) {
|
||||
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_ERROR_CHECK(esp_wifi_start());
|
||||
self->started = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
|
||||
uint8_t mac[6];
|
||||
esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
|
||||
return mp_const_none;
|
||||
uint8_t mac[6];
|
||||
esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
|
||||
if (self->current_scan != NULL) {
|
||||
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));
|
||||
}
|
||||
// check enabled
|
||||
start_station(self);
|
||||
if (self->current_scan != NULL) {
|
||||
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;
|
||||
scan->start_channel = 1;
|
||||
scan->end_channel = 11;
|
||||
scan->radio_event_group = self->event_group_handle;
|
||||
wifi_scannednetworks_scan_next_channel(scan);
|
||||
return scan;
|
||||
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
|
||||
self->current_scan = scan;
|
||||
scan->base.type = &wifi_scannednetworks_type;
|
||||
scan->start_channel = 1;
|
||||
scan->end_channel = 11;
|
||||
scan->radio_event_group = self->event_group_handle;
|
||||
wifi_scannednetworks_scan_next_channel(scan);
|
||||
return scan;
|
||||
}
|
||||
|
||||
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");
|
||||
// Free the memory used to store the found aps.
|
||||
wifi_scannednetworks_deinit(self->current_scan);
|
||||
self->current_scan = NULL;
|
||||
}
|
||||
|
||||
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, uint8_t channel, mp_float_t timeout) {
|
||||
// check enabled
|
||||
wifi_config_t* config = &self->sta_config;
|
||||
memcpy(&config->sta.ssid, ssid, ssid_len);
|
||||
config->sta.ssid[ssid_len] = 0;
|
||||
if (password_len > 0) {
|
||||
memcpy(&config->sta.password, password, password_len);
|
||||
}
|
||||
config->sta.password[password_len] = 0;
|
||||
config->sta.channel = channel;
|
||||
ESP_EARLY_LOGI(TAG, "connecting to %s", config->sta.ssid);
|
||||
esp_err_t result = esp_wifi_set_config(ESP_IF_WIFI_STA, config);
|
||||
if (result != ESP_OK) {
|
||||
ESP_EARLY_LOGI(TAG, "config fail %d", result);
|
||||
}
|
||||
result = esp_wifi_connect();
|
||||
if (result != ESP_OK) {
|
||||
ESP_EARLY_LOGI(TAG, "connect fail %d", result);
|
||||
}
|
||||
// check enabled
|
||||
wifi_config_t* config = &self->sta_config;
|
||||
memcpy(&config->sta.ssid, ssid, ssid_len);
|
||||
config->sta.ssid[ssid_len] = 0;
|
||||
if (password_len > 0) {
|
||||
memcpy(&config->sta.password, password, password_len);
|
||||
}
|
||||
config->sta.password[password_len] = 0;
|
||||
config->sta.channel = channel;
|
||||
esp_wifi_set_config(ESP_IF_WIFI_STA, config);
|
||||
esp_wifi_connect();
|
||||
|
||||
EventBits_t bits;
|
||||
EventBits_t bits;
|
||||
do {
|
||||
RUN_BACKGROUND_TASKS;
|
||||
bits = xEventGroupWaitBits(self->event_group_handle,
|
||||
@ -140,21 +125,18 @@ bool common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t* ssid, size_t
|
||||
0);
|
||||
} while ((bits & (WIFI_CONNECTED_BIT | WIFI_DISCONNECTED_BIT)) == 0 && !mp_hal_is_interrupted());
|
||||
if ((bits & WIFI_DISCONNECTED_BIT) != 0) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) {
|
||||
if (!esp_netif_is_netif_up(self->netif)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
esp_netif_ip_info_t ip_info;
|
||||
esp_err_t result = esp_netif_get_ip_info(self->netif, &ip_info);
|
||||
if (result != ESP_OK) {
|
||||
ESP_EARLY_LOGI(TAG, "get ip fail %d", result);
|
||||
}
|
||||
return common_hal_ipaddress_new_ipv4address(ip_info.ip.addr);
|
||||
if (!esp_netif_is_netif_up(self->netif)) {
|
||||
return mp_const_none;
|
||||
}
|
||||
esp_netif_ip_info_t ip_info;
|
||||
esp_netif_get_ip_info(self->netif, &ip_info);
|
||||
return common_hal_ipaddress_new_ipv4address(ip_info.ip.addr);
|
||||
}
|
||||
|
||||
mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout) {
|
||||
@ -171,15 +153,15 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
|
||||
uint32_t received = 0;
|
||||
uint32_t total_time_ms = 0;
|
||||
while (received == 0 && total_time_ms < timeout_ms) {
|
||||
RUN_BACKGROUND_TASKS;
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_REPLY, &received, sizeof(received));
|
||||
RUN_BACKGROUND_TASKS;
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_REPLY, &received, sizeof(received));
|
||||
}
|
||||
uint32_t elapsed_time = 0xffffffff;
|
||||
uint32_t elapsed_time = 0xffffffff;
|
||||
if (received > 0) {
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
|
||||
esp_ping_get_profile(ping, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
|
||||
}
|
||||
esp_ping_delete_session(ping);
|
||||
|
||||
return elapsed_time;
|
||||
return elapsed_time;
|
||||
}
|
||||
|
@ -39,12 +39,8 @@
|
||||
|
||||
#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;
|
||||
ESP_EARLY_LOGI(TAG, "free %x", self->results);
|
||||
if (self->results != NULL) {
|
||||
// Check to see if the heap is still active. If not, it'll be freed automatically.
|
||||
if (gc_alloc_possible()) {
|
||||
@ -94,7 +90,6 @@ 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.
|
||||
@ -104,7 +99,6 @@ 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;
|
||||
@ -152,12 +146,10 @@ void wifi_scannednetworks_scan_next_channel(wifi_scannednetworks_obj_t *self) {
|
||||
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 {
|
||||
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;
|
||||
|
@ -31,9 +31,6 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
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"
|
||||
@ -42,31 +39,20 @@ 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 %x", event_id);
|
||||
wifi_radio_obj_t* radio = arg;
|
||||
if (event_base == WIFI_EVENT) {
|
||||
if (event_id == WIFI_EVENT_SCAN_DONE) {
|
||||
ESP_LOGI(TAG, "scan done");
|
||||
xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT);
|
||||
} else if (event_id == WIFI_EVENT_STA_START) {
|
||||
ESP_LOGI(TAG, "station start");
|
||||
|
||||
} else if (event_id == WIFI_EVENT_STA_STOP) {
|
||||
ESP_LOGI(TAG, "station stop");
|
||||
|
||||
} else if (event_id == WIFI_EVENT_STA_CONNECTED) {
|
||||
ESP_LOGI(TAG, "connected to ap");
|
||||
} else if (event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
ESP_LOGI(TAG, "disconnected");
|
||||
wifi_event_sta_disconnected_t* d = (wifi_event_sta_disconnected_t*) event_data;
|
||||
ESP_LOGI(TAG, "reason %d", d->reason);
|
||||
// wifi_event_sta_disconnected_t* d = (wifi_event_sta_disconnected_t*) event_data;
|
||||
if (event_id != WIFI_REASON_ASSOC_LEAVE) {
|
||||
// reconnect
|
||||
}
|
||||
xEventGroupSetBits(radio->event_group_handle, WIFI_DISCONNECTED_BIT);
|
||||
} else if (event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) {
|
||||
ESP_LOGI(TAG, "auth change");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,9 +70,6 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
// ESP_LOGI(TAG,"connect to the AP fail");
|
||||
// } else
|
||||
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
// s_retry_num = 0;
|
||||
xEventGroupSetBits(radio->event_group_handle, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
@ -94,17 +77,12 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
static bool wifi_inited;
|
||||
|
||||
void common_hal_wifi_init(void) {
|
||||
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_EARLY_LOGI(TAG, "create wifi sta");
|
||||
wifi_radio_obj_t* self = &common_hal_wifi_radio_obj;
|
||||
self->netif = esp_netif_create_default_wifi_sta();
|
||||
|
||||
@ -120,8 +98,6 @@ void common_hal_wifi_init(void) {
|
||||
self,
|
||||
&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) {
|
||||
@ -129,12 +105,10 @@ 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);
|
||||
}
|
||||
|
||||
void wifi_reset(void) {
|
||||
ESP_LOGI(TAG, "reset");
|
||||
if (!wifi_inited) {
|
||||
return;
|
||||
}
|
||||
|
@ -45,9 +45,6 @@
|
||||
|
||||
#include "esp-idf/components/heap/include/esp_heap_caps.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
static const char *TAG = "cp port";
|
||||
|
||||
#define HEAP_SIZE (48 * 1024)
|
||||
|
||||
STATIC esp_timer_handle_t _tick_timer;
|
||||
@ -67,10 +64,6 @@ safe_mode_t port_init(void) {
|
||||
esp_timer_create(&args, &_tick_timer);
|
||||
|
||||
heap = malloc(HEAP_SIZE);
|
||||
if (heap == NULL) {
|
||||
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
|
||||
ESP_LOGE(TAG, "failed to allocate heap");
|
||||
}
|
||||
never_reset_module_internal_pins();
|
||||
return NO_SAFE_MODE;
|
||||
}
|
||||
@ -92,7 +85,6 @@ void reset_port(void) {
|
||||
#if CIRCUITPY_WIFI
|
||||
wifi_reset();
|
||||
#endif
|
||||
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
|
||||
}
|
||||
|
||||
void reset_to_bootloader(void) {
|
||||
@ -102,8 +94,6 @@ void reset_cpu(void) {
|
||||
}
|
||||
|
||||
uint32_t *port_heap_get_bottom(void) {
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "heap %x", heap);
|
||||
return heap;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include "shared-bindings/socketpool/SocketPool.h"
|
||||
|
||||
//| """
|
||||
//| The `ipaddress` module provides types for IP addresses. It is a subset of CPython's ipaddress
|
||||
//| module.
|
||||
//| The `socketpool` module provides sockets through a pool. The pools themselves
|
||||
//| act like CPython's `socket` module.
|
||||
//| """
|
||||
//|
|
||||
|
||||
|
@ -56,14 +56,6 @@ STATIC const mp_rom_map_elem_t ssl_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_create_default_context), MP_ROM_PTR(&ssl_create_default_context_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SSLContext), MP_ROM_PTR(&ssl_sslcontext_type) },
|
||||
|
||||
// class constants
|
||||
// { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(SOCKETPOOL_AF_INET) },
|
||||
// { MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(SOCKETPOOL_AF_INET6) },
|
||||
|
||||
// { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(SOCKETPOOL_SOCK_STREAM) },
|
||||
// { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(SOCKETPOOL_SOCK_DGRAM) },
|
||||
// { MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(SOCKETPOOL_SOCK_RAW) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ssl_globals, ssl_globals_table);
|
||||
|
Loading…
x
Reference in New Issue
Block a user