8000 esp32: Silence ESP-IDF log messages when in raw REPL mode. · micropython/micropython@ef4c8e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef4c8e6

Browse files
nickzoicdpgeorge
authored andcommitted
esp32: Silence ESP-IDF log messages when in raw REPL mode.
This prevents clients such as ampy, mpy-utils, etc getting confused by extraneous data.
1 parent dfeaea1 commit ef4c8e6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

ports/esp32/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828

2929
#include <stdio.h>
3030
#include <string.h>
31+
#include <stdarg.h>
3132

3233
#include "freertos/FreeRTOS.h"
3334
#include "freertos/task.h"
3435
#include "esp_system.h"
3536
#include "nvs_flash.h"
3637
#include "esp_task.h"
3738
#include "soc/cpu.h"
39+
#include "esp_log.h"
3840

3941
#include "py/stackctrl.h"
4042
#include "py/nlr.h"
@@ -58,6 +60,11 @@
5860
STATIC StaticTask_t mp_task_tcb;
5961
STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8)));
6062

63+
int vprintf_null(const char *format, va_list ap) {
64+
// do nothing: this is used as a log target during raw repl mode
65+
return 0;
66+
}
67+
6168
void mp_task(void *pvParameter) {
6269
volatile uint32_t sp = (uint32_t)get_sp();
6370
#if MICROPY_PY_THREAD
@@ -93,9 +100,11 @@ void mp_task(void *pvParameter) {
93100

94101
for (;;) {
95102
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
103+
vprintf_like_t vprintf_log = esp_log_set_vprintf(vprintf_null);
96104
if (pyexec_raw_repl() != 0) {
97105
break;
98106
}
107+
esp_log_set_vprintf(vprintf_log);
99108
} else {
100109
if (pyexec_friendly_repl() != 0) {
101110
break;

ports/esp32/modnetwork.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,34 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
139139
// This is a workaround as ESP32 WiFi libs don't currently
140140
// auto-reassociate.
141141
system_event_sta_disconnected_t *disconn = &event->event_info.disconnected;
142-
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d", disconn->reason);
142+
char *message = "";
143143
switch (disconn->reason) {
144144
case WIFI_REASON_BEACON_TIMEOUT:
145-
mp_printf(MP_PYTHON_PRINTER, "beacon timeout\n");
146145
// AP has dropped out; try to reconnect.
146+
message = "\nbeacon timeout";
147147
break;
148148
case WIFI_REASON_NO_AP_FOUND:
149-
mp_printf(MP_PYTHON_PRINTER, "no AP found\n");
150149
// AP may not exist, or it may have momentarily dropped out; try to reconnect.
150+
message = "\nno AP found";
151151
break;
152152
case WIFI_REASON_AUTH_FAIL:
153-
mp_printf(MP_PYTHON_PRINTER, "authentication failed\n");
153+
message = "\nauthentication failed";
154154
wifi_sta_connected = false;
155155
break;
156156
default:
157157
// Let other errors through and try to reconnect.
158158
break;
159159
}
160+
ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message);
161+
160162
if (wifi_sta_connected) {
161163
wifi_mode_t mode;
162164
if (esp_wifi_get_mode(&mode) == ESP_OK) {
163165
if (mode & WIFI_MODE_STA) {
164166
// STA is active so attempt to reconnect.
165167
esp_err_t e = esp_wifi_connect();
166168
if (e != ESP_OK) {
167-
mp_printf(MP_PYTHON_PRINTER, "error attempting to reconnect: 0x%04x", e);
169+
ESP_LOGI("wifi", "error attempting to reconnect: 0x%04x", e);
168170
}
169171
}
170172
}

0 commit comments

Comments
 (0)
0