MQTT Connects then disconnects?

Hello All,

Hope you are all well,

Here we have an issue with MQTT where all I`m wanting at the moment is a input out put of a random number generator between two devices.

Device 1 (Receiving)


image
image

Device 2 (Sending) Rasp Pi.

142100388_247048216811319_3708394862422742304_n 142368076_768740633733436_1461429314025222120_n 141794398_5462615717089320_3062832048068930615_n 141529337_440733540441204_1563225312115629261_n

As you can see topics are the same, client ID is different , both the certificates and keys are seperate to each device, when I load the MQTT on Pi it connects straight away then disconnects- nothing is sent in the process. Meanwhile Device 1 is firmly connected.

Any ideas anyone? Currently clueless as to whats wrong?

Thank you all!

Are you using the latest version of node-red? There was an issue recently with an mqtt problem that has now been fixed.

They are both using the same latest version.

Stop node-red and start it in a terminal on the pi and post the log here please. Copy/paste please rather than screenshot if possible please. When you paste it in use the </> button at the top of the forum text window.
You can stop and start on the pi using
node-red-stop
node-red-start

1 Like
Welcome to Node-RED
===================
23 Jan 15:23:53 - [info] Node-RED version: v1.2.7
23 Jan 15:23:53 - [info] Node.js  version: v12.18.2
23 Jan 15:23:53 - [info] Linux 4.19.118-v7l+ arm LE
23 Jan 15:23:54 - [info] Loading palette nodes
23 Jan 15:23:58 - [info] Dashboard version 2.27.0 started at /ui
23 Jan 15:23:59 - [info] Settings file  : /home/pi/.node-red/settings.js
23 Jan 15:23:59 - [info] Context store  : 'default' [module=memory]
23 Jan 15:23:59 - [info] User directory : /home/pi/.node-red
23 Jan 15:23:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
23 Jan 15:23:59 - [info] Flows file     : /home/pi/.node-red/flows_Chipcobpi.json
23 Jan 15:23:59 - [info] Server now running at http://127.0.0.1:1880/
23 Jan 15:23:59 - [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.
---------------------------------------------------------------------
23 Jan 15:23:59 - [info] Starting flows
23 Jan 15:23:59 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:23:59 - [info] Started flows
23 Jan 15:24:00 - [info] [mqtt-broker:ChipCob2] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:24:04 - [info] [mqtt-broker:ChipCob2] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:24:17 - [info] Stopping flows
23 Jan 15:24:17 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:24:32 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:24:32 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:24:32 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:24:32 - [info] Stopped flows
23 Jan 15:24:32 - [info] Starting flows
23 Jan 15:24:32 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:24:32 - [info] Started flows
23 Jan 15:24:32 - [info] [mqtt-broker:ChipCob2] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:24:37 - [info] [mqtt-broker:ChipCob2] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:27:35 - [info] Stopping flows
23 Jan 15:27:35 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:27:50 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:27:50 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:27:50 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:27:50 - [info] Stopped flows
23 Jan 15:27:50 - [info] Starting flows
23 Jan 15:27:50 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:27:50 - [info] Started flows
23 Jan 15:27:51 - [info] [mqtt-broker:ChipCob2] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:27:56 - [info] [mqtt-broker:ChipCob2] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:28:36 - [info] Stopping flows
23 Jan 15:28:36 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:28:51 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:28:51 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:28:51 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:28:51 - [info] Stopped flows
23 Jan 15:28:51 - [info] Starting flows
23 Jan 15:28:51 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:28:51 - [info] Started flows
23 Jan 15:28:51 - [info] [mqtt-broker:ChipCob2] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:28:56 - [info] [mqtt-broker:ChipCob2] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:29:10 - [info] Stopping flows
23 Jan 15:29:10 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:29:25 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:29:25 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:29:25 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:29:25 - [info] Stopped flows
23 Jan 15:29:25 - [info] Starting flows
23 Jan 15:29:25 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:29:25 - [info] Started flows
23 Jan 15:29:25 - [info] [mqtt-broker:ChipCob2] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:29:30 - [info] [mqtt-broker:ChipCob2] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:30:08 - [info] Stopping flows
23 Jan 15:30:08 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:30:23 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:30:23 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:30:23 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:30:23 - [info] Stopped flows
23 Jan 15:30:23 - [info] Starting flows
23 Jan 15:30:23 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:30:23 - [info] Started flows
23 Jan 15:30:24 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:30:29 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:33:53 - [info] Stopping flows
23 Jan 15:33:53 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:34:08 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:34:08 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:34:08 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:34:08 - [info] Stopped flows
23 Jan 15:34:08 - [info] Starting flows
23 Jan 15:34:08 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:34:08 - [info] Started flows
23 Jan 15:34:38 - [info] [mqtt-broker:server] Connection failed to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:1883
23 Jan 15:35:23 - [info] [mqtt-broker:server] Connection failed to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:1883
23 Jan 15:36:09 - [info] [mqtt-broker:server] Connection failed to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:1883
23 Jan 15:36:54 - [info] [mqtt-broker:server] Connection failed to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:1883
23 Jan 15:37:10 - [info] Stopping flows
23 Jan 15:37:10 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:37:25 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:37:25 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:37:25 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:37:25 - [info] Stopped flows
23 Jan 15:37:25 - [info] Starting flows
23 Jan 15:37:25 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:37:25 - [info] Started flows
23 Jan 15:37:26 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:37:30 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:37:39 - [info] [mqtt-broker:server] Connection failed to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:1883
23 Jan 15:38:21 - [info] Stopping flows
23 Jan 15:38:21 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:38:36 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:38:36 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:38:36 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:38:36 - [info] Stopped flows
23 Jan 15:38:36 - [info] Starting flows
23 Jan 15:38:36 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:38:36 - [info] Started flows
23 Jan 15:38:37 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:38:41 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:53:18 - [info] Stopping flows
23 Jan 15:53:18 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 15:53:33 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 15:53:33 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 15:53:33 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 15:53:33 - [info] Stopped flows
23 Jan 15:53:33 - [info] Starting flows
23 Jan 15:53:33 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 15:53:33 - [info] Started flows
23 Jan 15:53:34 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 15:53:39 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 16:19:03 - [info] Stopping flows
23 Jan 16:19:03 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 16:19:18 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 16:19:18 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 16:19:18 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 16:19:18 - [info] Stopped flows
23 Jan 16:19:18 - [info] Starting flows
23 Jan 16:19:18 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 16:19:18 - [info] Started flows
23 Jan 16:19:18 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 16:19:23 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 16:20:25 - [info] Stopping flows
23 Jan 16:20:25 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 16:20:40 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 16:20:40 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 16:20:40 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 16:20:40 - [info] Stopped flows
23 Jan 16:20:40 - [info] Starting flows
23 Jan 16:20:40 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 16:20:40 - [info] Started flows
23 Jan 16:20:41 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 16:20:45 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
Stopping Node-RED graphical event wiring tool...
23 Jan 17:22:24 - [info] Stopping flows
23 Jan 17:22:24 - [info] [aws-iot-device:ChipCob2] closed  ok
23 Jan 17:22:39 - [error] [modbusSerialConfig:2ff6ce39.133412] Error stopping node: Close timed out
23 Jan 17:22:39 - [error] [modbusSerialConfig:c84e12fd.be701] Error stopping node: Close timed out
23 Jan 17:22:39 - [error] [modbusSerialConfig:sensor] Error stopping node: Close timed out
23 Jan 17:22:39 - [info] Stopped flows
nodered.service: Succeeded.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
23 Jan 17:22:45 - [info]
Welcome to Node-RED
===================
23 Jan 17:22:45 - [info] Node-RED version: v1.2.7
23 Jan 17:22:45 - [info] Node.js  version: v12.18.2
23 Jan 17:22:45 - [info] Linux 4.19.118-v7l+ arm LE
23 Jan 17:22:45 - [info] Loading palette nodes
23 Jan 17:22:49 - [info] Dashboard version 2.27.0 started at /ui
23 Jan 17:22:50 - [info] Settings file  : /home/pi/.node-red/settings.js
23 Jan 17:22:50 - [info] Context store  : 'default' [module=memory]
23 Jan 17:22:50 - [info] User directory : /home/pi/.node-red
23 Jan 17:22:50 - [warn] Projects disabled : editorTheme.projects.enabled=false
23 Jan 17:22:50 - [info] Flows file     : /home/pi/.node-red/flows_Chipcobpi.json
23 Jan 17:22:50 - [info] Server now running at http://127.0.0.1:1880/
23 Jan 17:22:50 - [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.
---------------------------------------------------------------------
23 Jan 17:22:50 - [info] Starting flows
23 Jan 17:22:50 - [info] [aws-iot-device:ChipCob2] callback created
23 Jan 17:22:50 - [info] Started flows
23 Jan 17:22:50 - [info] [mqtt-broker:server] Connected to broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883
23 Jan 17:22:55 - [info] [mqtt-broker:server] Disconnected from broker: 2@mqtts://a1wj6cyprbq05g-ats.iot.eu-west-2.amazonaws.com:8883



Have a look at the mqtt broker log on the server and see if it says why it is disconnecting.

Thing is on the laptop its connecting fine? Its just the pi that connects then disconnects randomly

That isn't what you said earlier, you said that it connects and immediately disconnects, and doesn't manage to pass any data. Is that still correct?

Yes, the question is, why? The server log may give you a clue.
Are there any other MQTT clients in the network?
Check on both devices that you only have one MQTT config setup for that server. So if you go into an MQTT node and click the Server dropdown that you don't see any extra ones that point to the relevant server. If there are then delete them from the Config Nodes menu option.

Thanks for the reply Colin ,

Yes so it connects and disconnects immediately no data sent on the pi, but the laptop connects fine.

In the drop down i don't have any other mqtt servers set to the same location. Both the server was set up on aws with the exclusive url and different client IDS. I'll do as you say and check perhaps on the aws side as generally I believe the node red side is correct.

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