# Licence: WTFPLv2
# Copyright 2015: Julien Moutinho
.SECONDARY:
.SUFFIXES:
MAKEFLAGS += -r
RRD_CF:=AVERAGE
SENSORS:= \
humidity \
temperature \
quality \
particles
.rrd = $(wildcard rrd/*/*.rrd)
all: png
#
## INO
###
# For GNU/Linux
ARDUINO_DIR := /usr/share/arduino/
ARDMK_DIR := /usr/share/arduino/
AVR_TOOLS_DIR := /usr
# For Seeeduino
BOARD_TAG := uno
ARDUINO_LIBS := \
AirQuality_Sensor \
DustSensor \
Humidity_Temperature_Sensor \
LCD_Display9696 \
Wire
USER_LIB_PATH := $(abspath ./libraries)
include $(ARDMK_DIR)/Arduino.mk
ino: $(TARGET_EEP) $(TARGET_HEX)
#
## PNG
###
.PHONY: png $(addprefix png/,$(SENSORS))
png: $(addprefix png/,$(SENSORS))
ym=$(patsubst %.rrd,,$(notdir $*))
month_begin=$(shell date +'%s' -d '$(ym)/01')
month_end=$(shell date +'%s' -d '$(ym)/01 + 1 month - 1 second')
month_length=$(shell date +'%d' -d '$(ym)/01 + 1 month - 1 second')
day_begin=$(shell date +'%s' -d '$(ym)/$(day)')
day_end=$(shell date +'%s' -d '$(ym)/$(day) + 1 month - 1 second')
define png/sensor
sensor:=$1
label:=$2
png/$$(sensor): \
$$(patsubst rrd/%.rrd,png/$$(sensor)/%.png,$$(.rrd))
echo $$@
png/$$(sensor)/%.png: rrd/%.rrd
mkdir -p png/$$(sensor)/$$*
rrdtool graph $$@ \
-w 785 -h 120 -a PNG \
--slope-mode \
--start $$(month_begin) --end $$(month_end) \
--vertical-label '$$(label)' \
--x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
DEF:$$(sensor)=rrd/$$*.rrd:$$(sensor):$$(RRD_CF) \
LINE1:$$(sensor)'#ff0000':"$$(sensor)"
for day in $$(shell seq -w $$(month_length)); \
do \
day_begin=$$$$(date +'%s' -d "$$(ym)/$$$$day"); \
day_end=$$$$(date +'%s' -d "$$(ym)/$$$$day + 1 day - 1 second"); \
rrdtool graph png/$$(sensor)/$$*/$$$$day.png \
-w 785 -h 120 -a PNG \
--slope-mode \
--start $$$$day_begin --end $$$$day_end \
--vertical-label '$$(label)' \
--x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
DEF:$$(sensor)=rrd/$$*.rrd:$$(sensor):$$(RRD_CF) \
LINE1:$$(sensor)'#ff0000':"$$(sensor)"; \
done
endef
)=)
$(eval $(call png/sensor,temperature,Température (°C$)))
$(eval $(call png/sensor,humidity,Humidité (%$)))
$(eval $(call png/sensor,particles,Particules))
$(eval $(call png/sensor,quality,Qualité de l’air))