Buffering tweets

Hello, i have a flow that listen for tweets and controlling servo. Do you please give me suggestions what can i need to do to prevent when many tweets are send at the same time.
May be i need to put delay node after twitter node or something else.

This is my flow:

[{"id":"ce55bfb7.05939","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"207c7003.6e47f","type":"debug","z":"ce55bfb7.05939","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":120,"wires":[]},{"id":"726ce37b.8a26cc","type":"change","z":"ce55bfb7.05939","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":100,"wires":[["30f596c6.9963ba"]]},{"id":"30f596c6.9963ba","type":"change","z":"ce55bfb7.05939","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":180,"wires":[["207c7003.6e47f","1e43bcba.978cc3","cf03ffee.a3998"]]},{"id":"1e43bcba.978cc3","type":"pi-gpiod out","z":"ce55bfb7.05939","name":"","host":"localhost","port":8888,"pin":"2","set":"","level":"0","out":"ser","sermin":"1000","sermax":"2000","x":900,"y":240,"wires":[]},{"id":"d740632b.1c50b","type":"function","z":"ce55bfb7.05939","name":"","func":"setTimeout(function(){\n    msg['payload'] = null;\n    node.send(msg);\n}, 1000);\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":730,"y":360,"wires":[["1e43bcba.978cc3","207c7003.6e47f"]]},{"id":"cf03ffee.a3998","type":"delay","z":"ce55bfb7.05939","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":260,"wires":[["9251b28a.54fd6"]]},{"id":"9251b28a.54fd6","type":"change","z":"ce55bfb7.05939","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"30","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":320,"wires":[["1e43bcba.978cc3","207c7003.6e47f","d740632b.1c50b"]]},{"id":"3ad28896.330098","type":"twitter in","z":"ce55bfb7.05939","twitter":"","tags":"testdog15","user":"false","name":"","inputs":0,"x":190,"y":100,"wires":[["726ce37b.8a26cc"]]}]

Yes - probably a delay node - in rate limit mode (to drop any excess messages)

but i don't want to drop the messages. Just to trigger the servo one by one

Well tell it not to drop the intermediate messages then.

Thank you!

and what happens if you get a flood of tweets? the servo could be runnig for awhile :stuck_out_tongue_winking_eye:

With the delay node i will put rate limit of one message per 10 sec. So if i get many tweets they will trigger the servo one by one with 10s. delay

So if you get 6 tweets, it will take a minute for the last to be processed.
If you get 60 tweets, it will take 10 minutes for the last one to get processed.
I hope the servo doesn't control anything important.

And if you check the flow, it’s doing a search for a word, rather than tweets from a single person. Twitter was quite kind in showing how many tests have been done so far :wink:
Be careful in your final setup that others won’t be abusing it, as the way you have set it up it will be quite easy. My first twitter based automation was back in 2011. It would give the weather forecast back if you were to send a command in DM, and with the option to control who DMs you, it was rather safe. Hoping for you that those 400+ followers won’t be testing what that word means, nor that random other people without knowledge of your flow will start using the same keyword.

@yzerman the first change node after the tweet-in node moves msg.payload to msg.payload...why?

Thank you very much for your suggestions

its test flow and this is mistake

Instead of using a 10s fixed delay time, have you looked into using a message queueing system such as this example or even node-red-contrib-simple-message-queue which releases the next message (tweet) in the queue, when the previous one has completed.
It may be that the tweets may only take 5 or 6 seconds, so the queue would be cleared quicker than using a fixed 10 seconds, and would also allow more than 10 seconds delay if it was needed.

Thank you very much this is a better approach

You might also look at node-red-contrib-queue-gate (pardon the self-promotion). It's very like node-red-contrib-simple-message-queue but with a slightly different set of features.

1 Like