Skip to content

Instantly share code, notes, and snippets.

@hovissimo
Created August 11, 2014 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hovissimo/7d347a8f935bfc2fca49 to your computer and use it in GitHub Desktop.
Save hovissimo/7d347a8f935bfc2fca49 to your computer and use it in GitHub Desktop.
Magic Gate function for Node-RED, it let's you repeat messages arbitrarily
/* This function node will store the last message it
received as long as msg.payload != "abracadabra".
If this function receives a msg where the payload
exactly equals "abracadabra" then the stored
message will be forwarded.
This function is designed for storing and replaying
messages to help in testing flows. You can use it
by wiring up between two nodes where you want to
control or repeat messages, and also adding an
INJECT input that sends a the magic word in the
payload.
---Hovis
*/
context.storedMessage = context.storedMessage || {};
if (msg.payload != "abracadabra") {
context.storedMessage = msg;
} else {
return context.storedMessage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment