From 1f68c5a8ea9776ba37d682f34e9b5cc1b96fb5f5 Mon Sep 17 00:00:00 2001
From: Wolfgang Hottgenroth
+This is my first attempt to build a tweetbot. I'm using node-red both as development and runtime environment. It comes with dedicated plugins for both InfluxDB and Twitter.
+
+The whole flow of the tweetbot is this:
+
+
+It starts with an inject node "Daily at noon" (*), with triggers the whole flow once a day at high noon.
+
+The four influx query nodes read data from the InfluxDB using the following queries, each one encapsulated in one influx query node:
+
+#title#
+
+
+
+See one of this node here.
+
+select mean(pv) from measured where deviceid = 'Hedge' and kind = 'Temperature' and time > now() - 15m
+select mean(pv) from measured where deviceid = 'Hedge' and kind = 'Temperature' and time > now() - 24h
+select min(pv) from measured where deviceid = 'Hedge' and kind = 'Temperature' and time > now() - 24h
+select max(pv) from measured where deviceid = 'Hedge' and kind = 'Temperature' and time > now() - 24h
+
+The data in the InfluxDB considered by these queries looks like this: + +
+> select * from measured where kind = 'Temperature' and deviceid = 'Hedge' limit 10 +name: measured +time category deviceid kind pv qv sv tv +---- -------- -------- ---- -- -- -- -- +2018-12-24T12:57:42.749065469Z Outdoor Hedge Temperature 5.029083728790283 -1 +2018-12-24T12:58:54.77913537Z Outdoor Hedge Temperature 5.020352363586426 -1 +2018-12-24T13:00:06.754460483Z Outdoor Hedge Temperature 5.032242298126221 -1 +2018-12-24T13:01:18.76525238Z Outdoor Hedge Temperature 5.024284362792969 -1 +2018-12-24T13:02:30.767286588Z Outdoor Hedge Temperature 5.016140937805176 -1 +2018-12-24T13:03:42.765550192Z Outdoor Hedge Temperature 5.0108466148376465 -1 +2018-12-24T13:04:54.774511705Z Outdoor Hedge Temperature 5.019856929779053 -1 +2018-12-24T13:06:05.772434549Z Outdoor Hedge Temperature 5.020042419433594 -1 +2018-12-24T13:07:16.759739681Z Outdoor Hedge Temperature 5.036855697631836 -1 +2018-12-24T13:08:27.757626686Z Outdoor Hedge Temperature 4.993878364562988 -1 +> ++ +
pv
has the temperature, sv
has the battery voltage. In this case it is -1 since this particular thermometer is powered by a power supply from mains.
+
+
+
++In the following four change nodes (*) a dedicated topic for the messages from the influx query nodes will be set to merge them into a single key/value object in the following join node (*). This node will collect four messages and put them into a single object with the topic as key and the message as value. +
+ ++This object in turn is input for the function node "TextPreparator" (*) where the tweet is prepared using a small snippet of JavaScript code: + +
+let output = ""
+output += `Die aktuelle Temperatur zuhause ist ${msg.payload.avg15min[0].mean.toFixed(1)}°C.\n`
+output += `Die Durchschnittstemperatur der letzten 24 Stunden war ${msg.payload.avg24h[0].mean.toFixed(1)}°C, `
+output += `die Tiefsttemperatur war ${msg.payload.min[0].min.toFixed(1)}°C um ${msg.payload.min[0].time.getHours()}:${msg.payload.min[0].time.getMinutes()} Uhr und `
+output += `die Höchsttemperatur war ${msg.payload.max[0].max.toFixed(1)}°C um ${msg.payload.max[0].time.getHours()}:${msg.payload.max[0].time.getMinutes()} Uhr.\n`
+output += "Powered by @NodeRED and @InfluxDB."
+msg.payload = output
+return msg;
+
+
+
++Finally this text will be sent to Twitter via the node "Tweet" (*). Done. +
+ +
+
+
PNfuVkDl1fh<
z+x_^yHA4ENg-XC&C4>PM;wR|O+8tT>=m$~pR1Hu5KvNUBieFj=8;FDr_Vh8TOj0%*
zs(hZs`qx1Qgl%<80sH<9@U@(xcmv^n^0xLQwPablKuudq6CB((SYY4g?JLZ6x)8XC
z^CyOvJ1-wf)6iG8=RA21l)XduCK7CQ_b!S^FYKB4_6;O9y+hr`G1m1YyEm5VnSJ+H
z@gW2NG)$+)DD-$ei0}pn?Y&yo9CVt`0kkLk4%o1n GM0jT2^$-amRu_V-iGmN{U|oi
z9?3|=Wc6Mq7L+i*moZLQX=mv7fX=kB*qy)ql=3Q?;ua=I5MuXd`Y$)5Jm?SpQFixC
zS({4&ykj!=@2C}(J9~LipWTnkMp`b{vuARu3=a11n{WNzKjhq;N_4J1@t0e-#55P6
zM}yzvz
zot$@}kH>xu1i0{FtfqZy=R?eBtAUuZhhVrDALQSjhYzp^Lj~4(F6%j9`!z)u+-YQV
zx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