Everyone has been really good about helping and not making fun as I've fumbled my way through node-red. I've made a ton of progress, but I still have some gaps. I'm trying to write a function where basically node red just sits there and waits for the right sequence of messages to pass through it. In this case (for simplicity) 231. Then I'd like it to fire off something, anything when it receives that order. I've toyed with a few things but my javascript is failing me.
var newMsg = { payload: msg.payload.length };
newMsg.payload = "1";
return newMsg;
Then I'm trying to parse that, but I don't really know how to get it to hang on to a sort of "buffer" if the data that's flown through my function.
My feeble attempt at a function looks like this...
var gotIt = { payload: msg.payload.length };
//sequence is 231
sequence = {
check : function(e){
sequence.value += this.textContent;
if (sequence.value == sequence.sequence)
{
gotIt.payload = "Got It";
sequence.value = "";
}else{
gotIt.payload = "";
}
},
value : "",
sequence : "231"
}
return gotIt;
Again, I'm pretty sure I'm failing at not understanding how the whole buffer concept works. Any point in the right direction would be really helpful.
[{"id":"d8fbd570.94b8b8","type":"function","z":"45e5bebc.e6cbd","name":"GLOBAL","func":"global.set(\"gotIt\",\"0\"); \nreturn msg;","outputs":1,"noerr":0,"x":361.2000274658203,"y":376.2000274658203,"wires":[["bd43250a.f109b8","64f5efd0.b54f4"]]},{"id":"a9c88b9f.757228","type":"inject","z":"45e5bebc.e6cbd","name":"Button 1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126.19999694824219,"y":456.20001220703125,"wires":[["5316cf1f.badc9"]]},{"id":"5316cf1f.badc9","type":"function","z":"45e5bebc.e6cbd","name":"Trigger 1","func":"var newMsg = { payload: msg.payload.length };\nnewMsg.payload = \"1\";\nreturn newMsg;\n\n\n","outputs":1,"noerr":0,"x":315.5,"y":456.8000030517578,"wires":[["bd43250a.f109b8"]]},{"id":"34a9a447.9d0ccc","type":"inject","z":"45e5bebc.e6cbd","name":"SetGlobal","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":128.5,"y":376.8000030517578,"wires":[["d8fbd570.94b8b8"]]},{"id":"64f5efd0.b54f4","type":"debug","z":"45e5bebc.e6cbd","name":"","active":true,"console":"false","complete":"false","x":900.4999542236328,"y":384.8000030517578,"wires":[]},{"id":"7cc7ff6a.99218","type":"inject","z":"45e5bebc.e6cbd","name":"Button 2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":128.1999969482422,"y":534.2000122070312,"wires":[["a35a1e08.a2601"]]},{"id":"a35a1e08.a2601","type":"function","z":"45e5bebc.e6cbd","name":"Trigger 2","func":"var newMsg = { payload: msg.payload.length };\nnewMsg.payload = \"2\";\nreturn newMsg;\n\n\n","outputs":1,"noerr":0,"x":317.5,"y":534.8000030517578,"wires":[["bd43250a.f109b8"]]},{"id":"f49771e2.9fb79","type":"inject","z":"45e5bebc.e6cbd","name":"Button 3","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":128.1999969482422,"y":616.2000122070312,"wires":[["df2bcb25.817208"]]},{"id":"df2bcb25.817208","type":"function","z":"45e5bebc.e6cbd","name":"Trigger 3","func":"var newMsg = { payload: msg.payload.length };\nnewMsg.payload = \"3\";\nreturn newMsg;\n\n\n","outputs":1,"noerr":0,"x":317.5,"y":616.8000030517578,"wires":[["bd43250a.f109b8"]]},{"id":"bd43250a.f109b8","type":"function","z":"45e5bebc.e6cbd","name":"Sequencer","func":"var gotIt = { payload: msg.payload.length };\n//sequence is 231\n\nsequence = {\n \n check : function(e){\n sequence.value += this.textContent;\n \n if (sequence.value == sequence.sequence)\n {\n gotIt.payload = \"Got It\";\n sequence.value = \"\";\n }else{\n gotIt.payload = \"\"; \n }\n }, \n \n value : \"\",\n sequence : \"231\"\n\n}\n\n\n\n//end\nreturn gotIt;","outputs":1,"noerr":0,"x":598.4999847412109,"y":531.6000213623047,"wires":[["adb4b171.0727b"]]},{"id":"adb4b171.0727b","type":"debug","z":"45e5bebc.e6cbd","name":"","active":true,"console":"false","complete":"false","x":873.4999847412109,"y":527.8000335693359,"wires":[]}]