Comments (31)
Okay, got it! It's the lwip 2.0!
Installed the latest Arduino core and with default settings I get exactly the behavior you describe: block after five connections.
Switched back to "Lwip Variant 1.4 High Bandwidth" in the "Tools" menu - works!
So, I still do not understand, why it fails, but it seems to be an lwip 2.0 issue...
from umqttbroker.
Hi,
I just discovered this great library.
About lwip2 not working the reason is simple: this library historically uses espconn
which is an espressif derivative of lwIP's (obsolete) netconn
and lwip2 (port of lwIP-v2) does not support espconn.
Rewriting the network part using ESP8266WiFi
would add these benefits:
- use lwIP-v2 (more stable)
- allow SSL (thanks to BearSSL from WiFiClientSecure)
- allow more than 5 simultaneous connections
This is feasible but requires however some time because of the whole structure based on network events.
from umqttbroker.
Are you using the ESP as AP? There is a defaulf of max 4 connected STAs.
from umqttbroker.
I'm running the ESP on STA mode. It is connected to a Wifi network.
from umqttbroker.
Okay, I remember, there is another limit. Use:
extern "C" {
#include "espconn.h"
}
and
espconn_tcp_set_max_con(8);
from umqttbroker.
Thanks for your reply Martin.
I've tried adding the above codes into the program but it does not solve the issue. I've read more into the link you've provided above and I think the max connections only apply when the ESP is in AP mode?
I think the problem I am facing is related to proper closing of offline connections instead of max connections as with 0 live clients online, I am also not able to connect any new client to the broker if I've previously connected and disconnected 5 clients.
from umqttbroker.
Hi Martin, I've appended my log below:
#################
Starting MQTT broker
pm open,type:2 0
// CONNECTING 6 CLIENTS, ONLY 5 GOT CONNECTED
MQTT_ClientCon_connected_cb(): Client connected
MQTT: InitClientCon
MQTT_ClientCon_recv_cb(): 63 bytes of data received
MQTT: TCP: data received 63 bytes (State: 14)
MQTT: total_len: 63
MQTT: message_type: 1
MQTT: Connect received, message_len: 63
MQTT: Connect flags 2
MQTT: Keepalive 10
MQTT: Client id "de55ca0e-13dc-4d32-a7f9-d3f3baabcfb91524813283721"
MQTT: Server task activated - state 19
MQTT: Sending, type: 2, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_connected_cb(): Client connected
MQTT: InitClientCon
MQTT_ClientCon_recv_cb(): 63 bytes of data received
MQTT: TCP: data received 63 bytes (State: 14)
MQTT: total_len: 63
MQTT: message_type: 1
MQTT: Connect received, message_len: 63
MQTT: Connect flags 2
MQTT: Keepalive 10
MQTT: Client id "5af055b7-4265-4541-97ff-6c2908f4c05a1524813286414"
MQTT: Server task activated - state 19
MQTT: Sending, type: 2, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_connected_cb(): Client connected
MQTT: InitClientCon
MQTT_ClientCon_recv_cb(): 63 bytes of data received
MQTT: TCP: data received 63 bytes (State: 14)
MQTT: total_len: 63
MQTT: message_type: 1
MQTT: Connect received, message_len: 63
MQTT: Connect flags 2
MQTT: Keepalive 10
MQTT: Client id "6c0ac745-2d48-46f0-88b9-237ddb83e0471524813289611"
MQTT: Server task activated - state 19
MQTT: Sending, type: 2, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_connected_cb(): Client connected
MQTT: InitClientCon
MQTT_ClientCon_recv_cb(): 63 bytes of data received
MQTT: TCP: data received 63 bytes (State: 14)
MQTT: total_len: 63
MQTT: message_type: 1
MQTT: Connect received, message_len: 63
MQTT: Connect flags 2
MQTT: Keepalive 10
MQTT: Client id "70612d3b-9896-46b3-9730-bad9847271051524813292479"
MQTT: Server task activated - state 19
MQTT: Sending, type: 2, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_connected_cb(): Client connected
MQTT: InitClientCon
MQTT_ClientCon_recv_cb(): 63 bytes of data received
MQTT: TCP: data received 63 bytes (State: 14)
MQTT: total_len: 63
MQTT: message_type: 1
MQTT: Connect received, message_len: 63
MQTT: Connect flags 2
MQTT: Keepalive 10
MQTT: Client id "a83d8a8a-8a95-45f0-a71e-056cf67e922e1524813295274"
MQTT: Server task activated - state 19
MQTT: Sending, type: 2, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
MQTT_ClientCon_recv_cb(): 2 bytes of data received
MQTT: TCP: data received 2 bytes (State: 19)
MQTT: total_len: 2
MQTT: message_type: 12
MQTT: receive MQTT_MSG_TYPE_PINGREQ
MQTT: Server task activated - state 19
MQTT: Sending, type: 13, id: 0000
MQTT_ClientCon_sent_cb(): Data sent
// DISCONNECTED 5 CLIENTS
MQTT: Connection timeout 30s
MQTT: ServerDisconnect
MQTT: DeleteClientCon
MQTT: Server task activated - state 6
MQTT: Disconnect
MQTT: Connection timeout 30s
MQTT: ServerDisconnect
MQTT: DeleteClientCon
MQTT: Server task activated - state 6
MQTT: Disconnect
MQTT: Connection timeout 30s
MQTT: ServerDisconnect
MQTT: DeleteClientCon
MQTT: Server task activated - state 6
MQTT: Disconnect
MQTT: Connection timeout 30s
MQTT: ServerDisconnect
MQTT: DeleteClientCon
MQTT: Server task activated - state 6
MQTT: Disconnect
MQTT: Connection timeout 30s
MQTT: ServerDisconnect
MQTT: DeleteClientCon
MQTT: Server task activated - state 6
MQTT: Disconnect
// TRIED TO CONNECT NEW CLIENT AND RECONNECT EXISTING CLIENT
-- no response from ESP
from umqttbroker.
Some issues - questions:
How do you close the connections?
What happens, if you wait some seconds (minutes)? This frees TCP connections in TIMEWAIT.
espconn_tcp_set_max_con(8); really applies to all kind of network connections - it is the number of max concurrent TCP connections.
from umqttbroker.
I confirm that there is a issue regarding the number of connections. The 6th attempt to connect to the broker fails and there is no any rejection log at all. espconn_tcp_set_max_con(8) doesn't help.... just try to connect and disconnect 6 times.
I tried also to clean up connection MQTT_server_cleanupClientCons periodically, but no results.
from umqttbroker.
Hmm, cannot reproduce this - at least not with mqtt-spy as client. I can connect/disconnect as often, as I like...
What client SW do you use? Any sketch you can share with me?
from umqttbroker.
The Sketch is brokerSample
The client is mqtt buddy And others. But usually many clients doesn’t work properly with Mqtt 3.1.1. So I configured the library to work with ver. 3.1. Thanks for fast response.
from umqttbroker.
@MunteanuE Can you tell me the specific lines that you are changing to try and get more than 6 connections. I have a number of ESP8266 that I can set up for this test, along with MQTT Spy.
from umqttbroker.
@RudyFiero The file is
defaults.h
line 28
#define PROTOCOL_NAMEv311
I changed into
#define PROTOCOL_NAMEv31
from umqttbroker.
Sorry but I wasn't clear. I meant what changes did you make to increase the number of clients? Is this all that you did?
extern "C" {
#include "espconn.h"
}
and
espconn_tcp_set_max_con(8);
I will not be able to start looking at this until tomorrow. I'm very interested in getting this working.
from umqttbroker.
I tried also to increase the number of clients as you mentioned but with no effect
from umqttbroker.
I had time to test the BrokerSample this evening with PROTOCOL_NAMEv311 and with espconn_tcp_set_max_con(8);
. The MQTT client was MQTT-spy.
The problem is persistent, the 6th attempt to reconnect to broker fails. You don't need 6 devices to check it, just connect and disconnect to broker 6 times.
I'm almost sure that the problem is with disconnecting of clients ( MQTT_ClientCon_discon_cb
or espconn_disconnect from void ICACHE_FLASH_ATTR MQTT_ServerTask(os_event_t * e)
)
from umqttbroker.
Did some research here:
Setup: an external AP, one ESP connected to it running the uMQTTBroker (or my esp_mqtt that uses exactly the same uMQTTBroker but has a lot more runtime debugging) and a Linux machine with mqtt-spy and an Android Phone with MQTT Buddy.
Results:
- no problems with connecting and disconnection one MQTT session with mqtt-spy as often as I want
- MQTT Buddy is difficult: looked into wireshark traces:
- when going to standby it holds the old session first, than tries to close it and
- when waking up again, it floods the ESP with strange disconnect packets
- this consumes all mem in the ESP and prevents establishment of a new session (no mem)
from umqttbroker.
An Android client that behaves absolutely well in contrast is the "MQTT Dashboard" - again no problem in connecting and reconnecting as often as I like...
Please make sure, you are using the latest version of uMQTTBroker. Versions before Jan 25. had a known problem in special disconnect sequences...
from umqttbroker.
@martin-ger I had the same problem with "MQTT Dashboard" - after pausing of the application (staying in background for a while) the connection to broker is dropped, so after resuming application it reconnects again. Try this 6 times. The short cut is just to kill the "MQTT Dashboard" and relaunch it again. May be you didn't reconnect properly (you haven't a lost connection).
from umqttbroker.
Yes, it also drops the connection - but it reconnects properly as often as I like (at lleast for me) and doesn't flood the ESP with nonsense packets....
Let me try to reproduce it - some questions:
- Do you use the latest version of the lib?
- Do you have the same setup (external AP, one ESP connected to it running the uMQTTBroker)?
- Could you try the esp_mqtt binaries with your setup? (https://github.com/martin-ger/esp_mqtt/tree/master/firmware - here you can see with "show mqtt" and "show stats" the currently connected clients and the mem status)
from umqttbroker.
Other guess - if case 3. shows a different (better) behaviour, maybe it is a problem with lwip2 in the new Arduino core? I still have installed an Arduino environment with the original 1.4 lwip...
There are several reports on a "disconnection/reconnection issue" in Arduino core 2.4 (claims to be fixed in version 2.4.2)
Will try to install a clean fresh Arduino environment the next days...
from umqttbroker.
One more question: does it help, if you wait some time (1 minute or so) before trying it again? Guess is: state TCP_TIMEWAIT...
from umqttbroker.
I reinstalled this library. I am running git from a few days ago. I am using MQTT Spy as the client. I monitored the traffic with Wireshark.
I reset the broker.
I connected with MQTT Spy. I subscribed to a test message. I published one test message. I then closed the MQTT Spy session connection.
I then did the same sequence of the above (below resetting the broker) successfully four more times.
On the sixth time it did not establish a connection. If it is of any help I have attached a zip file that contains the Wireshark file.
from umqttbroker.
Okay, thanks a lot. This helps a little bit to trace it down: in packets 92-97 is the first unsuccessful connect request. Here the ESP actively resets (RST) the connection after the successful three-way handshake. Do not understand why, but we are coming closer.
Could you try the same and reconnect some time later (a minute or so)?
from umqttbroker.
Does it change anything if you replace
espconn_disconnect(
with
espconn_abort(
in line mqtt_server.c:890
Somewhat brutal, but it might free the resources...
from umqttbroker.
Hello @martin-ger ! Sorry for late answer but I was into some chores.
The answer for you question are:
- Yes;
- Yes;
- No. Becuase it is thorough (have to find a binary uploader, the binary is configured for another STA or
it works in AP-mode, which will not reproduce the situation). But if I'll find a time window during weekend I'll try it.
Could you try the same and reconnect some time later (a minute or so)?
It doesn't connect even after 8 hours.
Does it change anything if you replace
espconn_disconnect(
with
espconn_abort(
in line mqtt_server.c:890
No, it doesn't
from umqttbroker.
Here is the log file for one client without publishing, maybe it will be helpful
broker.log
.
from umqttbroker.
Thanks - looked into it: exactly the sequence I would expect - ends with a proper "disconnect" in the main task for each connection. Afterwards the (new ?) lwip stack rejects any new connection...
Think, I will have to install the lastest Arduino an try to debug into the stack...
from umqttbroker.
Yes, it works like a charm with lwip 1.4 !
Thank you @martin-ger !
from umqttbroker.
Just saw that - yes rewriting it without espconn is a major effort. I probably won't do that. An if so, I would probably go directly for the ESP32 as is costs only a little bit more and has enough memory for a broker.
from umqttbroker.
An ESP32 version would be fantastic!
from umqttbroker.
Related Issues (20)
- disconnect and reconnect 6-10 time,the broker will cant't be connected HOT 1
- Client count HOT 8
- How to restart the broker?
- Ignored espconn_send() return (error) value.
- Broker Crashing when wifi disconnects HOT 2
- Accessing via mosquitto_sub/pub. How? HOT 1
- Broker doesn't accept new connections after 24h running? HOT 4
- Locally published topics do not appear to retain
- Compiling Error HOT 1
- ESP32 Port? HOT 1
- CRASH BROKER ((( WHY ?
- Ip address MQTT broker
- Compiling error using uMQTTBroker HOT 1
- Partial message / disconnections HOT 1
- Connection problem
- problem with using lwip:v2
- mqtt no user and pass HOT 1
- Broker cannot be connected after client disconnect
- Cannot send HTTPClient POST with MQTT
- Using ESP8266 as MQTT broker and datalogger HOT 5
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 umqttbroker.