# \[SOLVED\] Getting timeouts to Losant but not other MQTT brokers

**URL:** <https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622>\
**Category:** Help\
**Created:** [September 21, 2017, 5:06pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622 "2017-09-21T17:06:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [September 21, 2017, 5:06pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/1 "2017-09-21T17:06:13Z")

</div>

I wrote a script to interpret engine logs and rebroadcast them via MQTT. It works perfect connected to test dot mosquitto dot org, but I’m getting timeouts with broker dot losant dot com

Using straight TCP for now. Using the info here. [https://docs.losant.com/mqtt/overview/](https://docs.losant.com/mqtt/overview/) and this MQTT library [https://github.com/bluerhinos/phpMQTT](https://github.com/bluerhinos/phpMQTT)

I do not have anything in the communication log for the application.

I can ping the broker.

I’m not sure what could be broken. At this point I know the script works connected to another MQTT server, without authentication at least. That seems to be the only thing different, and I’m going to test that shortly.

Any other ideas?

---

<div class="post-metadata">

**Author:** ![Tim\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@Tim\_Hoffman](https://forums.losant.com/u/Tim_Hoffman)\
**Post date:** [September 22, 2017, 7:49am UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/2 "2017-09-22T07:49:36Z")

</div>

We have about nearly 60 devices (about 30+ gateways) connected to losant at the moment using mosquitto as a local broker which forwards (bridge) everything to losants broker.

We are connected using TLS.

We are connecting via fairly unreliable network (3g) connections so do get a range of timeouts, connect errors etc

This is a connection log for a single gateway device since the 14th.

Device ID Date Sent Rec Details  
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 1:18:07 PM   
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 1:18:04 PM 403 0 Error: read ECONNRESET  
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 12:10:52 PM   
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 12:10:52 PM 161 0 Device establishing new connection, closing previous connection  
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 11:44:05 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 11:44:05 AM 233 0 Device establishing new connection, closing previous connection  
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 11:04:55 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 11:04:55 AM 358 0 Device establishing new connection, closing previous connection  
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 10:04:53 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/22/2017 10:04:45 AM 2793 0 Publish Error - Error: connect ECONNREFUSED 146.148.110.247:443  
591xxxxxxxxxxxxxxxxxxf7cd 09/15/2017 1:03:56 PM 4967 0 Keepalive Timeout  
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 11:14:22 PM   
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 11:14:19 PM 4318 0 Error: read ECONNRESET  
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 11:14:22 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 11:14:18 AM 360 0 Error: read ECONNRESET  
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 10:14:21 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 10:14:19 AM 1513 0 Error: read ECONNRESET  
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 6:02:03 AM   
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 6:02:02 AM 39 0 The server-side MQTT broker has been restarted for maintenance or upgrades  
591xxxxxxxxxxxxxxxxxxf7cd 09/14/2017 5:55:42 AM

This is a particularly bad network at times. (there is a big gas plant being constructed 5km off shore and the network can get hammered at times. All those tradies watch youtube during smoko 😉

Mosquitto will automatically retry the connection, and we are using QOS 1 for publishing so this is pretty self healing.

I was originally publishing directly via a python application but I found I had to deal with so many different network failure scenarios that I have up and now use that same python code to publish to the local broker acting as a bridge.

Everthing has been significantly more reliable since adopting that approach, and it keeps my code much simpler.

Cheers

Tim

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [September 22, 2017, 2:17pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/3 "2017-09-22T14:17:23Z")

</div>

In my case I’m not going to a local broker first, and both connections are on the same network in the same conditions.

It’s timing out to the losant broker but not the [test.mosquitto.org](http://test.mosquitto.org) broker. That implies o me the code is fine. Is it possible there’s a difference between them?

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [September 22, 2017, 2:35pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/4 "2017-09-22T14:35:31Z")

</div>

Hi @paul_wareham,

I’m sorry you are having problems! I have a couple questions that could help me figure out your issue.

Is the phpMQTT library the only one you tested out?

Are you getting any MQTT error codes after you run the script connecting to Losant?

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [September 22, 2017, 9:14pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/5 "2017-09-22T21:14:55Z")

</div>

Adding resolution here for others benefit.

Got it working. It was actually 2.2.3 Remaining Length in the MQTT spec that was the issue for that library. It only works up to 128 byte connect messages; the username / password put me up to 140.

> <https://github.com/bluerhinos/phpMQTT/pull/47>

---

<div class="post-metadata">

**Author:** ![Chen\_Tea](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@Chen\_Tea](https://forums.losant.com/u/Chen_Tea)\
**Post date:** [October 22, 2017, 8:55pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/6 "2017-10-22T20:55:01Z")

</div>

> [@Tim\_Hoffman](#):
>
> Keepalive Timeout

I have the same issue just using Arduino IDE to flash the ESP8266 board and sent MQTT payload to Losant server and I am disconnected every few minutes. The Losant show Keepalive Timeout error. How do you solve this and do you have sample codes to fix this.

---

<div class="post-metadata">

**Author:** ![Dung\_Le](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dung_le/32/500_2.png) [@Dung\_Le](https://forums.losant.com/u/Dung_Le)\
**Post date:** [February 2, 2018, 6:37pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/7 "2018-02-02T18:37:44Z")

</div>

@Chen_Tea I have same issue, if anyone has solution please share? Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Zac\_Helmberger](https://avatars.discourse-cdn.com/v4/letter/z/c89c15/32.png) [@Zac\_Helmberger](https://forums.losant.com/u/Zac_Helmberger)\
**Post date:** [April 30, 2018, 3:34pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/9 "2018-04-30T15:34:58Z")

</div>

I have the same issue as well. I have Arduino IDE 1.8.5 on Windows 7 x64 and a MakerFocus ESP-12N (nodeMCU) from Amazon. I get “Device establishing new connection…” fairly frequently. Not sure if this is normal or not. The device is about 20 feet from the router andI’m pretty sure it gets  
strong signal. Here is a sample of the device connection log:

04/30/2018 08:15:44   
04/30/2018 01:58:09 212 0 Keepalive Timeout  
04/30/2018 01:50:08   
04/30/2018 01:50:08 1645 0 Device establishing new connection, closing previous connection  
04/30/2018 00:51:06   
04/30/2018 00:51:06 4850 0 Device establishing new connection, closing previous connection  
04/29/2018 21:57:46   
04/29/2018 21:57:46 2126 0 Device establishing new connection, closing previous connection  
04/29/2018 20:41:41   
04/29/2018 20:41:41 474 0 Device establishing new connection, closing previous connection  
04/29/2018 20:24:35   
04/29/2018 20:24:35 3411 0 Device establishing new connection, closing previous connection  
04/29/2018 18:22:39   
04/29/2018 18:22:39 1051 0 Device establishing new connection, closing previous connection  
04/29/2018 17:44:57   
04/29/2018 17:44:57 255 0 Device establishing new connection, closing previous connection  
04/29/2018 17:35:37   
04/29/2018 17:35:37 582 0 Device establishing new connection, closing previous connection  
04/29/2018 17:14:36   
04/29/2018 17:14:36 2965 0 Device establishing new connection, closing previous connection  
04/29/2018 15:28:32   
04/29/2018 15:28:32 635 0 Device establishing new connection, closing previous connection  
04/29/2018 15:05:40   
04/29/2018 15:05:40 794 0 Device establishing new connection, closing previous connection  
04/29/2018 14:37

---

<div class="post-metadata">

**Author:** ![Leo\_Bach1](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Leo\_Bach1](https://forums.losant.com/u/Leo_Bach1)\
**Post date:** [December 10, 2019, 8:43pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/10 "2019-12-10T20:43:00Z")

</div>

I am also having this issue with the Losant MQTT Broker.  
Did you ever get a resolution for this issue?

---

<div class="post-metadata">

**Author:** ![Leo\_Bach1](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@Leo\_Bach1](https://forums.losant.com/u/Leo_Bach1)\
**Post date:** [December 10, 2019, 8:43pm UTC](https://forums.losant.com/t/solved-getting-timeouts-to-losant-but-not-other-mqtt-brokers/622/11 "2019-12-10T20:43:50Z")

</div>

Losant MQTT Broker is giving me the same issue.  
Has anyone discovered a resolution for this?
