I working on a project on node-red to create a stopwatch. I found timer-stopwatch in NPM, I think would be what I'm looking for but the issue is, I can't find a way to start the stopwatch.
I'm using a raspberry pi with node-red and the npm-contrib node to interface the timer-stopwatch. every time I try to inject a command the debug console respond with this error:
TypeError: Object # has no method 'reset'
I'm working on this project for a drag light and I want the stopwatch to start when the green light activate and then a set of IR sensors will be the stop signal for the stopwatch.
After this I want the result of the stopwatch to be shown on a local webpage, in live if possible, and have a history shown under the live part.
I'm looking for any way this could be possible to achieve.
at first I was working with simple python codes for the lights then found out node-red that helped me to understand.
here a clipboard copy of the node-red part for the stopwatch:
[{"id":"fa4e7c52.2b88e","type":"rpi-gpio in","z":"5b54b95f.a4ab48","name":"capteur-input","pin":"37","intype":"tri","debounce":"5","read":false,"x":1368,"y":106,"wires":[[]]},{"id":"f1641fdd.b28d7","type":"delay","z":"5b54b95f.a4ab48","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":1618,"y":216,"wires":[["c0e8ebcf.82a488"]]},{"id":"ce973724.f05608","type":"hysteresis","z":"5b54b95f.a4ab48","name":"","rising_threshold":".2999","falling_threshold":".0002","x":1489.500015258789,"y":171.6666717529297,"wires":[["f1641fdd.b28d7"]]},{"id":"453729db.6c73a8","type":"function","z":"5b54b95f.a4ab48","name":"","func":"var Stopwatch = ('timer-stopwatch');\n \nvar stopwatch = new Stopwatch(); // A new count up stopwatch. Starts at 0.\nvar start = stopwatch.start();\nvar stop = stopwatch.stop();\nvar reset = stopwatch.reset(countDownMS);\nglobal.set(time.ms);\n\nreturn msg;","outputs":"1","noerr":0,"x":1779,"y":306,"wires":[[]]},{"id":"710b7c12.919654","type":"template","z":"5b54b95f.a4ab48","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<ul>\n \n <li></li>\n \n</ul>","x":2245,"y":458,"wires":[["784f0ff.9fe1cf"]]},{"id":"d97e4759.f19cd8","type":"mongodb out","z":"5b54b95f.a4ab48","service":"_ext_","mongodb":"13244bb7.1f3da4","name":"","collection":"live-time","payonly":false,"upsert":false,"multi":false,"operation":"store","x":2274,"y":212,"wires":[]},{"id":"474dbe3a.ba9da","type":"mongodb in","z":"5b54b95f.a4ab48","service":"_ext_","mongodb":"13244bb7.1f3da4","name":"","collection":"live-time","operation":"find","x":2009,"y":452,"wires":[["710b7c12.919654"]]},{"id":"c0e8ebcf.82a488","type":"change","z":"5b54b95f.a4ab48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"time.ms","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1815,"y":96,"wires":[["b263bb1c.08fd88"]]},{"id":"784f0ff.9fe1cf","type":"http response","z":"5b54b95f.a4ab48","name":"","x":2409,"y":410,"wires":[]},{"id":"dff41be4.6bfd18","type":"http in","z":"5b54b95f.a4ab48","name":"","url":"/timer","method":"get","swaggerDoc":"","x":1728,"y":397,"wires":[["474dbe3a.ba9da"]]},{"id":"66c775f3.50469c","type":"mongodb in","z":"5b54b95f.a4ab48","service":"_ext_","mongodb":"13244bb7.1f3da4","name":"","collection":"hist-time","operation":"find","x":2201,"y":550,"wires":[[]]},{"id":"b313546.c476ba8","type":"npm","z":"5b54b95f.a4ab48","name":"","func":"var Stopwatch = 'timer-stopwatch';\nvar stopwatch = new Stopwatch();\n//stopwatch.start();\n//stopwatch.stop();\n//stopwatch.reset(countDownMS)\ntime.ms;\n","npm_module":"timer-stopwatch","module_style":"custom","msg_payload":"return_val","function_name":"timer.start();","x":2070,"y":348,"wires":[[]]},{"id":"b263bb1c.08fd88","type":"npm","z":"5b54b95f.a4ab48","name":"","func":"// NPM module exposed as variable, npm_module\nreturn npm_module(msg.payload);","npm_module":"timer-stopwatch","module_style":"cstr","msg_payload":"callback","function_name":"","x":1961,"y":160,"wires":[["82e9f9f4.6a5fc8"]]},{"id":"82e9f9f4.6a5fc8","type":"debug","z":"5b54b95f.a4ab48","name":"","active":true,"console":"false","complete":"false","x":2120,"y":112,"wires":[]},{"id":"29f889d2.a5db26","type":"template","z":"5b54b95f.a4ab48","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\nstart();\n","x":1653,"y":306,"wires":[["453729db.6c73a8"]]},{"id":"98b56bab.049578","type":"inject","z":"5b54b95f.a4ab48","name":"","topic":"","payload":"timer.start","payloadType":"str","repeat":"","crontab":"","once":false,"x":1826,"y":229,"wires":[["b263bb1c.08fd88"]]},{"id":"13244bb7.1f3da4","type":"mongodb","z":"","hostname":"127.0.0.1","port":"27017","db":"Chrono","name":""}]
via Mathieu Lapointe
No comments:
Post a Comment