smick_main_v05r01
Con tale main le misure ricevute dai sensori sono archiviate nella tabella db. E’ possibile verificarne l’inserimento tramite la fuzione SELECT COUNT(*) del flow dbms.
[{"id":"d8070d8c.97fed8","type":"subflow","name":"db insert","info":"","in":[{"x":80,"y":80,"wires":[{"id":"bc6b81e4.7796e"}]}],"out":[{"x":580,"y":80,"wires":[{"id":"2b721cd5.ed20dc","port":0}]}]},{"id":"bc6b81e4.7796e","type":"template","z":"d8070d8c.97fed8","name":"INSERT","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO db \n (time,\n sn,\n name,\n pos,\n class,\n field1,\n field2,\n field3,\n field4\n )\nVALUES \n (CURRENT_TIMESTAMP,\n \"{{payload.Sn}}\",\n \"{{payload.name}}\",\n \"{{payload.pos}}\",\n {{payload.class}},\n \"{{payload.field1}}\",\n \"{{payload.field2}}\",\n \"{{payload.field3}}\",\n \"{{payload.field4}}\"\n )","output":"str","x":240,"y":80,"wires":[["2b721cd5.ed20dc"]]},{"id":"2b721cd5.ed20dc","type":"mysql","z":"d8070d8c.97fed8","mydb":"fd196c36.4d8748","name":"db","x":430,"y":80,"wires":[[]]},{"id":"fd196c36.4d8748","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"nodered","tz":"'-02:00'"},{"id":"1810f828.1dba7","type":"subflow","name":"dht22 dash","info":"","in":[{"x":40,"y":160,"wires":[{"id":"da56c1b7.d408f"}]}],"out":[],"inputLabels":["json object"]},{"id":"ce3e00d1.9910b","type":"ui_gauge","z":"1810f828.1dba7","name":"","group":"77924864.53a6a8","order":0,"width":0,"height":0,"gtype":"gage","title":"","label":"°C","format":"{{value}}","min":"-10","max":"60","colors":["#80ffff","#ffff00","#ca3838"],"seg1":"12","seg2":"30","x":590,"y":80,"wires":[]},{"id":"7f24dba2.039fc4","type":"ui_gauge","z":"1810f828.1dba7","name":"","group":"653447b3.15c82","order":0,"width":0,"height":0,"gtype":"donut","title":"","label":"% RH","format":"{{msg.payload}}","min":"0","max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":590,"y":180,"wires":[]},{"id":"456f298d.e39918","type":"ui_chart","z":"1810f828.1dba7","name":"","group":"77924864.53a6a8","order":0,"width":0,"height":0,"label":"temperature (°C)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Sensor not connected","dot":true,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":630,"y":120,"wires":[[],[]]},{"id":"77bf9ff0.4a21","type":"ui_chart","z":"1810f828.1dba7","name":"","group":"653447b3.15c82","order":0,"width":0,"height":0,"label":"humidity (% RH)","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Sensor not connected","dot":true,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":620,"y":220,"wires":[[],[]]},{"id":"7a48836e.c5bb54","type":"change","z":"1810f828.1dba7","name":"Temp","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.field1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":100,"wires":[["ce3e00d1.9910b","456f298d.e39918"]]},{"id":"fa1bbc2b.cdfea","type":"change","z":"1810f828.1dba7","name":"Hum","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.field2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":200,"wires":[["7f24dba2.039fc4","77bf9ff0.4a21"]]},{"id":"da56c1b7.d408f","type":"switch","z":"1810f828.1dba7","name":"switch(class)","property":"payload.class","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"}],"checkall":"true","outputs":3,"x":190,"y":160,"wires":[["7a48836e.c5bb54","fa1bbc2b.cdfea"],[],[]],"outputLabels":["class==1: field1=Temp, field2=Hum","class==2: TBD","class==3: TBD"]},{"id":"77924864.53a6a8","type":"ui_group","z":"","name":"Temperature","tab":"3dccec0c.f37104","order":1,"disp":true,"width":"6","collapse":true},{"id":"653447b3.15c82","type":"ui_group","z":"","name":"Humidity","tab":"3dccec0c.f37104","order":2,"disp":true,"width":"6","collapse":true},{"id":"3dccec0c.f37104","type":"ui_tab","z":"","name":"Room","icon":"dashboard","order":7},{"id":"aa831b20.f3f35","type":"subflow","name":"dht22 sensor","info":"","in":[],"out":[{"x":420,"y":80,"wires":[{"id":"9779aeaa.70918","port":0}]}],"outputLabels":["message from sensor"]},{"id":"b783fa98.116208","type":"mqtt in","z":"aa831b20.f3f35","name":"","topic":"out/dht22","qos":"0","broker":"eed163.62e4bea","x":120,"y":80,"wires":[["9779aeaa.70918"]]},{"id":"9779aeaa.70918","type":"json","z":"aa831b20.f3f35","name":"","pretty":false,"x":290,"y":80,"wires":[[]]},{"id":"eed163.62e4bea","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"3ae75f15.d892a8","type":"subflow:aa831b20.f3f35","z":"d281347a.9bf4a","name":"","x":130,"y":120,"wires":[["f50ce513.b19668","9f0bbf88.b8b518","cd4b7655.3eaa28"]]},{"id":"f50ce513.b19668","type":"debug","z":"d281347a.9bf4a","name":"","active":true,"console":"false","complete":"payload","x":350,"y":80,"wires":[]},{"id":"9f0bbf88.b8b518","type":"subflow:1810f828.1dba7","z":"d281347a.9bf4a","name":"","x":350,"y":120,"wires":[]},{"id":"cd4b7655.3eaa28","type":"subflow:d8070d8c.97fed8","z":"d281347a.9bf4a","name":"","x":340,"y":160,"wires":[["2d096d4d.f1f4ba"]]},{"id":"2d096d4d.f1f4ba","type":"debug","z":"d281347a.9bf4a","name":"","active":true,"console":"false","complete":"payload","x":530,"y":160,"wires":[]}]