PORT := BAUD := 115200 PIOBOARD = nodemcuv2 PIOPROJ = firmware/esplogger PIODIR = .pio .PHONY: firmware monitor reset getport all: firmware install-pip3: wget https://bootstrap.pypa.io/get-pip.py && \ sudo python3 get-pip.py && rm get-pip.py install-platformio: wget https://bootstrap.pypa.io/get-pip.py && \ sudo python get-pip.py && rm get-pip.py sudo pip install platformio $(MAKE) add-udev-rules $(MAKE) add-dialout add-dialout: sudo usermod -a -G dialout $$USER add-udevrules: wget https://raw.githubusercontent.com/platformio/platformio/develop/scripts/99-platformio-udev.rules sudo cp -v 99-platformio-udev.rules /etc/udev/rules.d sudo service udev restart firmware: build upload monitor build: which platformio || $(MAKE) install-platformio @ echo "$$PIO_BUILD" | sh upload: which platformio || $(MAKE) install-platformio cd $(PIODIR) && platformio run -t upload monitor: platformio device monitor reset: getport @ echo "-----------------------------------------" @ echo "Reseting the board" esptool.py --port /dev/$(PORT) run @ python -c "import time; time.sleep(1)" getport: @ $(eval PORT := `python utils/getport.py`) @ echo $(PORT) example-blink: $(eval PIOPROJ := examples/blink) @ echo "$$PIO_BUILD" | sh example-wifiscan: $(eval PIOPROJ := examples/wifiscan) @ echo "$$PIO_BUILD" | sh $(MAKE) monitor example-sdcardinfo: $(eval PIOPROJ := examples/sd_card_info) @ echo "$$PIO_BUILD" | sh $(MAKE) monitor help: @ echo "$$HELP_MAKEFILE" clean: rm -rfv $(PIODIR) define HELP_MAKEFILE Usage: make where can be: firmware Build and upload the esplogger firmware using platformio monitor Start the picocom serial monitor (autodetect port) reset Attempt a soft reset of the ESP devkit board example-____ Build and upload one of the examples/ projects: blink -- turn on and off the led on pin 2 wifiscan -- detect and print all available SSIDs endef export HELP_MAKEFILE define PY_GET_PORT import os ports = [x for x in os.listdir("/dev") if x.startswith("ttyUSB") or x.startswith("ttyACM")] if ports and isinstance(ports[0], str): print(ports[0]) else: print("Error: Unable to find a ttyUSB/ttyACM serial port") raise SystemExit(1) endef export PY_GET_PORT define PIO_BUILD mkdir -p $(PIODIR) rm -rf $(PIODIR)/src platformio init --board $(PIOBOARD) -d $(PIODIR) cp -rf $(PIOPROJ)/* $(PIODIR)/src/ cd $(PIODIR) && platformio run endef export PIO_BUILD