How can I connect MQTT via websockets on Node-Red?

3,647 views
Skip to first unread message

Jacobo del Bosque

unread,
Jan 6, 2018, 1:08:03 PM1/6/18
to Node-RED
Im tring to connect to external MQTT broker and I can't find te proper configuration because this broker only permit message via websocket.

This simple flow represent my case with HiveMQ demo.HiveMQ has to ports 1883 for direct MQTT connection and 8000 for connection via websocket:

[{"id":"c7421d30.2f9b5","type":"mqtt out","z":"d9446e20.0d5ed","name":"","topic":"testABC/1","qos":"","retain":"","broker":"547e83eb.abaf5c","x":445.5555114746094,"y":190.00000381469727,"wires":[]},{"id":"a178f322.75af4","type":"inject","z":"d9446e20.0d5ed","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":266.66666412353516,"y":190.00000190734863,"wires":[["c7421d30.2f9b5"]]},{"id":"547e83eb.abaf5c","type":"mqtt-broker","z":"","broker":"broker.hivemq.com","port":"8000","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

It is possible to do this thing?

Thanks

AIOT MAKER

unread,
Jan 6, 2018, 5:22:19 PM1/6/18
to Node-RED
Hello,


I guess you want to use the MQTT client from HiveMQ to test your Node-RED flow. Here is a walkthrough:




1- Open the MQTT client in your browser (http://www.hivemq.com/demos/websocket-client/)  and click the connect button. There is no need to change any field at this point.




You will see that the client will connect right away to the public MQTT broker from Hive MQ.


2- Subscribe to your topic by clicking the button "Add new topic subscription"



Result:




4- In the  Node-RED MQTT side, configure the node with server = broker.hivemq.com:1883 (not to port 8000 as in your flow). You will see that it will connect to the broker.








5- Click in the button from the inject node in Node-REd and you will see the msg being published to the topic.





Jacobo del Bosque

unread,
Jan 7, 2018, 1:42:18 AM1/7/18
to Node-RED
Thanks a lot AIOT MAKER, but that I really need is send message from Node-RED to a MQTT server but this server is configured with comunication via WebSocket on port 8000. Then my question is: Is there a configuration or contrib module to make a MQTT request via WebSocket on Node-RED?

P.D. This request isn't an invention of mine, MQTT servers like mosquitto, hivemq, etc can be configured to accept request via websockets. This link is evidence http://www.steves-internet-guide.com/mqtt-websockets/

AIOT MAKER

unread,
Jan 7, 2018, 6:08:38 AM1/7/18
to Node-RED
Hello Jacobo,

Did you try the WebSocket output node? If yes why it is not suited for your case?

I use this node, for instance,  with the WIOLINK module from SEEED studio, so as I can monitor in real time the events from several sensors.


Nick O'Leary

unread,
Jan 7, 2018, 6:21:05 AM1/7/18
to node...@googlegroups.com

AIOT, the websocket nodes create a raw ws connection for you to then send and receive whatever data you need. But the question here is about running the mqtt protocol over the ws connection - something you wouldn't want to implement for yourself in your flows.

Jacobo, I'm not aware of a ws enabled mqtt node. The library we use for the core mqtt nodes certainly supports websockets, we just don't expose it as an option. It would appear to be a sensible option for us to add. So whilst that isn't an immediate solution, we can look at doing that for the next release.

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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/223f31a6-a711-474b-a5bd-1c69625acb13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacobo del Bosque

unread,
Jan 7, 2018, 9:15:35 AM1/7/18
to Node-RED
Thank you very much, I will be aware of future versions and in the meantime I will look for another solution.

Jacobo del Bosque

unread,
Jan 7, 2018, 3:13:28 PM1/7/18
to Node-RED
My decision was to add to NodeRed the ability to send MQTT messages via WebSocket and I just sent a pull request to have my solution conveyed to you.

Add some screenshots to illustrate better:



Thanks

yk....@photobookworldwide.com

unread,
Mar 16, 2018, 7:03:44 AM3/16/18
to Node-RED
Hi @Jacobo,

I am having the same problem as you and would like to use your solution. Would you mind share with me please ?

Thanks.
-YK

Simon H

unread,
Mar 17, 2018, 7:07:23 AM3/17/18
to Node-RED
I've also augmented MQTT for WS:// connections.  Original 0.17 based version here https://github.com/btsimonh/node-red/commits/btsimonh-mqtt-0.17

But I thought I saw some updates in NR recently for WS and WSS in MQTT a few weeks back?  (not checked out myself).

Alternatively,

Adds a few nice features (connection status info, dynamic set of path from input), and includes WS/WSS.
(not up-to-date with latest updates to mqtt in NR).

br,
s

Simon H

unread,
Mar 17, 2018, 7:19:04 AM3/17/18
to Node-RED
I should say, I've been using the below in production against Mosca for about a year now, with few issues.  Untested against other servers, but the connection aspect is down to the underlying MQTT, not the NR node....
Reply all
Reply to author
Forward
0 new messages