CoAP server not respecting node configuration port setting?

Hi,

i searched quite a long in the forum and the wild Internet but without success, maybe I'm just blind, but... :wink: So I registered here and this is my first post.

I have a node-red system running without any issues so far. The system contains the following components:
Ubuntu 24.04.1 on a VPS at a hosting provider.
Firewall (ufw) is configured for ports 5683/udp (v4 and v6)
npm 10.9.2
node 22.8.0
node-red 4.0.8
node-red-contrib-coap 0.8.0

I have a running CoAP server which is responding correctly to a IoT device sending requests to this server. So far so good.

By some reasons i have to change the port, the CoAP server is listening. So I changed the port in the coap server node from 5683 to 5685 and opened the port in the firewall as well (5683 still open).

If the IoT device now sends requests to port 5685, there is no response from the server. Checking with tcpdump shows, that the packet has passed the firewall but also tcpdump shows no server response. I rechecked the node configuration, 5685 is shown. I did a restart of node-red, no success. Next I reconfigured the IoT device to use the original port 5683. Now the server responded, even its port configuration still shows 5685. The same behaviour happens with any non-standard port.

The only way i found after digging deeper is changing the default UDP port (COAP_PORT) in the file .node-red/node_modules/coap/dist/lib/parameters.js to 5685.
Now the server listens on port 5685 all the time, regardless the server node configuration value.

It seems, that the server node does not use the configuration value but the default value, rergardless the port configuration. The server always uses the value set in COAP_PORT.

Is there anything I missed here or I'm doing completely wrong? Is this a kind of "undocumented known issue"?

I have to say, I am a experienced embedded C developer but not a specialist in node.js/node-red.

Thanks a lot and have a nice day,
Bernhard

Hi Bernard, welcome to the forum.

Given the lack of responses, I am guessing there not too many folk here running coap (or they just stick with the default port).

You might get some luck raising an issue on the github repo here: GitHub · Where software is built


To aid with Debugging (and for valuable info for the github issue you raise)...

Rather than editing the coap lib (that is a dependency of the contrib node, not something the author has control over), I would personally edit the contrib nodes code itself around here: node-red-contrib-coap/coap/coap-in.js at main · JKRhb/node-red-contrib-coap · GitHub
(probably found in .node-red/node_modules/node-red-contrib-coap/coap/coap-in.js but it depends on your system)

        node.server.listen(config.port, function () {
            node.log("CoAP Server Started");
        });

Try logging to console the port number being used!

        console.warn("calling node.server.listen with config.port:", config.port)
        node.server.listen(config.port, function () {
            node.log("CoAP Server Started on port " + config.port);
        });

also, a few lines up where you see node.server = new coap.createServer(serverSettings); I would try changing that to:

serverSettings.coapPort = config.port;
console.warn("Creating coap server with settings:", serverSettings);
node.server = new coap.createServer(serverSettings);
1 Like

Hi Steve!

Thanks for this very helpful answer. I will have a look in your suggested way. It's clear to me that modifying the lib is just a quick and dirty workaround but for the moment it fixed my problem.

I will add the additional logging and raise an issue on GitHub. It will take some time as I'm quite busy right now.

Anyway, if there are news, i will tell it here so that other peoples having the same issue in the future will probably find this post an getting some answers from it.

Thanks and have a good day!
Bernhard