ifneq (,$(wildcard .env)) include .env export $(shell sed 's/=.*//' .env) endif ENV = esp32dev BUILD_FLAGS = -D WIFI_SSID="\\\"$(WIFI_SSID)\\\"" \ -D WIFI_PASS="\\\"$(WIFI_PASS)\\\"" \ -D MQTT_URI="\\\"$(MQTT_URI)\\\"" 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)" PLATFORMIO_BUILD_FLAGS="$(BUILD_FLAGS)" pio run -e $(ENV) upload: @echo "Starting uploading process..." PLATFORMIO_BUILD_FLAGS="$(BUILD_FLAGS)" pio run -e $(ENV) -t upload monitor: @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 debug-flags: @echo $(BUILD_FLAGS) test: @echo "Starting unit tests..." PLATFORMIO_BUILD_FLAGS="$(BUILD_FLAGS)" pio test -e $(ENV) -vvv