From 28e3b347d400bc51b74cd10316481c6cbb6e9149 Mon Sep 17 00:00:00 2001 From: cpq Date: Wed, 18 Nov 2026 20:28:32 +0000 Subject: [PATCH] Tutorials - nits and mqtt client adoption --- tutorials/esp32/minimal/Makefile | 4 +--- tutorials/nxp/frdm-rw612/minimal/Makefile | 4 ++++ tutorials/nxp/frdm-rw612/minimal/main.c | 2 ++ tutorials/nxp/frdm-rw612/minimal/mongoose_config.h | 3 ++- tutorials/rp/pico-w/CMakeLists.txt | 2 +- tutorials/rp/pico-w/main.c | 2 ++ tutorials/rp/pico-w/mongoose_config.h | 1 + tutorials/stm32/nucleo-h563zi/cubemx/mongoose/dashboard.c | 1 + 8 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tutorials/esp32/minimal/Makefile b/tutorials/esp32/minimal/Makefile index 0f753ce8..6586f8e4 100644 --- a/tutorials/esp32/minimal/Makefile +++ b/tutorials/esp32/minimal/Makefile @@ -17,6 +17,4 @@ flash: cd build && esptool --chip $(ARCH) --baud 460800 --port $(PORT) write-flash @flash_args clean: - test -d build && (rm -rf build sdkconfig || true) - -.PHONY: build + test -d build && $(DOCKER) rm -rf build sdkconfig || true diff --git a/tutorials/nxp/frdm-rw612/minimal/Makefile b/tutorials/nxp/frdm-rw612/minimal/Makefile index dfa74705..de9a00fd 100644 --- a/tutorials/nxp/frdm-rw612/minimal/Makefile +++ b/tutorials/nxp/frdm-rw612/minimal/Makefile @@ -15,6 +15,7 @@ CFLAGS += -mcpu=cortex-m33+nodsp -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16 $(CF LDFLAGS ?= -Tlink.ld -nostdlib -nostartfiles --specs=nano.specs -lc -lgcc -Wl,--gc-sections SOURCES = main.c hal.c startup.c flexspi.c flash_config.c $(MGDIR)/mongoose.c +SOURCES += $(MGDIR)/tutorials/mqtt/mqtt-client/mongoose_mqtt.c SOURCES += cmsis_rw612/devices/RW612/drivers/fsl_clock.c SOURCES += cmsis_rw612/devices/RW612/drivers/fsl_trng.c SOURCES += cmsis_rw612/devices/RW612/drivers/fsl_reset.c @@ -44,5 +45,8 @@ flash: firmware.bin (echo 'loadfile firmware.elf'; echo 'reset'; echo 'exit';) | JLinkExe -device RW612 -if SWD -speed 4000 -autoconnect 1 -NoGui 1 -ExitOnError 1 # JRun --nogui --device RW612 --if SWD firmware.elf +erase: + (echo halt && echo exec EnableEraseAllFlashBanks && echo erase && echo exit) | JLinkExe -device RW612 -if SWD -speed 4000 -autoconnect 1 -NoGui 1 -ExitOnError 1 + clean: rm -rf firmware.* cmsis_* mongoose/mongoose.* diff --git a/tutorials/nxp/frdm-rw612/minimal/main.c b/tutorials/nxp/frdm-rw612/minimal/main.c index 0c4d1522..6a7f1286 100644 --- a/tutorials/nxp/frdm-rw612/minimal/main.c +++ b/tutorials/nxp/frdm-rw612/minimal/main.c @@ -104,6 +104,7 @@ int main(void) { // Start a minimal web server struct mg_mgr mgr; mg_mgr_init(&mgr); + mg_mqtt_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); mg_http_listen(&mgr, "https://0.0.0.0", http_ev_handler, NULL); @@ -113,6 +114,7 @@ int main(void) { for (;;) { mg_mgr_poll(&mgr, 0); + mg_mqtt_poll(&mgr); blink_task(); } diff --git a/tutorials/nxp/frdm-rw612/minimal/mongoose_config.h b/tutorials/nxp/frdm-rw612/minimal/mongoose_config.h index a11aa31d..d4a667b3 100644 --- a/tutorials/nxp/frdm-rw612/minimal/mongoose_config.h +++ b/tutorials/nxp/frdm-rw612/minimal/mongoose_config.h @@ -9,10 +9,11 @@ #define MG_ENABLE_CUSTOM_RANDOM 1 #define MG_OTA MG_OTA_RW612 #define MG_TLS MG_TLS_BUILTIN +#define MQTT_CLIENT_ID "rw612" // For tutorials/mqtt/mqtt-client #define MG_ENABLE_MDASH 0 // Set to 1 to enable https://mdash.net #define MG_MDASH_KEY "..." // Edit, see https://mdash.net/docs/#mongoose-library -#define MG_FIRMWARE_VERSION "1.0.1" +#define MG_FIRMWARE_VERSION "rw612.1.0.1" // #define MG_DRIVER_MDC_CR 51 // RMII MDC clock divider // #define MG_DRIVER_MDC_HOLDTIME 3 // RMII MDC Holdtime (valid values [0-7]) diff --git a/tutorials/rp/pico-w/CMakeLists.txt b/tutorials/rp/pico-w/CMakeLists.txt index 1fa36b76..c1f72d75 100644 --- a/tutorials/rp/pico-w/CMakeLists.txt +++ b/tutorials/rp/pico-w/CMakeLists.txt @@ -7,7 +7,7 @@ include(pico_sdk_import.cmake) project(firmware) pico_sdk_init() -add_executable(firmware main.c wifi.c ../../../mongoose.c) +add_executable(firmware main.c wifi.c ../../../mongoose.c ../../mqtt/mqtt-client/mongoose_mqtt.c) target_include_directories(firmware PRIVATE ../../.. ./) target_link_libraries(firmware pico_stdlib hardware_spi pico_rand pico_cyw43_driver pico_cyw43_arch_none hardware_flash pico_bootrom) diff --git a/tutorials/rp/pico-w/main.c b/tutorials/rp/pico-w/main.c index 670b2d8e..fa14a4f7 100644 --- a/tutorials/rp/pico-w/main.c +++ b/tutorials/rp/pico-w/main.c @@ -65,11 +65,13 @@ static void run_mongoose(void) { struct mg_mgr mgr; mg_log_set_fn(log_fn, NULL); mg_mgr_init(&mgr); + mg_mqtt_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0", http_ev_handler, NULL); mg_http_listen(&mgr, "https://0.0.0.0", http_ev_handler, NULL); for (;;) { mg_mgr_poll(&mgr, 1); + mg_mqtt_poll(&mgr); blink_task(); } } diff --git a/tutorials/rp/pico-w/mongoose_config.h b/tutorials/rp/pico-w/mongoose_config.h index ac4d4851..eb2115dd 100644 --- a/tutorials/rp/pico-w/mongoose_config.h +++ b/tutorials/rp/pico-w/mongoose_config.h @@ -5,6 +5,7 @@ #define MG_TLS MG_TLS_BUILTIN #define MG_OTA MG_OTA_PICOSDK #define MG_IO_SIZE 2048 +#define MQTT_CLIENT_ID "rp" // For tutorials/mqtt/mqtt-client #define MG_ENABLE_TCPIP 1 #define MG_ENABLE_DRIVER_PICO_W 1 diff --git a/tutorials/stm32/nucleo-h563zi/cubemx/mongoose/dashboard.c b/tutorials/stm32/nucleo-h563zi/cubemx/mongoose/dashboard.c index 259243c8..b986a0a3 100644 --- a/tutorials/stm32/nucleo-h563zi/cubemx/mongoose/dashboard.c +++ b/tutorials/stm32/nucleo-h563zi/cubemx/mongoose/dashboard.c @@ -259,6 +259,7 @@ void mg_dash_init(struct mg_mgr *mgr) { // Read settings from flash struct mg_dash_user u = {.level = 9}; // Super mega user settings_fn(MG_DASH_READ, &u); + s_dash.authenticate = s_enable_login ? authenticate : NULL; mg_mem_files = mg_packed_files; mg_http_listen(mgr, MG_HTTP_ADDR, mg_dash_ev_handler, &s_dash);