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

**URL:** https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675
**Category:** General
**Created:** [28 December 2019 10:27 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675 "2019-12-28T10:27:40Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [28 December 2019 10:27 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/1 "2019-12-28T10:27:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 December 2019 12:18 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/2 "2019-12-28T12:18:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [28 December 2019 13:52 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/3 "2019-12-28T13:52:45Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 December 2019 15:04 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/4 "2019-12-28T15:04:41Z")

</div>

> [@awsnode](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 December 2019 15:59 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/5 "2019-12-28T15:59:40Z")

</div>

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](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) to see how to share if you have not done it before.

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [29 December 2019 00:12 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/6 "2019-12-29T00:12:56Z")

</div>

````auto
[{"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.
````

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 December 2019 07:05 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/8 "2019-12-29T07:05:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [29 December 2019 07:28 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/9 "2019-12-29T07:28:40Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [29 December 2019 07:29 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/10 "2019-12-29T07:29:30Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 December 2019 08:37 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/11 "2019-12-29T08:37:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [29 December 2019 14:06 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/12 "2019-12-29T14:06:38Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 December 2019 14:16 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/13 "2019-12-29T14:16:20Z")

</div>

Is there anything else connected to that broker?

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [30 December 2019 00:31 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/14 "2019-12-30T00:31:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 December 2019 09:09 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/15 "2019-12-30T09:09:14Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![awsnode](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@awsnode](https://discourse.nodered.org/u/awsnode)
#### Post date: [31 December 2019 05:40 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/16 "2019-12-31T05:40:57Z")

</div>

yes. it works with 1.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 December 2019 14:22 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/17 "2019-12-31T14:22:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [31 December 2019 14:24 UTC](https://discourse.nodered.org/t/node-red-mqtt-in-node-not-working-for-aws-iot/19675/18 "2019-12-31T14:24:32Z")

</div>

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