Python to Server Websocket

860 views
Skip to first unread message

Peter McNeill

unread,
Feb 24, 2016, 11:47:19 AM2/24/16
to Node-RED
I have created a small Python app which simply sends hello world via a websocket.

I am trying to use node-red to read the value and return it to the webpage.

However my python program says the mesage is being sent but I am not receiving it on my node-red debug.

Here is my python code:

#!/usr/bin/python

import time

import websocket
ws = websocket.WebSocket();
ws.connect("ws://localhost:1880/ws/example")
count = 0;
while(count < 50):
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
time.sleep(5)
count = count + 1
ws.close()

Below is my flow in node-red.



Does anyone have any suggestions on where I am going wrong?






Untitled.png

Dave C-J

unread,
Feb 24, 2016, 4:00:13 PM2/24/16
to node...@googlegroups.com
Hi,
Looks good to me - even works for me... :-(

Steampunk Prof

unread,
Feb 25, 2016, 3:57:25 AM2/25/16
to Node-RED
Not sure if it's connected, but I was playing with the Google Maps flow last week and since updating from 0.13.1 to 0.13.2, it's stopped working, even just running the flow as supplied.


Nicholas O'Leary

unread,
Feb 25, 2016, 5:29:27 AM2/25/16
to Node-RED Mailing List
Interesting - we did change a setting in the websocket server to disable compression of messages due to a bug hit in the level of ws code we were using (but couldn't update for reasons).

Hmm, need to investigate this properly then to see if we've regressed some other behaviour unintentionally.

Nick



--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas O'Leary

unread,
Feb 25, 2016, 5:40:58 AM2/25/16
to Node-RED Mailing List
Hmm, having wrestled with pip/python to get the websockets package installed, the code at the top worked for me with node-red 0.13.2.

Which Google Maps flow were you trying?

Steampunk Prof

unread,
Feb 25, 2016, 8:46:51 AM2/25/16
to Node-RED
Live Google Maps Update - Websockets http://flows.nodered.org/flow/1aab1d44e387da96b3fe
Could just be something I've messed up somewhere.
Also had an issue with Twilio losing the authentication settings file, it was working in 0.13.1

Steampunk Prof

unread,
Feb 25, 2016, 9:00:33 AM2/25/16
to Node-RED
Ignore Twilio bit, just solved that one :-)

Peter McNeill

unread,
Feb 26, 2016, 7:49:07 AM2/26/16
to Node-RED


On Wednesday, 24 February 2016 21:00:13 UTC, Dave C-J wrote:
Hi,
Looks good to me - even works for me... :-(



I don't have much experience in using node-red, but when I deploy the flow I have above it returns an error of "Missing server configuration" then followed by "TypeError: Cannot read property 'wholemsg' of null"

Any ideas what it is I have missed? 

Nicholas O'Leary

unread,
Feb 26, 2016, 8:14:05 AM2/26/16
to Node-RED Mailing List
Hi Peter,

can you share the actual flow? Hard to debug a picture of one :)

The 'Missing server configuration' is probably coming from your websocket nodes - but you can check that by looking at the node id that is part of the log message and seeing which node it relates to.


Nick

--

Peter McNeill

unread,
Feb 26, 2016, 9:41:12 AM2/26/16
to Node-RED
I managed to debug it and got it working thankfully!

I have a small problem now. So I am testing reading the message coming in from my python program by sending it to the debug.

It is returning it as undefined. I was wondering how I go about node-red reading it as a string.

I have used the same python code as above along with a very simple flow:

My formatting does this:

msg.python = msg.python.toString();
return msg;

Dave C-J

unread,
Feb 26, 2016, 9:43:09 AM2/26/16
to node...@googlegroups.com
you will need to set the debug node to show the msg.python property... by default we normally use msg.payload and the "expected" place to find data... so the debug node defaults to that.

Peter McNeill

unread,
Feb 26, 2016, 10:05:13 AM2/26/16
to Node-RED
Ah I see, got it working now. Thanks for your help everyone!

Peter McNeill

unread,
Feb 27, 2016, 2:53:50 PM2/27/16
to Node-RED
Still a bit confused with this but didn't want to start a new thread.

My flow now looks like this:


So my python app sits on my desktop and successfully connects to the location web socket and node red prints this out to the debug ok.

But the simple web socket doesn't pass the message on.

My understanding of the flow is, my python app sends a message on the websocket, node red formats the message and sends it onto the simple websocket, the http in  will then pull this message from the websocket and pass it to my html page.

Is my understanding of the flow correct?

Or do you need more information?

Thanks again.




On Wednesday, 24 February 2016 16:47:19 UTC, Peter McNeill wrote:

Nicholas O'Leary

unread,
Feb 27, 2016, 3:15:11 PM2/27/16
to Node-RED Mailing List
HI Peter,

by default, when you have a Websocket In node wired to a Websocket Out node as you have in the top flow, the out node will be trying to send the message you give it back to the client who triggered the flow in the first place. In your scenario you want it to go to a different client.

The trick is to delete the msg._session property before passing the message to the Out node. This will cause the Out node to broadcast the message to everyone who is connected to that websocket end point.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack

---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Peter McNeill

unread,
Feb 27, 2016, 4:08:02 PM2/27/16
to Node-RED
Perfect that did the trick. Cheers!

Milica Lekic

unread,
Jan 13, 2018, 8:18:32 AM1/13/18
to Node-RED


Hi Nick!!

I was googling about my problem with Node-RED and found out that You could help me. I hope You will answer to this as soon as possible!

My problem is:
I use Node-RED on my Raspberry Pi and Node-RED like app on Bluemix. I need to send data from Node-RED-RPi to Node-RED-Bluemix, it is temeprature, over WEBSOCKETs! But the data doesn't arrive to the Node-RED-Bluemix. I was following this tutorial: https://developer.ibm.com/recipes/tutorials/iot-temperature-and-moisture-sensor-integrated-to-node-red-and-bluemix-ibm/#r_step4 .
Last two screenshots on that page coresponde to my problem. I configured websockets, as there is said. One is Cliente, onother is Server. But, there is no connections between them, so there is no messages in DEBUG tab. I will send You links of Node-REDs :
 Node-RED-RPi -> http://10.99.133.40:1880/#flow/c72eb0f1.7ccfd
 and
Node-RED-Bluemix -> https://dht11sensor.eu-gb.mybluemix.net/red/#flow/d896d785.ad3cc8 .

I got errors in Node-RED-RPi : ws:undefined : Error: not opened

I HOPE You can help me!!!!

Julian Knight

unread,
Jan 13, 2018, 9:55:48 AM1/13/18
to Node-RED
For future use, it is best to start a new topic on the Google group for new questions.

I'm not a Bluemix expert by any means. But I doubt that you have websockets access to bluemix. Instead you probably want to have an MQTT broker locally and configure it to connect to MQTT on Bluemix. Your local Node-RED will talk to the local MQTT which will pass specified topics on to Bluemix.
Reply all
Reply to author
Forward
0 new messages