From b68da1548b582f594bdf66e45630461e9141126c Mon Sep 17 00:00:00 2001 From: cpq Date: Thu, 15 Oct 2026 12:02:29 +0100 Subject: [PATCH] Restore logging, make WiFi creds settable from make --- tutorials/rp/pico-rm2/CMakeLists.txt | 9 +++++++++ tutorials/rp/pico-rm2/main.c | 6 ++++++ tutorials/rp/pico-rm2/wifi.c | 9 +++++++-- tutorials/rp/pico-rmii/main.c | 6 ++++++ tutorials/rp/pico-rndis-device/main.c | 6 ++++++ tutorials/rp/pico-rndis/main.c | 6 ++++++ tutorials/rp/pico-w/CMakeLists.txt | 9 +++++++++ tutorials/rp/pico-w/main.c | 6 ++++++ tutorials/rp/pico-w/wifi.c | 9 +++++++-- tutorials/rp/w5500-evb-pico/main.c | 6 ++++++ tutorials/rp/w55rp20-evb-pico/main.c | 6 ++++++ 11 files changed, 74 insertions(+), 4 deletions(-) diff --git a/tutorials/rp/pico-rm2/CMakeLists.txt b/tutorials/rp/pico-rm2/CMakeLists.txt index a8013517..8d469c7e 100644 --- a/tutorials/rp/pico-rm2/CMakeLists.txt +++ b/tutorials/rp/pico-rm2/CMakeLists.txt @@ -16,3 +16,12 @@ pico_enable_stdio_usb(firmware 1) # Route stdio to USB # Prevent extreme optimization from breaking OTA target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns) + +# Wi-Fi credentials from the environment, e.g. make WIFI_NAME=... WIFI_PASS=... +# Read when build/ is configured: run "make clean" after changing them +if (DEFINED ENV{WIFI_NAME}) + target_compile_definitions(firmware PRIVATE "WIFI_SSID=\"$ENV{WIFI_NAME}\"") +endif() +if (DEFINED ENV{WIFI_PASS}) + target_compile_definitions(firmware PRIVATE "WIFI_PASS=\"$ENV{WIFI_PASS}\"") +endif() diff --git a/tutorials/rp/pico-rm2/main.c b/tutorials/rp/pico-rm2/main.c index c64e5ae3..dd0eae9a 100644 --- a/tutorials/rp/pico-rm2/main.c +++ b/tutorials/rp/pico-rm2/main.c @@ -16,10 +16,16 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { void driver_init(struct mg_mgr *mgr); struct mg_mgr mgr; + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); driver_init(&mgr); mg_log_set(MG_LL_DEBUG); // Set log level diff --git a/tutorials/rp/pico-rm2/wifi.c b/tutorials/rp/pico-rm2/wifi.c index d208e68a..0948b49f 100644 --- a/tutorials/rp/pico-rm2/wifi.c +++ b/tutorials/rp/pico-rm2/wifi.c @@ -4,8 +4,13 @@ #include "hardware/pio.h" #include "mongoose.h" -#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME" // SET THIS! -#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS! +// Set these, or pass on the command line: make WIFI_NAME=... WIFI_PASS=... +#ifndef WIFI_SSID +#define WIFI_SSID "YOUR_WIFI_NETWORK_NAME" +#endif +#ifndef WIFI_PASS +#define WIFI_PASS "YOUR_WIFI_PASSWORD" +#endif #define SPIPIO pio0 #define SPISM 0 diff --git a/tutorials/rp/pico-rmii/main.c b/tutorials/rp/pico-rmii/main.c index aa8a86d8..63d722b8 100644 --- a/tutorials/rp/pico-rmii/main.c +++ b/tutorials/rp/pico-rmii/main.c @@ -44,9 +44,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { struct mg_mgr mgr; + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); driver_init(&mgr); mg_log_set(MG_LL_DEBUG); // Set log level diff --git a/tutorials/rp/pico-rndis-device/main.c b/tutorials/rp/pico-rndis-device/main.c index ac73e3cd..66c3192c 100644 --- a/tutorials/rp/pico-rndis-device/main.c +++ b/tutorials/rp/pico-rndis-device/main.c @@ -64,12 +64,18 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_dta) { if (ev == MG_EV_HTTP_MSG) return mg_http_reply(c, 200, "", "ok\n"); } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + int main(void) { gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); stdio_init_all(); struct mg_mgr mgr; // Initialise Mongoose event manager + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); // and attach it to the interface struct mg_tcpip_driver driver = {.tx = usb_tx, .poll = usb_poll}; diff --git a/tutorials/rp/pico-rndis/main.c b/tutorials/rp/pico-rndis/main.c index 8ed79a04..4f3ed2f1 100644 --- a/tutorials/rp/pico-rndis/main.c +++ b/tutorials/rp/pico-rndis/main.c @@ -69,9 +69,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { struct mg_mgr mgr; + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); driver_init(&mgr); mg_log_set(MG_LL_DEBUG); // Set log level diff --git a/tutorials/rp/pico-w/CMakeLists.txt b/tutorials/rp/pico-w/CMakeLists.txt index 2bd70b59..aca447eb 100644 --- a/tutorials/rp/pico-w/CMakeLists.txt +++ b/tutorials/rp/pico-w/CMakeLists.txt @@ -16,3 +16,12 @@ pico_enable_stdio_usb(firmware 1) # Route stdio to USB # Prevent extreme optimization from breaking OTA target_compile_options(firmware PRIVATE -fno-tree-loop-distribute-patterns) + +# Wi-Fi credentials from the environment, e.g. make WIFI_NAME=... WIFI_PASS=... +# Read when build/ is configured: run "make clean" after changing them +if (DEFINED ENV{WIFI_NAME}) + target_compile_definitions(firmware PRIVATE "WIFI_NAME=\"$ENV{WIFI_NAME}\"") +endif() +if (DEFINED ENV{WIFI_PASS}) + target_compile_definitions(firmware PRIVATE "WIFI_PASS=\"$ENV{WIFI_PASS}\"") +endif() diff --git a/tutorials/rp/pico-w/main.c b/tutorials/rp/pico-w/main.c index 195f732e..9941eb02 100644 --- a/tutorials/rp/pico-w/main.c +++ b/tutorials/rp/pico-w/main.c @@ -23,9 +23,15 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { struct mg_mgr mgr; + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); diff --git a/tutorials/rp/pico-w/wifi.c b/tutorials/rp/pico-w/wifi.c index 4e0e4372..652ab155 100644 --- a/tutorials/rp/pico-w/wifi.c +++ b/tutorials/rp/pico-w/wifi.c @@ -3,8 +3,13 @@ #include "mongoose.h" -#define WIFI_NAME "YOUR_WIFI_NETWORK" // SET THIS! -#define WIFI_PASS "YOUR_WIFI_PASSWORD" // SET THIS! +// Set these, or pass on the command line: make WIFI_NAME=... WIFI_PASS=... +#ifndef WIFI_NAME +#define WIFI_NAME "YOUR_WIFI_NETWORK" +#endif +#ifndef WIFI_PASS +#define WIFI_PASS "YOUR_WIFI_PASSWORD" +#endif // Access point setup #define ENABLE_AP false // Change to true to enable diff --git a/tutorials/rp/w5500-evb-pico/main.c b/tutorials/rp/w5500-evb-pico/main.c index e9059752..5b0ea7e7 100644 --- a/tutorials/rp/w5500-evb-pico/main.c +++ b/tutorials/rp/w5500-evb-pico/main.c @@ -66,6 +66,11 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { struct mg_mgr mgr; @@ -75,6 +80,7 @@ static void run_mongoose(void) { .driver_data = &spi, }; generate_mac_from_board_id(mif.mac); + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); mg_tcpip_init(&mgr, &mif); MG_INFO(("Driver: W5500, MAC: %M", mg_print_mac, mif.mac)); diff --git a/tutorials/rp/w55rp20-evb-pico/main.c b/tutorials/rp/w55rp20-evb-pico/main.c index f3773a8e..8d32de55 100644 --- a/tutorials/rp/w55rp20-evb-pico/main.c +++ b/tutorials/rp/w55rp20-evb-pico/main.c @@ -179,10 +179,16 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) { } } +static void log_fn(char ch, void *param) { + (void) param; + putchar(ch); +} + // In an RTOS environment, give this task 8 KB of stack space. static void run_mongoose(void) { struct mg_mgr mgr; + mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL);