Makefile 4.42 KB
Newer Older
1
2
PYVER := 3
VENV := .venv
3
INODIR := .ino
4
5
6
7

all: help

help:
8
	@ echo "USAGE: make <command>"
9
	@ echo ""
10
	@ echo "COMMANDS:"
11
	@ echo ""
12
	@ echo "  full           --  setup & bu & deploy-logger"
13
	@ echo ""
14
15
16
	@ echo "  apt-install      --  Uses Debian's apt to install required system tools"
	@ echo "  venv             --  Creates a Python local virtual environment at ${VENV}"
	@ echo "  setup            --  apt-install & venv"
17
	@ echo ""
18
19
20
21
22
	@ echo "  build          --  Compile the sketch usin Ino Tool"
	@ echo "  upload         --  Send the compiled sketch to the board using Ino Tool"
	@ echo "  serial         --  Enter IPython session with serial opened"
	@ echo "  bu             --  build & upload"
	@ echo "  bus            --  build & upload & serial"
23
	@ echo ""
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	@ echo "  sync-rtc       --  Synchronizes the board's clock with the system's"
	@ echo ""
	@ echo "  run-logger      --  Starts the logger. Keep log at logger/logs"
	@ echo "  deploy-logger   --  Activate logger daemon. Keep log at logger/logs/"
	@ echo "  undeploy-logger --  Deactivate logger daemon"
	@ echo ""
	@ echo "  tail-log       --  Exibits and follow last modified execution log file"
	@ echo "  tail-data      --  Exibits and follow last modified datalog file"
	@ echo ""
	@ echo "  plot-data col=<C>  --  Uses Gnuplot to plot last modified datalog file"
	@ echo "                         Replace <C> with the column number to plot as y axis"
	@ echo "  clean-venv     --  Remove Python's virtual environment directory"
	@ echo "  clean-ino      --  Remove Ino folder"
	@ echo "  clean-data     --  !!! CAUTION !!! Remove all datalog files"
	@ echo "  clean-logs     --  !!! CAUTION !!! Remove all execution log files"
	@ echo "  clean-all      --  Performs all the above cleans" 
40
41
42
	@ echo ""

apt-install:
43
	sudo apt-get install python python3 python3-pip supervisor python-pip
44
45
	sudo pip${PYVER} install virtualenv
	sudo pip2 install ino
46
47

setup: apt-install venv
48
	
49
venv: clean-venv
50
51
52
53
54
55
	@ echo "-------------------------------------------------------"
	virtualenv -v --python='python${PYVER}' ${VENV}
	@ echo "Virtualenv with 'python${PYVER}' interpreter was created at ${VENV}"
	@ echo "-------------------------------------------------------"
	${VENV}/bin/pip install --upgrade pip
	@ echo "-------------------------------------------------------"
Nelso Jost's avatar
Nelso Jost committed
56
	${VENV}/bin/pip install -r logger/requirements.pip
57
58
59
60
61
62
63
64
65
66
	@ echo "-------------------------------------------------------"
	@ echo "Virtualenv is ready at ${VENV}!"
	@ echo " "
	@ echo "TOTAL SIZE: "
	@ du -sh ${VENV}

clean-venv:
	rm -rf ${VENV}

build:
67
68
69
70
71
	$(eval MODEL := $(shell ${VENV}/bin/python -c "from logger.app import Meteorologger; print(Meteorologger().CFG['ARDUINO']['BOARD_MODEL'])"))
	mkdir -p ${INODIR}
	mkdir -p ${INODIR}/src/ ${INODIR}/lib/
	cp -rf meteorolog/. ${INODIR}/src/
	cd ${INODIR}/ && ino build -m $(MODEL)
72
73
	
upload:
74
75
76
	$(eval MODEL := $(shell ${VENV}/bin/python -c "from logger.app import Meteorologger; print(Meteorologger().CFG['ARDUINO']['BOARD_MODEL'])"))
	$(eval PORT := $(shell ${VENV}/bin/python -c "from logger.app import Meteorologger; print(Meteorologger().CFG['ARDUINO']['SERIAL_PORTS'][0])"))
	cd ${INODIR}/ && ino upload -m $(MODEL) -p $(PORT)
77
78

serial:
79
	${VENV}/bin/ipython -i logger/init_serial.py
80
81
82
83
84
85
86
87
88
89
90

bu: build upload

bus: build upload serial

sync-rtc:
	${VENV}/bin/python${PYVER} run.py --syncrtc
 
run-logger:
	${VENV}/bin/python logger/run.py

91
deploy-logger: undeploy-logger
92
93
94
95
96
97
98
	mkdir -p logger/logs
	sudo ${VENV}/bin/python${PYVER} logger/deploy.py

undeploy-logger:
	sudo ${VENV}/bin/python${PYVER} logger/deploy.py -u

tail-logger:
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	$(eval TMP := $(shell ls -t -I stdout* logger/logs/ | head -n 1))
	@ echo "Last log file updated: logger/logs/$(TMP)"
	@ echo "File size: `du -h logger/logs/$(TMP) | cut -f1`"
	@ echo ""
	@ tail -F logger/logs/$(TMP)

plot-data:
	@ echo "Quit by closing the window with Q and hitting Ctrl+C here to end the process"
	@ cd tools && gnuplot -persist -e "config='config.plt'; col=${col}" loop.plt

tail-data:
	$(eval TMP := $(shell ls -t -I outgoing* data/ | head -n 1))
	@ echo "Last datalog file updated: data/$(TMP)"
	@ echo "Number of lines/points: `cat data/$(TMP) | wc -l`"
	@ echo "File size: `du -h data/$(TMP) | cut -f1`"
	@ echo ""
	@ head -1 data/$(TMP)
	@ echo ""
	@ tail -F data/$(TMP)

clean-data:
	rm -rfv data/*.csv data/outgoing/*.json

clean-logs:
	rm -rfv logger/logs/*

clean-ino:
	rm -rf ${INODIR}

clean-all: clean-data clean-logs clean-ino clean-venv
	cd logger && sudo py3clean app
Nelso Jost's avatar
Nelso Jost committed
130

131
full: setup bu deploy-logger