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


#1

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/ and this MQTT library 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?


#2

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 :wink:

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


#3

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 broker. That implies o me the code is fine. Is it possible there’s a difference between them?


#4

Hi @Evan_d_Entremont,

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?


#5

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


#6

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.


#7

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


#9

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