Giter VIP home page Giter VIP logo

Comments (31)

martin-ger avatar martin-ger commented on July 20, 2024 2

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.

d-a-v avatar d-a-v commented on July 20, 2024 2

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.

martin-ger avatar martin-ger commented on July 20, 2024

Are you using the ESP as AP? There is a defaulf of max 4 connected STAs.

from umqttbroker.

chiu-sg avatar chiu-sg commented on July 20, 2024

I'm running the ESP on STA mode. It is connected to a Wifi network.

from umqttbroker.

martin-ger avatar martin-ger commented on July 20, 2024

Okay, I remember, there is another limit. Use:

extern "C" {
  #include "espconn.h"
}

and
espconn_tcp_set_max_con(8);

esp8266/Arduino#3185

from umqttbroker.

chiu-sg avatar chiu-sg commented on July 20, 2024

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.

chiu-sg avatar chiu-sg commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

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.

RudyFiero avatar RudyFiero commented on July 20, 2024

@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.

MunteanuE avatar MunteanuE commented on July 20, 2024

@RudyFiero The file is

defaults.h

line 28

#define PROTOCOL_NAMEv311

I changed into

#define PROTOCOL_NAMEv31

from umqttbroker.

RudyFiero avatar RudyFiero commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

I tried also to increase the number of clients as you mentioned but with no effect

from umqttbroker.

MunteanuE avatar MunteanuE commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

@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.

martin-ger avatar martin-ger commented on July 20, 2024

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:

  1. Do you use the latest version of the lib?
  2. Do you have the same setup (external AP, one ESP connected to it running the uMQTTBroker)?
  3. 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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

RudyFiero avatar RudyFiero commented on July 20, 2024

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.

uBroker.zip

from umqttbroker.

martin-ger avatar martin-ger commented on July 20, 2024

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.

martin-ger avatar martin-ger commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

Hello @martin-ger ! Sorry for late answer but I was into some chores.
The answer for you question are:

  1. Yes;
  2. Yes;
  3. 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.

MunteanuE avatar MunteanuE commented on July 20, 2024

Here is the log file for one client without publishing, maybe it will be helpful
broker.log
.

from umqttbroker.

martin-ger avatar martin-ger commented on July 20, 2024

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.

MunteanuE avatar MunteanuE commented on July 20, 2024

Yes, it works like a charm with lwip 1.4 !
Thank you @martin-ger !

from umqttbroker.

martin-ger avatar martin-ger commented on July 20, 2024

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.

RudyFiero avatar RudyFiero commented on July 20, 2024

An ESP32 version would be fantastic!

from umqttbroker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.