#idea Processing Events using Websockets on Node-red

DSC_0522.JPGOn my third day I am making new discoveries. Previously I used polling to get events such as pushing a button. This is too slow, wasteful of computer resources and might even miss the event if I am not polling fast enough. Another method is to use interrupts or ‘events’ using websockets.

Seeedo does all the hard work for you. Just select ‘events’ on the Android or Ios App, download the firmware and cut and paste the ip and access token into the selected node-red nodes. I am hosting node-red on a Beaglebones Green computer and WioLink (here Wio02) is a front end for Grove IO with results on my Windows Chrome browser. All you have to so is cut and paste the access token into an ‘inject node’ on node-red and insert two websocket nodes - one for in and one for out. You can access the payload from the out websocket node and do want you want with it - either add extra nodes for processing or a node function and program it in javascript. I have only captured it with a debug node for demo.

Its all interrupt processing with non block programming using callbacks and events. It is more efficient and works on every event. You can set all of this up within 1 minute! The diagrams below show the node-red flow and dialogs for the websocket nodes.For the hardware of this flow I am using a Grove PIR module that captures every IR event.

I still have to add the processing for the alerts tones to the speakers but that is easy and I have tested the speaker interface separately. Don’t expect music - potential transmitted frequencies are minimal (only 4 are support on a single musically scale (A to G).

If you want any of the flows give me feedback and I will add them. Then you can paste them into your own node-red canvas.

Post-edit: take care when posting like this so as not to include either your or in the diagrams. I have since removed these. Read your posting carefully. Also this method is not secure as the payload includes the Access Token. As a suggestion, the team at Seeedo Studio could remove the access token from the return payload. It is not need then. In the future secure protocols should be used for real projects.

Ref: Example 3.7 Using Websockets with Node-RED on Node-RED: Lecture 3 – Basic nodes and flows at University of Waterloo (http://noderedguide.com/index.php/2015/10/28/node-red-lecture-3-basic-nodes-and-flows/ ). You can host your node-red either there or on a Raspberry Pi, Beaglebone Black, Green computer or even a Mac or Windows PC.
Node-red flow1.jpeg

I just received my boards, and am away travelling (too bad). But planning my first project. I was looking at various local servers (Huginn, for example) but really like Node-RED from what I am reading. Can you provide your full flow definitions? I too was looking to catch the events and stream them vs polling, so your test scenario looks like a great place to start. I am planning to the gesture input and polling would be ridiculous. Thanks for the heads up on Node-RED as a conditional processor for prototypes.


Hi Bill, see my #idea Thermostat - Final. http://www.seeedstudio.com/forum/viewtopic.php?f=72&t=6950 It contains a fuller description and uses every RESTful method including events. All works nicely with minimal latency. I am happy to provide a full flow of the Thermostat but first you have to down load node-red. Go to the website where there are plenty of resources: http://nodered.org/

Yep! Got Node-RED and tested. I really like this for prototyping! I did see your final version as I have been trolling through theses forums. Looking forward to working with the WioLink when I get back home. This will make getting something running fun and quick. Appreciate the help!


good luck with your first project. Share the results here on the forum. I think the combination of WioLink and node-red is interesting and you can develop proto-types very quickly. The only down side is that node-red chews up lots of RAM but I have many Beaglebone computers so this is not an issue for me. I have a node-red performance node coupled with user interface node and this is very useful so you can see the performance on the chrome browser as you develop. On some programs I have observed memory leakages and reduced free memory.