ok. here a quick how to store and graph data from MQTT it is easy> a couple of people have asked
after you have your MQTT being published from your devices - you need to capture them. but before you can do that you need to create a rrd container data base
this one by example averages out 3 sent mqtt and creates a data base called KW with in the container of 2.6 million entries or about 90 days of data stored if you send data every second
rrdtool create wind.rrd --step 3 DS:kw:GAUGE:5:0:U RRA:MIN:0.5:12:2592000 RRA:AVERAGE:0.5:1:2592000 RRA:MAX:0.5:1:2592000
next you will need to capture the topics the easiest is a simple pl script
#!/usr/bin/perl -w
open(SUB, "/usr/bin/mosquitto_sub -t /wind |");
#SUB->autoflush(1);
while ($wind = <SUB>) {
$wind=($wind/1000);
print "$wind ";
system("rrdtool update wind.rrd N:$wind");
}
this listens for a topic called /wind and when it receives a topic it writes it to the rrd container called wind.rrd ( the emontx was sending mqtt in watts so I divided by 1000 to make it kw for the rrd container)
that’s it, that was simple: now to create a graph:
this particular one creates a graph that is 24 hours in length, displays the min avg, and peak. it also calculates your daily cost and projects your monthly production based on that day
#!/bin/bash
now=$(date +%s)
now_formatted=$(date +%s | awk '{printf "%s\n", strftime("%c",$1)}' | sed -e 's/:/\\:/g')
/usr/bin/rrdtool graph /var/www/html/24hrswind.png \
-w 543 -h 267 -a PNG \
--slope-mode \
--start -86200 --end now \
--title "Wind: For the Last 24 Hours" \
--vertical-label "KILOWATTS (KW)" \
DEF:kw=wind.rrd:kw:AVERAGE \
VDEF:Last=kw,LAST \
VDEF:First=kw,FIRST \
VDEF:Min=kw,MINIMUM \
VDEF:Peak=kw,MAXIMUM \
VDEF:Average=kw,AVERAGE \
CDEF:kWh=kw,10,/,168,* \
CDEF:Proj=kw,1,/,720,* \
CDEF:Cost=kWh,.0665,* \
CDEF:Costp=Proj,.0665,* \
LINE1:kw#005199FF:"wind " \
AREA:kw#00519933:"" \
GPRINT:Last:"%6.4lf%sKW" \
COMMENT:"\\n" \
HRULE:Average#9595FF:"Average" \
GPRINT:kw:AVERAGE:"%6.4lf%sKW" \
COMMENT:"\\n" \
HRULE:Peak#ff0000:"Peak " \
GPRINT:kw:MAX:"%6.3lf%sKW" \
COMMENT:"\\n" \
HRULE:Min#58FAF4:"Min " \
GPRINT:kw:MIN:"%6.4lf%sKW" \
COMMENT:"\\n" \
GPRINT:kWh:AVERAGE:" total %6.2lfkWh\\n" \
GPRINT:Cost:AVERAGE:" cost %6.2lf $\\n" \
GPRINT:Proj:AVERAGE:" Projected %6.2lfKWh in a 30 Day period\\n" \
GPRINT:Costp:AVERAGE:" cost %6.2lf $\\n" \
COMMENT:" \\n" \
now all you need to to do is in cron set the Mqtt.pl to run on boot to capture mqtt
and the 24hrs graph script to run every few minutes.
for other optoins using rrdtools see RRDtool - RRDtool Documentation
as a suggestion if you are not the most linux savy person it easy to install webmin. once that is install you have a nice webbase administration panel to talk to you pi or sever remotely to move files around and set up cron or what have you…
good luck have fun