Sensor Data Flow
The Node-RED flow for capturing sensor data from the Nano and Pico circuits is shown below.
Code
You can recreate the flow by importing the code below into your Node-RED editor.
[{"id":"17fd02ad03f50979","type":"tab","label":"Sensor Data Flow","disabled":false,"info":"","env":[]},{"id":"3edd400a453b4f21","type":"serial in","z":"17fd02ad03f50979","name":"NanoSerialIn","serial":"e89ac83158ba7533","x":1110,"y":920,"wires":[["0d921c733e07d93f","e881775a18644168"]]},{"id":"404b7711d9c92a1e","type":"debug","z":"17fd02ad03f50979","name":"PublishedJSONDebug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2740,"y":800,"wires":[]},{"id":"0d921c733e07d93f","type":"json","z":"17fd02ad03f50979","name":"","property":"payload","action":"obj","pretty":false,"x":1310,"y":1000,"wires":[["46824651894c1ac2"]]},{"id":"c5e22e7fdb94fac1","type":"switch","z":"17fd02ad03f50979","name":"IdentifySensor","property":"payload.parameter","propertyType":"msg","rules":[{"t":"eq","v":"Temperature","vt":"str"},{"t":"eq","v":"Humidity","vt":"str"},{"t":"eq","v":"Distance","vt":"str"},{"t":"eq","v":"Motion","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":1720,"y":1060,"wires":[["f95b17a8d7c7525c"],["c5e0d1088934d392"],["5201a765e1a3fc67"],["52f3a6ef80c34eba"],["6a43760cee75ade1"]]},{"id":"133bf93cea305ff2","type":"mqtt out","z":"17fd02ad03f50979","name":"Publish - STEMVentorHiveMQ","topic":"sensor-data","qos":"","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"90844ce0ad4c8dc2","x":2770,"y":1060,"wires":[]},{"id":"6a43760cee75ade1","type":"function","z":"17fd02ad03f50979","name":"ReturnInvalidSensorMsg","func":"return msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2030,"y":1220,"wires":[[]]},{"id":"9ac05a055933820b","type":"json","z":"17fd02ad03f50979","name":"","property":"payload","action":"str","pretty":false,"x":2530,"y":1060,"wires":[["133bf93cea305ff2","404b7711d9c92a1e"]]},{"id":"1c3bf67106b1c424","type":"comment","z":"17fd02ad03f50979","name":"Note on URL","info":"For MQTT brokers Node-RED uses the TCP URL and Port unlike the mobile app that uses the Websocket URL and port. For the private STEMVentor HiveMQ cluster select the TLS option and provide userid and password but no TLS Config or certificates are required.","x":2710,"y":1120,"wires":[]},{"id":"c04c603d78aadd68","type":"debug","z":"17fd02ad03f50979","name":"Messages","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1710,"y":800,"wires":[]},{"id":"46824651894c1ac2","type":"switch","z":"17fd02ad03f50979","name":"DataType","property":"payload.data_type","propertyType":"msg","rules":[{"t":"eq","v":"Message","vt":"str"},{"t":"eq","v":"Data","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1500,"y":1000,"wires":[["c04c603d78aadd68"],["c5e22e7fdb94fac1"]]},{"id":"2dc7832ade2af12d","type":"function","z":"17fd02ad03f50979","name":"processDistance","func":"// Add the timestamp in epoch (milliseconds)\nmsg.payload.timestamp = Date.now();\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2240,"y":1060,"wires":[["9ac05a055933820b"]]},{"id":"cf96bff4412d1477","type":"function","z":"17fd02ad03f50979","name":"processMotion","func":"// Add the timestamp in epoch (milliseconds)\nmsg.payload.timestamp = Date.now();\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2240,"y":1140,"wires":[["9ac05a055933820b"]]},{"id":"e881775a18644168","type":"debug","z":"17fd02ad03f50979","name":"NanoSerialInDebug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":800,"wires":[]},{"id":"7aee33ebc7b44878","type":"serial in","z":"17fd02ad03f50979","name":"PicoSerialIn","serial":"98dbac6f7bfc9d91","x":1110,"y":1100,"wires":[["0d921c733e07d93f","280dedb91781091a"]]},{"id":"280dedb91781091a","type":"debug","z":"17fd02ad03f50979","name":"PicoSerialInDebug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":1200,"wires":[]},{"id":"f95b17a8d7c7525c","type":"range","z":"17fd02ad03f50979","minin":"15","maxin":"35","minout":"15","maxout":"35","action":"drop","round":true,"property":"payload.value","name":"FilterTemperature","x":2010,"y":900,"wires":[["541878ed8f414687"]]},{"id":"541878ed8f414687","type":"function","z":"17fd02ad03f50979","name":"processTemperature","func":"// Add the timestamp in epoch (milliseconds)\nmsg.payload.timestamp = Date.now();\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2260,"y":900,"wires":[["9ac05a055933820b"]]},{"id":"c5e0d1088934d392","type":"range","z":"17fd02ad03f50979","minin":"40","maxin":"100","minout":"40","maxout":"100","action":"drop","round":true,"property":"payload.value","name":"FilterHumidity","x":2000,"y":980,"wires":[["b4e5d26662e0bab1"]]},{"id":"b4e5d26662e0bab1","type":"function","z":"17fd02ad03f50979","name":"processHumidity","func":"// Add the timestamp in epoch (milliseconds)\nmsg.payload.timestamp = Date.now();\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2240,"y":980,"wires":[["9ac05a055933820b"]]},{"id":"5201a765e1a3fc67","type":"range","z":"17fd02ad03f50979","minin":"0","maxin":"25","minout":"0","maxout":"25","action":"drop","round":true,"property":"payload.value","name":"FilterDistance","x":2000,"y":1060,"wires":[["2dc7832ade2af12d"]]},{"id":"52f3a6ef80c34eba","type":"range","z":"17fd02ad03f50979","minin":"0","maxin":"1","minout":"0","maxout":"1","action":"drop","round":true,"property":"payload.value","name":"FilterMotion","x":1990,"y":1140,"wires":[["cf96bff4412d1477"]]},{"id":"e89ac83158ba7533","type":"serial-port","name":"","serialport":"COM3","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"\\n","responsetimeout":"10000"},{"id":"90844ce0ad4c8dc2","type":"mqtt-broker","name":"STEMVentor HiveMQ","broker":"0d7e686af22d4bada5068acbd9312761.s1.eu.hivemq.cloud","port":"8883","tls":"","clientid":"","autoConnect":true,"usetls":true,"protocolVersion":"5","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":"COM11","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"\\n","responsetimeout":"10000"}]