Node-red mqtt-in node not working for aws iot

Hello,
i'm trying to connect to aws iot from node-red..The MQTT out node seem to work without any issues
However the moment I add mqtt-in node the connection keeps toggling.. The connect is intermittent (based on the console logs. it connects and subsequently disconnects).

How do i troubleshoot this further. THe log dont seem to provide much details.

appreciate your support

Have you got two mqtt configuration nodes with the same client id specified?
In particular, in node-red make sure you use the same configuration node for all In and Out nodes that use that server.

Hi,
There is only one configuration node. The mqtt out node don't seem to have any problem. Only the mqtt IN node is having the problem. The connection keeps resetting..(i'm seeing the connected and eventually disconnected message from the console.

Since the configuration node is the same, the client id is also the same..

Is there any detailed log available for node-red ?

Run node red in a terminal and the log will appear there.
It would also be worth looking in the log for your mqtt server, if you can access that.

Could you export the In and Out nodes and post them here so we can see if there is anything unusual there?
Read this post to see how to share if you have not done it before.

[{"id":"6b723fb1.24587","type":"tab","label":"Flow 2a","disabled":false,"info":""},{"id":"31d4595c.251b66","type":"mqtt in","z":"6b723fb1.24587","name":"","topic":"demo","qos":"2","datatype":"auto","broker":"82526810.02b8d8","x":95,"y":220,"wires":[["172af53a.723e0b"]],"l":false},{"id":"172af53a.723e0b","type":"debug","z":"6b723fb1.24587","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":220,"wires":[]},{"id":"82526810.02b8d8","type":"mqtt-broker","z":"","name":"TEST","broker":"yyyy-ats.xx.yy-2.xxx.com","port":"8883","tls":"87e7a49e.56b3a8","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"87e7a49e.56b3a8","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"xxxx-certificate.pem.crt","keyname":"xxx-private.pem.key","caname":"rootca.pem","servername":"","verifyservercert":true}]```

above is he flow (masked some parameters). have included only the mqtt-in node. If i use only the mqtt-out node, it works fine. If i use mqtt-in alone or both the mqtt-in & out (sharing the config node), the connection keeps resetting.

Please post both in and out so we can see what the conflict is

sure. please find the attached. Even with just the mqtt-in alone in the flow it doesn't connect. appreciate ur support

[{"id":"d689d22c.4acf9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"723469b0.a744b8","type":"inject","z":"d689d22c.4acf9","name":"","topic":"iotdemo","payload":"{\"desired\":{\"powerOn\":1},\"reported\":{\"powerOn\":0}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["9ca435b.e58abc8","4fa8de85.cc28b"]]},{"id":"9ca435b.e58abc8","type":"mqtt out","z":"d689d22c.4acf9","name":"","topic":"iotdemo","qos":"","retain":"","broker":"82526810.02b8d8","x":450,"y":120,"wires":[]},{"id":"4fa8de85.cc28b","type":"debug","z":"d689d22c.4acf9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":310,"y":200,"wires":[]},{"id":"8cc9140a.c3ffa8","type":"mqtt in","z":"d689d22c.4acf9","name":"","topic":"iotdemo","qos":"2","datatype":"auto","broker":"82526810.02b8d8","x":110,"y":300,"wires":[["4fa8de85.cc28b"]]},{"id":"82526810.02b8d8","type":"mqtt-broker","z":"","name":"TEST","broker":"qqq.com","port":"8883","tls":"87e7a49e.56b3a8","clientid":"asasa1212","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"87e7a49e.56b3a8","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"mycert.pem.crt","keyname":"mykeyprivate.pem.key","caname":"rootca1.pem","servername":"","verifyservercert":true}]

please find the attached. even with the mqtt-in alone it doesn't work

[{"id":"d689d22c.4acf9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"723469b0.a744b8","type":"inject","z":"d689d22c.4acf9","name":"","topic":"demo","payload":"{\"desired\":{\"status\":1},\"reported\":{\"status\":0}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["9ca435b.e58abc8","4fa8de85.cc28b"]]},{"id":"9ca435b.e58abc8","type":"mqtt out","z":"d689d22c.4acf9","name":"","topic":"iotdemo","qos":"","retain":"","broker":"82526810.02b8d8","x":450,"y":120,"wires":[]},{"id":"4fa8de85.cc28b","type":"debug","z":"d689d22c.4acf9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":310,"y":200,"wires":[]},{"id":"8cc9140a.c3ffa8","type":"mqtt in","z":"d689d22c.4acf9","name":"","topic":"iotdemo","qos":"2","datatype":"auto","broker":"82526810.02b8d8","x":110,"y":300,"wires":[["4fa8de85.cc28b"]]},{"id":"82526810.02b8d8","type":"mqtt-broker","z":"","name":"TEST","broker":"qqq.com","port":"8883","tls":"87e7a49e.56b3a8","clientid":"asasa1212","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"87e7a49e.56b3a8","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"mycert.pem.crt","keyname":"mykeyprivate.pem.key","caname":"rootca1.pem","servername":"","verifyservercert":true}]

Please post the node red startup log (should start with welcome to node red) and tell us what operating system you are running.
[Edit] That is with the In node included so we can see the exact error too.

Hi,
i couldn't find any detailed log file. below is what is seen from the console. in settings.js i have tried to enable the level to "trace"..but don't seem to take effect. I'm running windows 10

C:\Users\xxxxx>node-red
29 Dec 22:02:55 - [info]

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

29 Dec 22:02:55 - [info] Node-RED version: v1.0.2
29 Dec 22:02:55 - [info] Node.js  version: v10.14.1
29 Dec 22:02:55 - [info] Windows_NT 10.0.18362 x64 LE
29 Dec 22:02:56 - [info] Loading palette nodes
29 Dec 22:02:57 - [info] Dashboard version 2.17.1 started at /ui
29 Dec 22:02:57 - [info] Settings file  : \Users\xxxxx\.node-red\settings.js
29 Dec 22:02:57 - [info] Context store  : 'default' [module=memory]
29 Dec 22:02:57 - [info] User directory : \Users\xxxxx\.node-red
29 Dec 22:02:57 - [warn] Projects disabled : editorTheme.projects.enabled=false
29 Dec 22:02:57 - [info] Flows file     : \Users\xxxxx\.node-red\flows_LAPTOP-04DHNNC2.json
29 Dec 22:02:57 - [info] Server now running at http://127.0.0.1:1880/
29 Dec 22:02:57 - [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.
---------------------------------------------------------------------

29 Dec 22:02:57 - [info] Starting flows
29 Dec 22:02:57 - [info] Started flows
29 Dec 22:02:58 - [info] [mqtt-broker:xxxxx-aws-iot] Connected to broker: mqtts://xxxx..com:8883
29 Dec 22:02:58 - [info] [mqtt-broker:xxxxx-aws-iot] Disconnected from broker: mqtts://xxxx.com:8883
2

Is there anything else connected to that broker?

got it working finally.. Set the QoS to 0. Initially it was 2.

That sounds like an issue with the MQTT server. It certainly should work with QOS=2. With 0 it is not guaranteed that the value gets through. Does it work with 1?

yes. it works with 1.

Perhaps that mqtt server cannot handle QoS 2. That QoS is only needed for situations where you must not receive the same value twice, so generally 1 is the one to use.

As documented here - https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html

1 Like