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
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)
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
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.
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
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.
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.