# MQTT-In Not Connecting

**URL:** <https://discourse.nodered.org/t/mqtt-in-not-connecting/17325>\
**Category:** General\
**Created:** [30 October 2019 12:24 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325 "2019-10-30T12:24:17Z")\
**Posts on this page:** 10\
**Page:** 4

<div class="post-metadata">

**Author:** ![mirou\_IoT](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mirou\_IoT](https://discourse.nodered.org/u/mirou_IoT)\
**Post date:** [6 November 2019 14:34 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/62 "2019-11-06T14:34:39Z")

</div>

@knolleary ok thank you i will try this

---

<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:** [6 November 2019 14:49 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/63 "2019-11-06T14:49:18Z")

</div>

> [@mirou\_IoT](#):
>
> don't use the MQTT explore i

I know, that is why I suggest you try it to see whether you can connect.  
Alternatively install mosquitto-clients on the pi  
`sudo apt install mosquitto-clients`  
then in a terminal run  
`mosquitto_sub -t "#" -h 176.31.nnn.nnn`  
and see whether it connects. If you have specified username/password in your broker then  
`mosquitto_sub -t "#" -h 176.31.nnn.nnn -u theuser -P thepwd`

---

<div class="post-metadata">

**Author:** ![mirou\_IoT](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mirou\_IoT](https://discourse.nodered.org/u/mirou_IoT)\
**Post date:** [6 November 2019 15:06 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/64 "2019-11-06T15:06:08Z")

</div>

@Colin thank you for help but i try (mosquitto\_sub -t "#" -h 176.31.nnn.nnn -u theuser -P thepwd and mosquitto\_pub -t "#" -h 176.31.nnn.nnn -u theuser -P thepwd) the error is connection was lost

---

<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:** [6 November 2019 15:12 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/65 "2019-11-06T15:12:57Z")

</div>

Did you replace the nnn.nnn with your IP and user pwd with your user/pwd?  
If so can you post the _exact_ error you get. If it does say 'connection lost' then that suggests it connects but then loses it. That is why the exact message is important.

**[Edit]** By the way you can't publish to the wildcard topic. You have to specify a particular topic.

---

<div class="post-metadata">

**Author:** ![mirou\_IoT](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mirou\_IoT](https://discourse.nodered.org/u/mirou_IoT)\
**Post date:** [6 November 2019 15:24 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/66 "2019-11-06T15:24:46Z")

</div>

the exact msg is error : connection was lost i use mosquitto\_sub -h 176.31.n.n -t testTopic and mosquitto\_pub -h 176.31.n.n -t testTopic -m "hello world" the result is error : connection was lost

---

<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:** [6 November 2019 15:29 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/67 "2019-11-06T15:29:24Z")

</div>

Have you configured mosquitto in the server to expect user/pwd and/or to use TLS?  
If not, then now is the time to try and answer the other question I asked some time ago. What does the mosquitto log on the server show?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 November 2019 15:35 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/68 "2019-11-06T15:35:42Z")

</div>

Another common issue is cloud hosts only export port 80/443 by default for HTTP/S traffic.

@mirou_IoT MQTT uses port 1883 to connect. Have you configured your server to expose that port?

In additional to Colin's questions, have you tried connecting from a different machine such as you own laptop/computer?

---

<div class="post-metadata">

**Author:** ![mirou\_IoT](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mirou\_IoT](https://discourse.nodered.org/u/mirou_IoT)\
**Post date:** [7 November 2019 08:36 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/69 "2019-11-07T08:36:19Z")

</div>

@knolleary i configured my server to expose the port 1883 , no i did not try to connect from different machine  
@Colin i use the mosquitto\_sub -h 176.31.n.n -t testTopic and mosquitto\_pub -h 176.31.n.n -t testTopic -m"humidity" the result that i have is connection was lost

---

<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:** [7 November 2019 09:35 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/70 "2019-11-07T09:35:37Z")

</div>

I have suggested several times that you look at the mosquitto log, but as far as I can see you have not even acknowledged that I asked.

---

<div class="post-metadata">

**Author:** ![mirou\_IoT](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mirou\_IoT](https://discourse.nodered.org/u/mirou_IoT)\
**Post date:** [7 November 2019 10:29 UTC](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325/71 "2019-11-07T10:29:10Z")

</div>

thank you all for help  
it's work good now the problem is the port 1883 i change it and it's connect good 🙂

[Previous page](https://discourse.nodered.org/t/mqtt-in-not-connecting/17325.md?page=3)
