# MQTT over Websockets

**URL:** <https://discourse.nodered.org/t/mqtt-over-websockets/83992>\
**Category:** General\
**Created:** [23 December 2023 17:40 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992 "2023-12-23T17:40:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [23 December 2023 17:40 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/1 "2023-12-23T17:40:28Z")

</div>

Hello all,

I try to retrieve data from the Notification service of the Royal Netherlands Meteorological Institute (KNMI), but I do not have any experience with MQTT over Websockets and so this is quite new for me.

Perhaps someone with more experience sees it immediately and can give a hint.

The server has the following configuration (see: [Notification Service](https://developer.dataplatform.knmi.nl/notification-service#howto))

![Screenshot_KNMI_Notification](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7ac645a3035e51b98b9b97e766a7ec48d2b9e9ea.png)

My "MQTT Input" node has the following configuration:

 ![Screenshot_MQTT Input_KNMI](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/0/a0e0558e9758d27c3eaadd8b4988a562dfa4403e.png)

and

 ![Screenshot_MQTT Input_Config_KNMI](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d61ab332e033bd80963ac9140549927b3e1ae7c.png)

I tried several different settings in the configuration, but the node does not connect and keeps showing "connecting".

I also tried it with MQTT Explorer, but that does not connect either.  
I'm able to "ping" the server, so the server is online.  
A simple [https://mqtt.dataplatform.knmi.nl/](https://mqtt.dataplatform.knmi.nl/) gives a message "Not found".

Has anybody an idea?

Thanks in advance,

Regards and Merry Christmas.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2023 20:02 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/2 "2023-12-23T20:02:38Z")

</div>

Try removing the :443 from the host name and set the port entry to 443

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [24 December 2023 13:35 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/3 "2023-12-24T13:35:43Z")

</div>

Thank you, Steve, for your quick response.

Your suggestion to remove :443 after the host name and enter it in the port field does not work.  
As soon as you put :// in front of the host name, such as ws:// or wss:// the port entry field is disabled (greyed-out)

I got the suggestion from:[MQTT over WebSocket - Datacake Docs](https://docs.datacake.de/api/internal-mqtt/mqtt-over-websocket) and also from: [Accessing MQTT Broker using websockets from Node-RED – Cymplecy (Simplesi)](https://simplesi.net/accessing-mqtt-broker-using-websockets-from-node-red/)

I also checked [https://groups.google.com/g/node-red/c/ByzqoQdkGMI](https://groups.google.com/g/node-red/c/ByzqoQdkGMI), where Nick said, in fact, the MQTT over Websocket does not exist in Node-RED. This is approx 6 years ago and the time might have been changed since then. However I never saw the PR from Jacobo del Bosque.

Any other suggestions?

Regards

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 December 2023 13:49 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/4 "2023-12-24T13:49:26Z")

</div>

It does work (I'm certain 🤔) but I'm not in a position to try it out to show you. Will be home later. Hopefully someone will pop by with a quick how to before then.

Note: you will need to send me (private message (click my avatar-\>message)) with details of your MQTT server if you want me to try for you.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [24 December 2023 13:50 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/5 "2023-12-24T13:50:07Z")

</div>

Are you able to try out the python example to see if that works?

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [24 December 2023 17:45 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/6 "2023-12-24T17:45:40Z")

</div>

Hello@Steve-Mcl

I will send you the broker details in a PM.  
[Edit: Done]

Hello @cymplecy

Simon, thank you for jumping in.

I think, you mean the python example at [Notification Service](https://developer.dataplatform.knmi.nl/notification-service#example).

After a small modification of the script and inserting the CLIENT\_ID and the TOKEN I got a positive result. I had to add the shebang (#!/usr/bin/python3)  
The result:

```auto
pi@RPi1:~ $ ./KNMI-test.py 
INFO: __main__ :Connected using client ID: b'42117fea-e6dc-49e8-b976-62c8a8586705'
INFO: __main__ :Session present: 1
INFO: __main__ :Connection result: Success
INFO: __main__ :Subscribed to topic 'dataplatform/file/v1/radar_echotopheight_5min/1.0/#'
INFO: __main__ :Received message on topic dataplatform/file/v1/radar_echotopheight_5min/1.0/created: b'{"specversion": "1.0", "type": "nl.knmi.dataplatform.file.created.v1", "source": "https://dataplatform.knmi.nl", "id": "440c1390-c56b-0d18-5c39-197d856f88c2", "time": "2023-12-24T17:30:34Z", "datacontenttype": "application/json", "data": {"datasetName": "radar_echotopheight_5min", "datasetVersion": "1.0", "filename": "RAD_NL25_ETH_NA_202312241725.h5", "url": "https://api.dataplatform.knmi.nl/open-data/v1/datasets/radar_echotopheight_5min/versions/1.0/files/RAD_NL25_ETH_NA_202312241725.h5/url"}}'
INFO: __main__ :Received message on topic dataplatform/file/v1/radar_echotopheight_5min/1.0/created: b'{"specversion": "1.0", "type": "nl.knmi.dataplatform.file.created.v1", "source": "https://dataplatform.knmi.nl", "id": "f9390589-8c8b-01aa-293f-f741c1c3f870", "time": "2023-12-24T17:35:33Z", "datacontenttype": "application/json", "data": {"datasetName": "radar_echotopheight_5min", "datasetVersion": "1.0", "filename": "RAD_NL25_ETH_NA_202312241730.h5", "url": "https://api.dataplatform.knmi.nl/open-data/v1/datasets/radar_echotopheight_5min/versions/1.0/files/RAD_NL25_ETH_NA_202312241730.h5/url"}}'

```

So every 5 minutes I receive a message from the Python script. My conclusion so far is that the endpoint is giving a valid response.

I hope this is enough information for you.

Thanks for your time to look into this issue.

Regards

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [24 December 2023 17:49 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/7 "2023-12-24T17:49:59Z")

</div>

Great that you got that working - it verifies that your API key and all the other information is correct 🙂

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 December 2023 18:26 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/8 "2023-12-24T18:26:40Z")

</div>

I think it [defaults to 1883 if the port is not set](https://github.com/node-red/node-red/blob/0e8d3127944a91f39fb49bcb4b388b184ce11edd/packages/node_modules/%40node-red/nodes/core/network/10-mqtt.js#L656), and the port cannot be set when using ws(s)://

---

<div class="post-metadata">

**Author:** ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)\
**Post date:** [24 December 2023 18:55 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/9 "2023-12-24T18:55:35Z")

</div>

Yes, as soon as you insert :// in front of the hostname, such as ws:// or wss:// the port field is disabled. Therefore I found the suggestion to add the port after the hostname.

See links above.

However playing with this gives not any results and it ends even in a crash of Node-RED.

Regards

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [24 December 2023 20:03 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/10 "2023-12-24T20:03:36Z")

</div>

If you need a temporary work around, you could set up a local broker. Talk to that over mqtt. Then get it to talk to the remote broker over websockets.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 December 2023 21:55 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/11 "2023-12-24T21:55:07Z")

</div>

I have certainly had this working, though I don't have a working wss server at the moment. Looking at the server node setup I see that I entered the the port number in the same way you have, but it also shows as greyed out in the port field. I assume that I entered that field before filling in the url. That should not make a difference but you never know.

> [@FireWizard52](#):
>
> it ends even in a crash of Node-RED

Can you show us the crash please? In fact start node red in a command window and show us the full node red startup output up to the crash.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 February 2024 21:55 UTC](https://discourse.nodered.org/t/mqtt-over-websockets/83992/12 "2024-02-22T21:55:24Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
