summaryrefslogtreecommitdiff
path: root/src/main/Makefile
blob: 2000b24090bd96fe57a53ef640e31ce6246dae80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Optionally some environment variables can be set:
#
#   FQBN        Fully Qualified Board Name; if not set in the environment
#               it will be assigned a value in this makefile
#
#   SERIAL_DEV  Serial device to upload the sketch; if not set in the
#               environment it will be assigned:
#               /dev/ttyUSB0   if it exists, or
#               /dev/ttyACM0   if it exists, or
#               unknown
#
#   IOT_NAME    Name of the IOT device; if not set in the environment
#               it will be assigned a value in this makefile. This is
#               very useful for OTA update, the device will be searched
#               on the local subnet using this name
#
#   OTA_PORT    Port used by OTA update; if not set in the environment
#               it will be assigned the default value of 8266 in this
#               makefile
#
#   OTA_PASS    Password used for OTA update; if not set in the environment
#               it will be assigned the default value of an empty string

FQBN      =  esp8266:esp8266:espmxdevkit
IOT_NAME  =  mush
OTA_PORT  =  8266
OTA_PASS  =

SERIAL_DEV = $(firstword $(wildcard /dev/ttyUSB* /dev/ttyACM*))

cli = arduino-cli -b "$(FQBN)"

BUILD_DIR != $(cli) compile --show-properties | sed -ne 's/^build.path=//p'

SRC        := main.ino
HDRS       := $(wildcard *.h)
BIN        := $(BUILD_DIR)/main.ino.bin
ELF        := $(BUILD_DIR)/main.ino.elf

all: $(ELF)
.PHONY: all

compile: $(ELF)
.PHONY: compile

$(BIN) $(ELF): $(SRC) $(HDRS)
	$(cli) compile

upload:
	$(cli) upload -p "$(SERIAL_DEV)"

PLAT_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.platform.path=//p'
PY_PATH != $(cli) compile --show-properties | sed -ne 's/^runtime.tools.python3.path=//p'
IOT_IP != getent ahostsv4 mush.local | (read ip _; echo $$ip)

ota: $(BIN)
	"$(PY_PATH)/python3" "$(PLAT_PATH)/tools/espota.py" -i "$(IOT_IP)" -p "$(OTA_PORT)" --auth="$(OTA_PASS)" -f "$(BIN)"