TestDataGenerator
Test Coursera IBM.
So we will implement a small data simulator workflow which is simulating Node-RED running on an IoT device and publishing data through the IBM Watson IoT platform using the MQTT protocol. The IBM Watson IoT platform includes an MQTT broker, as a service with built in fault tolerance, load balancing and failover in over 50 IBM Data Centers spread around the globe.
[{"id":"d75e85b9.00fe28","type":"inject","z":"423db466.ba8a64","name":"Fluid Simulator","topic":"","payload":"{ \"d\": {\"count\":0, \"hardness\": 61, \"temperature\": 50, \"flowrate\": 11, \"fluidlevel\": \"acceptable\" } }","payloadType":"json","repeat":"1","crontab":"","once":false,"x":195,"y":131,"wires":[["5a7d45c9.e5afc4"]]},{"id":"79951689.9815a","type":"ibmiot out","z":"423db466.ba8a64","authentication":"boundService","apiKey":"c4f55b4b.cdca88","outputType":"evt","deviceId":"Washer01","deviceType":"WashingMachine","eventCommandType":"status","format":"json","data":"msg.payload","qos":"","name":"Washer01","service":"registered","x":761,"y":209.183349609375,"wires":[]},{"id":"fff9ffcc.c1fdf8","type":"inject","z":"423db466.ba8a64","name":"Voltage Sensor Simulator","topic":"","payload":"{ \"d\": { \"voltage\": 240, \"frequency\": 50 } }","payloadType":"json","repeat":"3","crontab":"","once":false,"x":174.66668701171875,"y":206.10000610351562,"wires":[["ce1e134.2d6427"]]},{"id":"3fcfe7f6.585318","type":"inject","z":"423db466.ba8a64","name":"Mechanical Sensor Simulator","topic":"","payload":"{ \"d\": { \"speed\": 1200 } }","payloadType":"json","repeat":"5","crontab":"","once":false,"x":182.66668701171875,"y":290.1000061035156,"wires":[["e964837b.f605c"]]},{"id":"5a7d45c9.e5afc4","type":"function","z":"423db466.ba8a64","name":"Fluid data","func":"// initialise the counter to 0 if it doesn't exist already\nvar count = context.get('count')||0;\nvar hardness = context.get('hardness')||0;\nvar randomness = context.get('randomness')||0;\ncount += 1;\n// store the value back\ncontext.set('count',count);\n// make it part of the outgoing msg object\nmsg.payload.d.count = count;\nif(count % 300 == 0) {\n context.set('randomness',1);\n context.set('hardness', 83);\n} else if(count % 20 == 0) {\n context.set('randomness',0);\n} else if(count % 121 == 0) {\n context.set('randomness',2);\n context.set('hardness', 100);\n}\n\nif(randomness == 0) {\n // no variation\n msg.payload.d.hardness = Math.floor(Math.random() * (80 - 70 + 1) + 70);\n} else if(randomness == 1) {\n // gradually increase\n msg.payload.d.hardness = hardness + 1;\n context.set('hardness', (hardness + 1));\n} else {\n msg.payload.d.hardness = hardness + 5;\n context.set('hardness', (hardness + 5));\n}\nmsg.payload.d.temperature = Math.floor(Math.random() * (100 - 80 + 1) + 80);\n\n//msg.payload = JSON.stringify(msg.payload)\nmsg.eventOrCommandType = \"fluid\"\nreturn msg;","outputs":1,"noerr":0,"x":416.5500183105469,"y":130.48333740234375,"wires":[["7a3fb60f.48e7a"]]},{"id":"ce1e134.2d6427","type":"function","z":"423db466.ba8a64","name":"Voltage data","func":"// 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// make it part of the outgoing msg object\nmsg.payload.d.count = count;\nif(count % 100 <= 90) {\n msg.payload.d.voltage = Math.floor(Math.random() * (240 - 220) + 220);\n} else {\n msg.payload.d.voltage = Math.floor(Math.random() * (260 - 240) + 240);\n}\nmsg.payload.d.frequency = Math.floor(Math.random() * (80 - 60 + 1) + 60);\n//msg.payload = JSON.stringify(msg.payload)\nmsg.eventOrCommandType = \"voltage\"\nreturn msg;","outputs":1,"noerr":0,"x":422.5500183105469,"y":205.98333740234375,"wires":[["7a3fb60f.48e7a"]]},{"id":"e964837b.f605c","type":"function","z":"423db466.ba8a64","name":"Drum data","func":"// 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// make it part of the outgoing msg object\nmsg.payload.d.count = count;\nif(count % 100 <= 90) {\n // No variation - within the safe limit\n msg.payload.d.speed = Math.floor(Math.random() * (1100 - 1000) + 1000); \n} else {\n msg.payload.d.speed = Math.floor(Math.random() * (1300 - 1150) + 1150); \n}\n\n\n//msg.payload = JSON.stringify(msg.payload)\nmsg.eventOrCommandType = \"drum\"\nreturn msg;","outputs":1,"noerr":0,"x":425.5500183105469,"y":289.98333740234375,"wires":[["7a3fb60f.48e7a"]]},{"id":"7a3fb60f.48e7a","type":"function","z":"423db466.ba8a64","name":"","func":"msg.payload.d.ts = new Date().getTime();\nreturn msg;","outputs":1,"noerr":0,"x":601.5,"y":206.23333740234375,"wires":[["d0de19b9.3cbcd8","79951689.9815a"]]},{"id":"d0de19b9.3cbcd8","type":"debug","z":"423db466.ba8a64","name":"","active":true,"console":"false","complete":"payload","x":685.5,"y":284.98333740234375,"wires":[]},{"id":"c4f55b4b.cdca88","type":"ibmiot","z":"423db466.ba8a64","name":"coi0nz"}]