From a27af14e815ef993e9a0c94e5bc8b32dbf989a94 Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Wed, 29 Oct 2025 13:29:27 +0100 Subject: Solve baud detection bug, fix wifi searching task scheduling bug, improve documentation, implement additional mqtt topics --- firmware/Makefile | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'firmware/Makefile') diff --git a/firmware/Makefile b/firmware/Makefile index 0fd1699..0595792 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -9,7 +9,29 @@ BUILD_FLAGS = -D WIFI_SSID="\\\"$(WIFI_SSID)\\\"" \ -D WIFI_PASS="\\\"$(WIFI_PASS)\\\"" \ -D MQTT_URI="\\\"$(MQTT_URI)\\\"" -.PHONY: build upload monitor clean debug-flags test +PORT ?= $(shell ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | head -n 1) + +ifdef BAUD + BAUD := $(BAUD) +else ifneq ("$(wildcard .baud_detected)","") + BAUD := $(shell cat .baud_detected) +else + BAUD := 115200 +endif + +detect-baud: + @echo "[*] Detecting correct baud rate..." + @if screen -L -dmS test_screen $(PORT) 74880; then \ + sleep 1; \ + grep -q "rst:" screenlog.0 && echo "74880" > .baud_detected || echo "115200" > .baud_detected; \ + rm -f screenlog.0; \ + screen -S test_screen -X quit; \ + else \ + echo "115200" > .baud_detected; \ + fi + @echo "[✓] Set BAUD=$$(cat .baud_detected)" + +.PHONY: build upload monitor clean debug-flags test detect-baud build: @echo "Starting build with SSID=$(WIFI_SSID)" @@ -20,7 +42,11 @@ upload: PLATFORMIO_BUILD_FLAGS="$(BUILD_FLAGS)" pio run -e $(ENV) -t upload monitor: - pio device monitor -e $(ENV) + @PORT=$(PORT); \ + BAUD=$(BAUD); \ + if [ -z "$$PORT" ]; then echo "[ERROR] Port /dev/ttyUSB* or /dev/ttyACM* not found"; exit 1; fi; \ + echo "[*] Opening monitor: $$PORT @ $$BAUD baud"; \ + screen $$PORT $$BAUD clean: pio run -e $(ENV) -t clean -- cgit v1.2.3