#センサーからのデータを擬似的に生成するシミュレーターを作ります
- Node-REDのフローをコピーする方法を参照して、下記のフローをコピペします。
シミュレーターを作る
[{"id":"cf562dd1.56fa08","type":"function","z":"50dbe8c5.d1ab78","name":"0.x〜10.x","func":"var v = (Math.floor( Math.random() * 100 ) + 1 )/10;\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":180,"wires":[["646f389f.439888"]]},{"id":"ac3e3e42.f42ac","type":"inject","z":"50dbe8c5.d1ab78","name":"0.5秒毎","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":false,"x":110,"y":140,"wires":[[]]},{"id":"646f389f.439888","type":"debug","z":"50dbe8c5.d1ab78","name":"","active":true,"console":"false","complete":"false","x":520,"y":100,"wires":[]},{"id":"d5fe769c.52b17","type":"function","z":"50dbe8c5.d1ab78","name":"20.x〜50.x","func":"var v = (Math.floor( Math.random() * (500+1-200) ) + 200 )/10;\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":220,"wires":[["646f389f.439888"]]},{"id":"6dc3981a.abcdc8","type":"function","z":"50dbe8c5.d1ab78","name":"100〜500","func":"var v = (Math.floor( Math.random() * (500+1-100) ) + 100 );\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":120,"wires":[["646f389f.439888"]]},{"id":"7e78bf59.d78228","type":"function","z":"50dbe8c5.d1ab78","name":"0〜10","func":"var v = Math.floor( Math.random() * (10 + 1 - 0) ) + 0 ;\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":40,"wires":[["646f389f.439888"]]},{"id":"3f11ef65.c37168","type":"function","z":"50dbe8c5.d1ab78","name":"10〜20","func":"var v = Math.floor( Math.random() * (20 + 1 - 10) ) + 10 ;\nmsg.payload = v;\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":80,"wires":[["646f389f.439888"]]},{"id":"adf9ca6c.7f2d9","type":"inject","z":"50dbe8c5.d1ab78","name":"1回","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":110,"y":40,"wires":[[]]},{"id":"3b8a73c1.449134","type":"inject","z":"50dbe8c5.d1ab78","name":"1秒毎","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":110,"y":180,"wires":[[]]},{"id":"c1f34a92.aa32b","type":"inject","z":"50dbe8c5.d1ab78","name":"0.1秒毎","topic":"","payload":"","payloadType":"date","repeat":"0.1","crontab":"","once":false,"x":110,"y":100,"wires":[[]]},{"id":"26b29e95.bf1322","type":"inject","z":"50dbe8c5.d1ab78","name":"1分毎","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":110,"y":220,"wires":[[]]}]
#用意した配列の値を順に送信するシミュレーター
- Node-REDのフローをコピーする方法を参照して、下記のフローをコピペします。
配列要素を送信するシミュレーター
[{"id":"b795e50c.eabc18","type":"inject","z":"50dbe8c5.d1ab78","name":"0.5秒毎","topic":"","payload":"","payloadType":"date","repeat":"0.5","crontab":"","once":false,"x":170,"y":680,"wires":[["93c655e4.df7e3"]]},{"id":"19ecd10.f3c812f","type":"debug","z":"50dbe8c5.d1ab78","name":"payloadを表示","active":true,"console":"false","complete":"payload","x":680,"y":580,"wires":[]},{"id":"f7513152.4819e","type":"inject","z":"50dbe8c5.d1ab78","name":"1回","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":170,"y":580,"wires":[[]]},{"id":"18ad76a9.bf0b39","type":"inject","z":"50dbe8c5.d1ab78","name":"1秒毎","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":170,"y":720,"wires":[[]]},{"id":"a7128021.dd9f7","type":"inject","z":"50dbe8c5.d1ab78","name":"0.1秒毎","topic":"","payload":"","payloadType":"date","repeat":"0.1","crontab":"","once":false,"x":170,"y":640,"wires":[[]]},{"id":"aa745e8a.004a68","type":"inject","z":"50dbe8c5.d1ab78","name":"1分毎","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":170,"y":760,"wires":[[]]},{"id":"d38f21fc.87a4b8","type":"function","z":"50dbe8c5.d1ab78","name":"出力","func":"var i = global.get('index22')||0;\nvar total = global.get('total22')||0;\n\nvar time = [\"10:00\",\"10:01\",\"10:02\",\"10:03\",\"10:04\",\"10:05\",\"10:06\",\"10:07\",\"10:08\",\"10:09\",\"10:10\",\"10:11\",\"10:12\",\"10:13\",\"10:14\",\"10:15\",\"10:16\",\"10:17\",\"10:18\",\"10:19\",\"10:20\",\"10:21\",\"10:22\",\"10:23\",\"10:24\",\"10:25\",\"10:26\",\"10:27\",\"10:28\",\"10:29\",\"10:30\",\"10:31\",\"10:32\",\"10:33\",\"10:34\",\"10:35\",\"10:36\",\"10:37\",\"10:38\",\"10:39\",\"10:40\",\"10:41\",\"10:42\",\"10:43\",\"10:44\",\"10:45\",\"10:46\",\"10:47\",\"10:48\",\"10:49\",\"10:50\",\"10:51\",\"10:52\",\"10:53\",\"10:54\",\"10:55\",\"10:56\",\"10:57\",\"10:58\",\"10:59\"];\nvar amnt = [0,10,20,10,40,50,20,10,30,0,20,50,40,50,10,40,50,20,0,10,0,10,30,20,50,40,20,0,10,30,20,50,40,20,0,10,20,40,20,50,40,20,30,10,0,50,40,50,40,20,30,0,10,20,40,30,50,10,30,20];\nvar qtty = [2,4,8,0,4,6,8,10,4,6,0,4,8,10,8,0,8,4,2,10,4,8,6,0,10,4,6,4,10,2,6,2,4,10,6,2,0,8,10,2,6,10,0,2,6,4,8,10,6,2,0,2,4,8,0,6,4,0,10,2];\n\n//total += amnt[i];\ntotal += qtty[i];\n\nmsg.combo = '{ \"index\": ' + i + ', \"time\": ' + time[i] + ', \"amnt\": ' + amnt[i] + ', \"qtty\": ' + qtty[i] + ', \"total\": ' + total + '}';\nvar data1 = [[time[i]],[amnt[i]],[qtty[i]]];\nvar data2 = [[time[i]],[amnt[i]],[total]];\nvar data3 = [[time[i]],[qtty[i]],[total]];\n\nmsg.payload = data3;\nmsg.total = total;\n\ni += 1;\nglobal.set('index22', i);\nglobal.set('total22', total);\n\nreturn msg;\n","outputs":1,"noerr":0,"x":490,"y":580,"wires":[["19ecd10.f3c812f","154920ea.fa7c9f","9243d9be.56801"]]},{"id":"eb29e52e.e85af8","type":"inject","z":"50dbe8c5.d1ab78","name":"restart","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":170,"y":820,"wires":[["3439e80.dfa8218"]]},{"id":"154920ea.fa7c9f","type":"debug","z":"50dbe8c5.d1ab78","name":"comboを表示","active":true,"console":"false","complete":"combo","x":680,"y":640,"wires":[]},{"id":"9243d9be.56801","type":"debug","z":"50dbe8c5.d1ab78","name":"totalを表示","active":true,"console":"false","complete":"total","x":670,"y":700,"wires":[]},{"id":"3439e80.dfa8218","type":"function","z":"50dbe8c5.d1ab78","name":"リセット","func":"if (msg.payload === 0 ) {\n global.set('total22',0);\n global.set('index22', 0);\n}","outputs":1,"noerr":0,"x":360,"y":820,"wires":[[]]},{"id":"93c655e4.df7e3","type":"function","z":"50dbe8c5.d1ab78","name":"起動判断","func":"var time = [\"10:00\",\"10:01\",\"10:02\",\"10:03\",\"10:04\",\"10:05\",\"10:06\",\"10:07\",\"10:08\",\"10:09\",\"10:10\",\"10:11\",\"10:12\",\"10:13\",\"10:14\",\"10:15\",\"10:16\",\"10:17\",\"10:18\",\"10:19\",\"10:20\",\"10:21\",\"10:22\",\"10:23\",\"10:24\",\"10:25\",\"10:26\",\"10:27\",\"10:28\",\"10:29\",\"10:30\",\"10:31\",\"10:32\",\"10:33\",\"10:34\",\"10:35\",\"10:36\",\"10:37\",\"10:38\",\"10:39\",\"10:40\",\"10:41\",\"10:42\",\"10:43\",\"10:44\",\"10:45\",\"10:46\",\"10:47\",\"10:48\",\"10:49\",\"10:50\",\"10:51\",\"10:52\",\"10:53\",\"10:54\",\"10:55\",\"10:56\",\"10:57\",\"10:58\",\"10:59\"];\nvar i = global.get('index22'); // ユニークな変数名に\nif (i > time.length-1) return;\nreturn msg;\n","outputs":1,"noerr":0,"x":360,"y":580,"wires":[["d38f21fc.87a4b8"]]}]