# 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
png/$(sensor): \
$$(patsubst rrd/%.rrd,png/$(sensor)/%.png,$$(.rrd))
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 '$$(SENSOR_LABEL_$(sensor))' \
--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 '$$(SENSOR_LABEL_$(sensor))' \
--x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
DEF:$(sensor)=rrd/$$*.rrd:$(sensor):$$(RRD_CF) \
LINE1:$(sensor)'#ff0000':"$(sensor)"; \
done
endef
SENSOR_LABEL_temperature=Température (°C)
SENSOR_LABEL_humidity=Humidité (%)
SENSOR_LABEL_particles=Particules
SENSOR_LABEL_quality=Qualité de l’air
$(foreach sensor,$(SENSORS),$(eval $(call png/sensor)))