MQTT over Websockets

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)

Screenshot_KNMI_Notification

My "MQTT Input" node has the following configuration:

and

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/ gives a message "Not found".

Has anybody an idea?

Thanks in advance,

Regards and Merry Christmas.

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

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 and also from: Accessing MQTT Broker using websockets from Node-RED – Cymplecy (Simplesi)

I also checked 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

1 Like

It does work (I'm certain :thinking:) 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.

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

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.

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:

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

1 Like

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

I think it defaults to 1883 if the port is not set, and the port cannot be set when using ws(s)://

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

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.

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.

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.

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