Nore-red and Web Sockets: How to check connection?

#1

Hi Nore-red people.
I’m really excited from the possiblites node red has.

I’m trying to have node-red controlling a program called WatchOut

I’ve found a working javascript code and when I tried to migrate it to node-red I failed. The websocket is not properly connecting to the program (while the jacascript little app does).

The funny part is that if I setup a websocket server in Processing both connect and send correct messages.

My flow

[{"id":"80521cc8.7be9c","type":"debug","z":"8bf241d0.87881","name":"Controllo output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1189.88330078125,"y":427.0000305175781,"wires":[]},{"id":"4c1529d.efd3f58","type":"function","z":"8bf241d0.87881","name":"<30: HALT","func":"//recupero nome timeline\nvar timeline = flow.get(\"timeline\");\n\n//costruisco la stringa da inviare\nvar new_payload = 'halt \"' + timeline + '\"\\n';\n\n//la passo al prossimo blocchetto\nmsg.payload = new_payload;\n\nreturn msg;","outputs":1,"noerr":0,"x":880.88330078125,"y":423.0000305175781,"wires":[["80521cc8.7be9c","ee159b60.1d8ff"]]},{"id":"269bc17b.0c26e6","type":"function","z":"8bf241d0.87881","name":">70: gotoControlClue","func":"//recupero nome timeline\nvar timeline = flow.get(\"timeline\");\n\n//creo un comando random tra 0 e 10\nvar command = Math.floor((Math.random() * 10) + 1);\n\n//costruisco la stringa da inviare\nvar new_payload = 'gotoControlCue \"' + command + '\" false ' + timeline + '\\n';\n\n//la passo al prossimo blocchetto\nmsg.payload = new_payload;\n\nreturn msg;","outputs":1,"noerr":0,"x":910.88330078125,"y":463.0000305175781,"wires":[["80521cc8.7be9c","ee159b60.1d8ff"]]},{"id":"8c792880.f13c9","type":"function","z":"8bf241d0.87881","name":"else: PLAY","func":"//recupero nome timeline\nvar timeline = flow.get(\"timeline\");\n\n//costruisco la stringa da inviare\nvar new_payload = 'play \"' + timeline + '\"\\n';\n\n//la passo al prossimo blocchetto\nmsg.payload = new_payload;\n\nreturn msg;","outputs":1,"noerr":0,"x":880.88330078125,"y":503.0000305175781,"wires":[["80521cc8.7be9c","ee159b60.1d8ff"]]},{"id":"a5bb28a1.347f2","type":"switch","z":"8bf241d0.87881","name":"Definisci trigger","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"30","vt":"num"},{"t":"gt","v":"70","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":680.88330078125,"y":463.0000305175781,"wires":[["4c1529d.efd3f58"],["269bc17b.0c26e6"],["8c792880.f13c9"]]},{"id":"a3a93f54.8d2768","type":"range","z":"8bf241d0.87881","minin":"0","maxin":"1080","minout":"0","maxout":"100","action":"scale","round":true,"property":"payload","name":"adatta a range 0-100","x":460.88330078125,"y":503.0000305175781,"wires":[["a5bb28a1.347f2","be1f4478.69748"]]},{"id":"390e3b3f.0d452c","type":"function","z":"8bf241d0.87881","name":"normalizza in numero","func":"var value = parseInt(msg.payload);\n\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":400.88330078125,"y":463.0000305175781,"wires":[["a3a93f54.8d2768"]]},{"id":"be1f4478.69748","type":"debug","z":"8bf241d0.87881","name":"Controllo normalizzazione","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":699.88330078125,"y":367.0000305175781,"wires":[]},{"id":"79cc5548.177ab4","type":"inject","z":"8bf241d0.87881","name":"Simula altro valore","topic":"","payload":"550","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":299.88330078125,"y":387.0000305175781,"wires":[["390e3b3f.0d452c"]]},{"id":"22b07d70.be13da","type":"inject","z":"8bf241d0.87881","name":"Simula valore >70%","topic":"","payload":"850","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":299.88330078125,"y":347.0000305175781,"wires":[["390e3b3f.0d452c"]]},{"id":"4f2dc02d.ecd8a8","type":"inject","z":"8bf241d0.87881","name":"Simula valore <30%","topic":"","payload":"300","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":299.88330078125,"y":307.0000305175781,"wires":[["390e3b3f.0d452c"]]},{"id":"f40724c4.019c48","type":"inject","z":"8bf241d0.87881","name":"Definisci Nome Timeline","topic":"","payload":"Timeline 1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":309.88330078125,"y":187.00003051757812,"wires":[["c8619f85.9193a8"]]},{"id":"c8619f85.9193a8","type":"function","z":"8bf241d0.87881","name":"Salva come variabile il Nome Timeline","func":"flow.set(\"timeline\", msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"x":599.88330078125,"y":187.00003051757812,"wires":[[]]},{"id":"ee159b60.1d8ff","type":"websocket out","z":"8bf241d0.87881","name":"","server":"","client":"5223a05f.bee468","x":1214.1666259765625,"y":569.6666870117188,"wires":[]},{"id":"5223a05f.bee468","type":"websocket-client","z":"","path":"ws://192.168.1.48:3040","tls":"","wholemsg":"false"}]

Any help?
What am I doind wrong?

#2

no luck with anybody?

#3

To be honest, I’m having a hard time understanding what that last sentence means – what do you mean by “setup a websocket server in Processing”?

I don’t see anything wrong with the flow itself, so what do you see in the Editor underneath the websocket node? Does it ever show status “connected”? Are you disconnecting that little javascript app first? Any error in the node-red log?

I’m guessing that your flow is not running on the same hardware as your browser. If that is true, then you need to make sure the node-red server host can ping the 192.168.1.48 addr, and port #3040 is not blocked by the network or a firewall rule. Please post more information about your configuration, including the output of npm -v, node -v, and whatever appears in the node-red log on startup.

P.S. you don’t need the “normalizza in numero” function node – the “range” node will coerce your string payload,to a number before scaling it anyway…

#4

To be honest, I’m having a hard time understanding what that last sentence means – what do you mean by “setup a websocket server in Processing”?

like this

I don’t see anything wrong with the flow itself, so what do you see in the Editor underneath the websocket node? Does it ever show status “connected”? Are you disconnecting that little javascript app first? Any error in the node-red log?

yes I close the app first (the two shouldn’t collide though) and no, no error other than disconnected

I’m guessing that your flow is not running on the same hardware as your browser. If that is true, then you need to make sure the node-red server host can ping the 192.168.1.48 addr, and port #3040 is not blocked by the network or a firewall rule. Please post more information about your configuration, including the output of npm -v, node -v, and whatever appears in the node-red log on startup.

Mah. They ping each other and yes, the node-red is on a pi. I’m used to this different hardwares ad I’m sure the see each other, no firewalls, etc…

BTW, I was able to solve this problem by using TCP connection to the watchout server.

Still a big question mark: while the javascript code was working and succeded in establishing a connection with the WatchOut Server on port 3040, neither node-red nor a nodejs server I used for proxy as a second attempt to solve this problem seemed to work. Which is amazing.

It seems that the websocket held by firefox or the browser succeded while node-red/node.js didn’t.

The fact that I solved this problem in another way won’t make me dig more, but the whole thing would merit a deeper analysis.

thanks for commenting though