mlesniew / PicoMQTT

ESP MQTT client and broker library
GNU Lesser General Public License v3.0
219 stars 25 forks source link

What is the max number of connected clients? #37

Closed ehabtawfikelbwab closed 1 month ago

ehabtawfikelbwab commented 1 month ago

Hello Sir,

I'm using Esp32 as a broker and the clients are esp12f(esp8266) so how many clients can broker handle and any advice?

also how to set keepAlive time and socket_timeout time ?

Thank you!

mlesniew commented 1 month ago

The library itself does not limit the number of clients, it's only limited by the number of TCP sockets the board can handle. IIRC the ESP32 can handle 16 sockets, that would mean 15 clients (because the 16th is used by the server socket listening for connections).

For clients the two parameters you asked about can be specified as constructor parameters, here's the declaration: https://github.com/mlesniew/PicoMQTT/blob/49ad5cff55aa7d4937cea6151e97d572a0f6b702/src/PicoMQTT/client.h#L66

For servers the socket timeout can be set by changing the socket_timeout_millis instance variable, see: https://github.com/mlesniew/PicoMQTT/blob/49ad5cff55aa7d4937cea6151e97d572a0f6b702/src/PicoMQTT/server.h#L194C23-L194C44. It can be changed at any time, but the new value will only be applied to newly connected clients.

ehabtawfikelbwab commented 1 month ago

Okay , Thank you very much!

Can you suggest a mini cheap device can handle 30 mqtt clients without no problem ?

mlesniew commented 1 month ago

A broker running on Esp8266 should be able to handle around 30 connections. There will be little RAM for left for anything else in the sketch, but if you just need a broker, it could work.

I believe the esp32 socket limit is set purely in software, so perhaps it could be increased by tweaking some preprocessor defines.

Unfortunately esp8266 and esp32 are the only boards supported by this lib.

If you need something more powerful, then a raspberry pi zero running mosquitto would be a good alternative.

ehabtawfikelbwab commented 1 month ago

@mlesniew Okay , Thank you very much!