MQTT node disconnected

My flow shows the MQTT nodes as disconnected, I'm running mosquitto. It runs on port 1883 and the MQTT nodes are configured to connect in localhost on port 1883

image

image

When I run Node-red "node-red", I get this error at the terminal:

11 Nov 09:54:42 - [info] Starting flows
ReferenceError: URL is not defined
    at Object.connect (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/connect/index.js:64:18)
    at MQTTBrokerNode.connect (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:245:40)
    at MQTTBrokerNode.register (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:221:22)
    at new MQTTInNode (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:421:33)
    at Object.createNode (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/util.js:493:31)
    at Flow.start (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:194:48)
    at start (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:345:33)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Should I remove mosquitto and install it again?

No, that won't help.
Start node-red in a terminal and post the full log here, from the start up to the error message please.

user@user-VirtualBox:~$ node-red
11 Nov 11:03:37 - [info] 

Welcome to Node-RED
===================

11 Nov 11:03:37 - [info] Node-RED version: v1.2.3
11 Nov 11:03:37 - [info] Node.js  version: v8.10.0
11 Nov 11:03:37 - [info] Linux 5.4.0-52-generic x64 LE
11 Nov 11:03:37 - [info] Loading palette nodes
11 Nov 11:03:39 - [info] Settings file  : /home/user/.node-red/settings.js
11 Nov 11:03:39 - [info] Context store  : 'default' [module=memory]
11 Nov 11:03:39 - [info] User directory : /home/user/.node-red
11 Nov 11:03:39 - [warn] Projects disabled : editorTheme.projects.enabled=false
11 Nov 11:03:39 - [info] Flows file     : /home/user/.node-red/flows_user-VirtualBox.json
11 Nov 11:03:39 - [info] Server now running at http://127.0.0.1:1880/
11 Nov 11:03:39 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

11 Nov 11:03:39 - [info] Starting flows
ReferenceError: URL is not defined
    at Object.connect (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/connect/index.js:64:18)
    at MQTTBrokerNode.connect (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:245:40)
    at MQTTBrokerNode.register (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:221:22)
    at new MQTTInNode (/usr/local/lib/node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js:421:33)
    at Object.createNode (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/util.js:493:31)
    at Flow.start (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:194:48)
    at start (/usr/local/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:345:33)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
11 Nov 11:03:39 - [info] Started flows
(node:1588) DeprecationWarning: createSession: Create Session object directly instead

This is the log from the terminal

The problem is almost certainly the ancient version of nodejs you are using. Version 8.10 is nearly three years old and the latest release of 8.x (8.17.x I think) has been out of support for some months. At least upgrade to 8.17 and preferably to 12.x.

If you are using a Debian based OS such as Ubuntu then you can upgrade using the pi/Debian/Ubuntu script recommended in the node red docs. https://nodered.org/docs/getting-started/raspberrypi

This might be an issue with latest MQTT.js - there has been lots of activity on that project recently.

You could try modifying package.json in .node-red and setting mqtt version to an earlier version (see versions here) then run npm install

I would try 4.1.0 or 2.18.8

Isn't it the mqtt library installed with the node-red core that is giving the problem? If so then that is installed globally. Running, from the .node-red folder,
npm list mqtt
will show if it is installed locally (in .node-red/node_modules), or
npm list -g mqtt
will show if it is installed globally, and will show the version. I get

npm list -g mqtt
/usr/lib
└─┬ node-red@1.2.3
  └─┬ @node-red/nodes@1.2.3
    └── mqtt@4.2.4 

I got this inside .node-red

user@user-VirtualBox:~/.node-red$ npm list mqtt
node-red-project@0.0.1 /home/user/.node-red
└── (empty)

user@user-VirtualBox:~/.node-red$ mqtt list -g mqtt

Command 'mqtt' not found, did you mean:

  command 'mutt' from snap mutt (1-14-7-rel)
  command 'mutt' from deb mutt
  command 'mtt' from deb xawtv

See 'snap info <snapname>' for additional versions.

However, node-red works

Try adding -g to that npm command.

user@user-VirtualBox:~/.node-red$ npm -g list mqtt
/home/user/.nvm/versions/node/v14.4.0/lib
└── (empty)

Sorry, typo on my part, should have been npm list -g mqtt (which is actually the command I ran). I will correct my post.

You shouldn't be using nvm unless you know what you are doing. I suggest uninstalling that, uninstalling nodejs and npm and running the script I suggested. I still think the fundamental problem is the nodejs version.

Should I uninsall npm? It is part of the command you've provided me.

About installing the latest version of nodejs, I cannot upgrade from 8 to 12 (or later versions). I've followed many tutorial but it doesn't work.

Yes uninstall npm nodejs npm and (assuming you are running a Debian based distribution, then run the script.

It is ubuntu 18.04

ubuntu is debian based - run the installer as described in the docs.

Blasted phone! Try again: nvm, nodejs, npm

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