Comments (9)
Most likely there is some null pointer exception when calling disconnect
while not beeing connected. This should be an easy fix in the library.
But the difference between the mega2560 and the esp8266 is weird, since the same code is executed on both platforms. Maybe we can check this again when the issue has been fixed. I'll work on this as soon as I'm back.
from arduino-mqtt.
I fixed a bug that might have caused a crash when disconnecting without having any previous connection. Can you give the new v2.1.0
version a try?
from arduino-mqtt.
void mqConnect() {
uint8_t loops = 0;
toggle (24, HIGH);
mq.setWill("node/" MQTT_CLIENTID "/status", "0", true, 0); // ... retained, QoS
while (!mq.connect(MQTT_CLIENTID, MQTT_USERNAME, MQTT_KEY)) {
Serial.print('.');
if (++loops >= 2) {
toggle (24, LOW);
return;
}
delay(400);
//mq.disconnect();
}
toggle (24, LOW);
Serial.print(F("\nConnected to mqtt-broker\n"));
mq.subscribe("node/#");
Tested on v2.1.4. On Mega2560 it still does not reconnect after broker has been offline for a while. (code above). If the broker is offline when Arduino boots up, Mega2560 has no problem connecting to the broker. If I uncomment mq.disconnect();
it works.
Other info:
-ESP8266 now sometimes 'hangs' after I disconnect from broker, use the WiFiClientSecure
for another connection and then reconnects to the broker again. They hangs forever, so I physically have to disconnect power to them. The built in watchdog fails. This did not happen on v2.1.3 and earlier.
-One ESP8266 sent information very seldom, often forcing the library to PINGRREQ
. This did not work when the client had been online for like 8 hours or more in previous versions. Instead the client was forced offline and then immediately reconnected. This is OK in v2.1.4.
from arduino-mqtt.
Hello!
I'm working on Genuino MKR1000 (SAMD21 + ATWINC1500 WiFi module), I'm using connect and publish functions as described in the example.
If I stop/start MQTT broker (Mosquitto) the client is able to recconnects to the broker without problems but often, after some publish commands, the client looses the connection to the broker and it is not able to recover this state, on the server I've got this error:
Client <unknown> has exceeded timeout, disconnecting.
1508254942: Socket error on client <unknown>, disconnecting.
When the program is working correctly all messages in Mosquito log are identified with the correct client id; in this case I have client id. (I don't have other clients running).
from arduino-mqtt.
Hi all, I just pushed some commits that may fix the metioned problem (check the git history for what has been changed). It would be awesome if you could rerun your tests with master branch of the library before I release a new version
from arduino-mqtt.
I just released v2.2.0 (might take some time to appear in the library manager) that fixes more related issues. Can you check again?
from arduino-mqtt.
@256dpi I have the same issue using the latest version (v2.2.0).
I use 800L GPRS modem with a ClientInterface
compatible interface (a library I have built).
Whenever a timeout disconnection happens, it doesn't reconnect.
1508819521: Client <IMEI> has exceeded timeout, disconnecting.
1508819521: Socket error on client <IMEI>, disconnecting.
It run for almost 38 hours without a glitch (thanks for the amazing library).
Any idea where to look into?
Here is the code I use:
void setup() {
mqtt.begin(MQTT_SERVER, client);
mqtt.setOptions(60, false, 2500);
mqtt.onMessage(messageReceived);
mqtt_subscribe();
}
void loop() {
mqtt.loop();
if(!mqtt.connected()) {
mqtt_subscribe();
}
....
}
bool mqtt_subscribe() {
if (!mqtt.connected()) mqtt_connect();
mqtt.subscribe("topic/p/" + IMEI, MQTT_QOS);
mqtt_event_subscribe(); # sending events as soon as the device subscribes
return true;
}
bool mqtt_connect() {
if (!mqtt.connected()) {
Serial.print("\nConnecting to MQTT server...");
while (!mqtt.connect(IMEI.c_str(), MQTT_USER, MQTT_PASS)) {
Serial.print(".");
delay(500);
}
mqtt.setWill("topic/testament", IMEI.c_str());
Serial.print(" [OK]");
}
return true;
}
from arduino-mqtt.
Now, with my hardware and v2.2.0 runs without problems. Thanks!
from arduino-mqtt.
The first issue, that the code refuse to reconnect when the broker is online again is solved in v2.2.0. Good work!
Second issue with ESP rebooting if a disconnect() is issued while having no connection on ESP8266 also passed the test. No restarts.
Thanks!
from arduino-mqtt.
Related Issues (20)
- Unable to connect with Platform I/O [email protected] (Arduino Core v3.1) HOT 3
- Cant connect to broker when using esp8266 version 3.1.1 HOT 9
- publish --> Mark as Duplicate HOT 10
- Session Store HOT 1
- Can't get connect with AWS IoT Core HOT 2
- JWT as password HOT 1
- Mqtt bufferSize value cannot exceed 1024 * 43 otherwise with error "Guru Meditation Error" HOT 1
- Possibility to serialize messages directly to server? HOT 1
- Issue with latest lwmqtt and the separation of the header and the payload HOT 4
- MQTT reconnection when not disconnected. ESP8266 HOT 6
- Unreliable behaviour with reconnections HOT 3
- MQTT HOT 1
- Websockets support HOT 3
- MQTT SSL connection issue with QoS1 and QoS2 messages HOT 1
- DCU: cannot connect to local MQTT broker HOT 1
- This library uses some posix functions that are not provided for Uno R4 HOT 3
- Subscribe query HOT 1
- Release version `v2.5.1` different of master version HOT 1
- 0
- Error connect MQTT SSL/TLS with module CBU use platform libretiny
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-mqtt.