MQTT Broker listening to ports , retreiving the data in Node-RED

503 views
Skip to first unread message

sudu...@gmail.com

unread,
Feb 15, 2018, 9:10:15 AM2/15/18
to Node-RED
Hello,

Sorry in advance for a simple question. I am:
  • running mosquitto broker on raspberry pi 3B. Default port is 1883.
  • now publishing the data to the same broker from the websocket (not a node-RED node) to the port 1885.(I configured the mosquitto.conf to listen to the port 1885).
  • trying to retrieve the data published by websocket in nodered.

But, Node-RED mqtt nodes could not connect to the localhost:1885.

I am totally new to this world. Please suggest me if I am doing it the right way.

Thanks in advance


steve rickus

unread,
Feb 15, 2018, 9:57:38 AM2/15/18
to Node-RED
You can configure the MQTT nodes to connect to any host/port you would like...
When you edit the MQTT In node, the first pulldown in a list of all the previously configured brokers.
Next to that is a button with a pencil icon -- click that to get to the broker configuration page.
There you can set all of the broker specific settings, including port 1885

sudu...@gmail.com

unread,
Feb 16, 2018, 3:31:30 AM2/16/18
to Node-RED
Thank you Steve for the detailed answer.

But currently, I am trying to communicate to the 1885 port from the websocket throught MQTT.

I observe that when the websocket communication is working (pub-sub), node-RED MQTT nodes cannot connect to the same port. 
Similarly, when node red nodes are connected, websockets won't connect.

My goal is to send the message from websocket to nodered MQTT node(subscribe). But I cannot make both work at the same time.

Any inputs will be appreciated.

Thanks!

Nick O'Leary

unread,
Feb 16, 2018, 3:39:45 AM2/16/18
to Node-RED Mailing List
To clarify, is your mosquitto broker listening on both 1883 and 1885? Or is it just 1885?

How exactly have you configured the mqtt-broker node in Node-RED? What broker url are you using?

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+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/fa08f493-21a4-4ef6-b2cf-afb3dbce215e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

sudu...@gmail.com

unread,
Feb 16, 2018, 3:44:46 AM2/16/18
to Node-RED
Hello Nick,
Yes the broker is listening on both 1883 and 1885

My mosquitto.conf has

port 1883

listener 1885
protocol websocket

listener 1883
protocol mqtt

In Node-RED, I have configured it as,

localhost:1885 

It is subscribed to the same topic the websocket is publishing.
But the status shows connecting and it is never connected unless the websocket is not using the port. 
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.

Nick O'Leary

unread,
Feb 16, 2018, 3:47:52 AM2/16/18
to Node-RED Mailing List
The MQTT nodes in Node-RED were only updated to support connecting over websockets in 0.18.

If you are on an earlier version, then the nodes will not be able to connect to port 1885 - you will have to use 1883.

If you are on 0.18, then, as described in the node help, you must use a full url such as ws://localhost:1885 to get the node to use websockets.

Is there a particular reason you want them both connecting to the same port even though you have it listening to both 1883 and 1885?

NIck 

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

sudu...@gmail.com

unread,
Feb 16, 2018, 3:57:24 AM2/16/18
to Node-RED
I am using Node-RED version 0.17.5! Now I see the problem.

The reason I need 1885 is, other sensor nodes are using the port 1883. I observed they don't receive any data when I try to configure it to listen to WebSocket.
later, I read somewhere that we have to add an extra port for mosquitto to communicate with WebSockets. So I configured it that way.

My action points:
  • I will use the 1883 port for both and try again. If that does not work,
  • I will update node-RED to 0.18 and try what you have explained.

Nick O'Leary

unread,
Feb 16, 2018, 4:00:11 AM2/16/18
to Node-RED Mailing List
If you want to use both normal tcp and websockets you will need two separate ports - just as you have done. 1883 for normal connections and 1885 for websockets.

Once connected, the clients can publish/subscribe to the same topic space regardless of which port they connected on.

Nick

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

sudu...@gmail.com

unread,
Feb 16, 2018, 7:29:01 AM2/16/18
to Node-RED
Hello,

As per your advice, I updated the Node-RED to 0.18 version.

Now I have 1883 (default) and 1885 (protocol websocket) (NOTE: 1883 not configured as listener)
 
port 1883

listener 1885
protocol websocket

  • with this, websocket communication with the broker works fine. But, no data sent/received in 1883 port. 
  • If I configure both 1883 and 1885  as listeners, both websocket and mqtt communication stops.
  • new core MQTT looks the same in the new version.
I am a bit confused. Any solutions to make it work?

Mark Setrem

unread,
Feb 16, 2018, 8:09:07 AM2/16/18
to Node-RED
I'm assuming the text in grey is from your Mosquitto config?

https://mosquitto.org/man/mosquitto-conf-5.html  suggests that "websocket" is not a valid value

protocol value
Set the protocol to accept for this listener. Can be mqtt, the default, or websockets if available.

sudu...@gmail.com

unread,
Feb 16, 2018, 8:12:32 AM2/16/18
to Node-RED
I am sorry. That was a typo.

It is "websockets" in the .conf file.

Eelco Folkertsma

unread,
Feb 17, 2018, 6:21:32 AM2/17/18
to Node-RED
Hi
I suggest you first work on getting the broker configured. It is helpful to see what is being published at the topics. My favourite viewer for this is MQTTspy.
1: bring mosquitto-broker back to config with listeners 1883-mqtt, 1885-websockets
2: connect MQTTspy to your broker at 1883 over mqtt and subscribe to all topics (#)
3: connect your sensors and let them send some messages
4: you should see all messages appear in MQTTspy

Once you have broker and sensors wired up per above, go back to Node-Red MQTT node and configure it to listen to broker end point at port 1883, again for all topics You now should see messages from all sensors. Note that the broker sits in between sensor and Node-Red so no need to align ports

Reply all
Reply to author
Forward
0 new messages