Nano Flow
The Node-RED flow for the Nano circuit is shown below.
Code
You can recreate the flow by importing the code below into your Node-RED editor.
[{"id":"bfd1e3badb9499a8","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"00180b1933d5abe1","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"90844ce0ad4c8dc2","type":"mqtt-broker","name":"Public HiveMQ","broker":"broker.hivemq.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"3062fea8ab76f99f","type":"mqtt-broker","name":"STEMVentor HiveMQ","broker":"0d7e686af22d4bada5068acbd9312761.s1.eu.hivemq.cloud","port":"8883","tls":"","clientid":"","autoConnect":true,"usetls":true,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"cff5a75f4cdc8c3c","type":"mqtt-broker","name":"EMQX Public Broker","broker":"broker.emqx.io","port":"8883","tls":"","clientid":"","autoConnect":true,"usetls":true,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"98dbac6f7bfc9d91","type":"serial-port","name":"","serialport":"COM9","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"1d0ca10b263cd761","type":"inject","z":"bfd1e3badb9499a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":170,"y":520,"wires":[["abad54cfeaadf1f1"]]},{"id":"abad54cfeaadf1f1","type":"function","z":"bfd1e3badb9499a8","name":"function 1","func":"var random_value = Math.floor(Math.random() * 100);\nvar newMsg = {payload:{sensor_name: \"Sensor 1\", value: random_value}};\nreturn newMsg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":520,"wires":[["d982d4cc0cdbd363"]]},{"id":"33318e6bed4d7a13","type":"debug","z":"bfd1e3badb9499a8","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":520,"wires":[]},{"id":"d982d4cc0cdbd363","type":"json","z":"bfd1e3badb9499a8","name":"","property":"payload","action":"","pretty":false,"x":510,"y":520,"wires":[["33318e6bed4d7a13","021eb51a35501c3b"]]},{"id":"021eb51a35501c3b","type":"mqtt out","z":"bfd1e3badb9499a8","name":"","topic":"sensor-1","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"90844ce0ad4c8dc2","x":700,"y":440,"wires":[]},{"id":"ece07d233cbc3cd9","type":"mqtt in","z":"bfd1e3badb9499a8","name":"","topic":"device-1","qos":"2","datatype":"auto-detect","broker":"90844ce0ad4c8dc2","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":620,"wires":[["5d6c873db12e107b"]]},{"id":"5d6c873db12e107b","type":"debug","z":"bfd1e3badb9499a8","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":620,"wires":[]},{"id":"8d5e3af5ccfb3f79","type":"inject","z":"bfd1e3badb9499a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":170,"y":800,"wires":[["59a828b1e32bf639"]]},{"id":"59a828b1e32bf639","type":"function","z":"bfd1e3badb9499a8","name":"function 2","func":"var random_value = Math.floor(Math.random() * 100);\nvar newMsg = {payload:{sensor_name: \"Sensor 2\", value: random_value}};\nreturn newMsg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":800,"wires":[["a3703e33aa36ba5a"]]},{"id":"ee235639252b4945","type":"debug","z":"bfd1e3badb9499a8","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":800,"wires":[]},{"id":"a3703e33aa36ba5a","type":"json","z":"bfd1e3badb9499a8","name":"","property":"payload","action":"","pretty":false,"x":510,"y":800,"wires":[["ee235639252b4945","bfe5c037ef698e3a"]]},{"id":"bfe5c037ef698e3a","type":"mqtt out","z":"bfd1e3badb9499a8","name":"","topic":"sensor-2","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"3062fea8ab76f99f","x":700,"y":720,"wires":[]},{"id":"384d9908c6268195","type":"inject","z":"bfd1e3badb9499a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":170,"y":980,"wires":[["bea6c1d1fc3ef85f"]]},{"id":"bea6c1d1fc3ef85f","type":"function","z":"bfd1e3badb9499a8","name":"function 3","func":"var random_value = Math.round(Math.random());\nvar newMsg = {payload:{sensor_name: \"Sensor 3\", value: random_value}};\nreturn newMsg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":980,"wires":[["fd871e18e515b61f"]]},{"id":"b8e286ddc696d92e","type":"debug","z":"bfd1e3badb9499a8","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":980,"wires":[]},{"id":"fd871e18e515b61f","type":"json","z":"bfd1e3badb9499a8","name":"","property":"payload","action":"","pretty":false,"x":510,"y":980,"wires":[["b8e286ddc696d92e","028508c5ad8a6ef0"]]},{"id":"028508c5ad8a6ef0","type":"mqtt out","z":"bfd1e3badb9499a8","name":"","topic":"sensor-3","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"cff5a75f4cdc8c3c","x":700,"y":900,"wires":[]},{"id":"57c5c51f71152c52","type":"serial in","z":"bfd1e3badb9499a8","name":"Nano Serial In","serial":"98dbac6f7bfc9d91","x":190,"y":120,"wires":[["d750b9a761b1ae01","803697000626f7f8"]]},{"id":"d750b9a761b1ae01","type":"debug","z":"bfd1e3badb9499a8","name":"Nano Debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":120,"wires":[]},{"id":"803697000626f7f8","type":"json","z":"bfd1e3badb9499a8","name":"","property":"payload","action":"obj","pretty":false,"x":390,"y":220,"wires":[["daf944a20d8d50b0"]]},{"id":"80de1da00bd1737e","type":"function","z":"bfd1e3badb9499a8","name":"processTemperature","func":"// Access the node's context object\n// var nodeContext = this.context();\n// var flowContext = this.context().flow;\n// var globalContext = this.context().global;\n\n// initialise the counter to 0 if it doesn't exist already\nvar count = context.get('count') || 0;\ncount += 1;\n// store the value back\ncontext.set('count', count);\n\nvar new_payload = {};\nnew_payload.display = msg.payload.value + \"deg C\";\nnew_payload.count = count;\n\nvar newMsg = { payload: new_payload };\nreturn newMsg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":180,"wires":[["d750b9a761b1ae01","6b0b0dd5a58a62fc"]]},{"id":"58d831e05a90ae6d","type":"inject","z":"bfd1e3badb9499a8","name":"TestTemperatureValue","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Temperature","payload":"{\"parameter\":\"Temperature\",\"value\":100}","payloadType":"json","x":200,"y":220,"wires":[["803697000626f7f8"]]},{"id":"daf944a20d8d50b0","type":"switch","z":"bfd1e3badb9499a8","name":"IdentifySensor","property":"payload.parameter","propertyType":"msg","rules":[{"t":"eq","v":"Temperature","vt":"str"},{"t":"eq","v":"Humidity","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":560,"y":260,"wires":[["80de1da00bd1737e"],["b3d97c337b6ec8e5"],["2787b0ed06e72f2c"]]},{"id":"b3d97c337b6ec8e5","type":"function","z":"bfd1e3badb9499a8","name":"processHumidity","func":"var new_payload = {};\nnew_payload.display = msg.payload.value + \"%\";\nvar newMsg = { payload: new_payload };\nreturn newMsg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":320,"wires":[["6b0b0dd5a58a62fc"]]},{"id":"6fe96cf2aab7ff5f","type":"inject","z":"bfd1e3badb9499a8","name":"TestHumidityValue","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Humidity","payload":"{\"parameter\":\"Humidity\",\"value\":60}","payloadType":"json","x":210,"y":300,"wires":[["803697000626f7f8"]]},{"id":"6b0b0dd5a58a62fc","type":"debug","z":"bfd1e3badb9499a8","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1020,"y":240,"wires":[]},{"id":"890cd31ce8ab7fb6","type":"debug","z":"bfd1e3badb9499a8","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":400,"wires":[]},{"id":"2787b0ed06e72f2c","type":"function","z":"bfd1e3badb9499a8","name":"function 4","func":"var new_msg = { payload: msg.payload.parameter };\n\nreturn new_msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":400,"wires":[["890cd31ce8ab7fb6"]]},{"id":"3bc8e1d2.744abe","type":"switch","z":"00180b1933d5abe1","name":"Route ","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"temperature","vt":"str"},{"t":"eq","v":"humidity","vt":"str"},{"t":"eq","v":"pressure","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":390,"y":200,"wires":[["907bf3b8.def45"],["fe425938.926838"],["ec261304.52f73"]]},{"id":"be3da36c.1c142","type":"inject","z":"00180b1933d5abe1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","payload":"27","payloadType":"num","x":200,"y":160,"wires":[["3bc8e1d2.744abe"]]},{"id":"f271ceef.172b3","type":"inject","z":"00180b1933d5abe1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"humidity","payload":"45","payloadType":"num","x":190,"y":200,"wires":[["3bc8e1d2.744abe"]]},{"id":"907bf3b8.def45","type":"debug","z":"00180b1933d5abe1","name":"Temperature","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":570,"y":160,"wires":[]},{"id":"fe425938.926838","type":"debug","z":"00180b1933d5abe1","name":"Humidity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":560,"y":200,"wires":[]},{"id":"ec261304.52f73","type":"debug","z":"00180b1933d5abe1","name":"Pressure","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":560,"y":240,"wires":[]},{"id":"fca957dd.9d8078","type":"inject","z":"00180b1933d5abe1","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pressure","payload":"1001","payloadType":"num","x":190,"y":240,"wires":[["3bc8e1d2.744abe"]]}]