Description
Well, I'm trying to make a HAP device with the Espressif hap, Espressif arduino and Espressif idf.
The problem I experienced is:
- Default CONFIG_LWIP_MAX_SOCKETS is set to 10
- No lwip sources provided with arduino core
- Homekit opens a persistent connection to each client. So, in average family, there are 10-15 devices connected simultaneously. I tested with my own 6 and ran into this problem.
- I also use WebServer (which built on WiFiServer), and by default it consumes, as far as I remember, 5 sockets. But no matter, even without the WiFiServer it is a problem, because 7 connected HAP clients surely ain't enough for real purposes. So, in my case, with the default configuration and 6 connected hap clients, any access to the WiFiServer leads to
lwip_accept
fails with errno 23.
It's a bit strange, that Espressif products don't work together. Even more, the main esp32's advantage is the networking, but 10 sockets is just a joke in this sense.
Proposed fixes:
-
Include lwip sources, so any user could configure the required sockets amount and range (not default 1-16, but more reasonable 1-20 or maybe 1-30 as lwip has no such limit)
It would probably lead to the need to add the whole IDF sources, but I'm not sure -
Include different precompiled liblwip.a versions, like with 10 (current value), 16 (current menuconfig max value) and 20 or even 30 CONFIG_LWIP_MAX_SOCKETS
Maybe you could propose better, I don't know, sorry.
Activity
BbIKTOP commentedon Sep 24, 2021
Found also, that httpd_server performs an explicit check of this setting, so, it should be recompiled as well. Also, set the limit to 20, everything is working fine so far. It’s definitely needs to be changed
me-no-dev commentedon Sep 29, 2021
@SuGlider please check memory usage if that value changes to 16 as part of your memory investigations :)
me-no-dev commentedon Sep 29, 2021
@david-cermak mind giving your two cents? :)
BbIKTOP commentedon Sep 29, 2021
already did:
After some settlement period, with 20 sockets:
and with default 10 sockets
So, the difference is about 2kb per 10 sockets. Sorry, didn't test it with 16, but I suppose the result will be quite close to 20 ;)
SuGlider commentedon Sep 29, 2021
Ok. So this is the Heap with nothing running on the ESP32.
What about when the application opens and uses all those sockets?
BbIKTOP commentedon Sep 29, 2021
This is with esp-hap and webserver and 6 hap clients connected
BbIKTOP commentedon Sep 29, 2021
With 16 sockets after 6 minutes:
So, I suppose 20 is ok, but would require custom idf with redefined max value in the esp-idf/components/lwip/Kconfig
As the least thing to do, it would be good to set it to at least 16. 20 would be better, for sure, but I understand it is too much complicated to implement )))) So, please, make it at least 16.
Btw, 14 minutes uptime, 16 sockets max, the same app:
SuGlider commentedon Sep 29, 2021
Is this running on a ESP32WROVER with PSRAM, right?
Although it seems that himem allocation changes almost nothing, would it change heap allocation in a plain ESP32WROOM (no PSRAM)?
Can you test it as well, please?
BbIKTOP commentedon Sep 29, 2021
I have A LOT of psram allocations for my objects, like peripheral drivers, events, etc, it's really difficult to change everywhere, and I suppose it won't affect the result. As I have a pool allocator for psram and my objects use almost 1mb of it, I'd need to rewrite it to the standard alloc/free. I could try, if you insist, but really, do you think it matters? Arduino and idf both don't use psram, so its just me who does.
SuGlider commentedon Sep 29, 2021
Ok. Most probably nothing will really change. Some IDF 4.4 drivers allow to use PSRAM for buffers and queues, I but think this is disabled for Arduino.
All right, thus, your suggestion/request is to increase MAX SOCKETS in IDF KConfig for LWIP in Arduino for a next release, correct?
Arduino uses a set of IDF components precompiled into a set of libxxx.a which are built from IDF sdkconfig and KConfigs once a new Arduino version is released.
We could consider setting the number of sockets to 20 in LWIP KConfig and make it default in the precompiled library and its header files.
At this time we have people complaining about high heap allocation in new Arduino Core version 2.0.0. I'll have to check how to make room for all those changes and yet free some Heap to users.
An alternative option for you would be build your own library version with all the resources you need and replace the libxxx.a + header files set in your Arduino environment. Not sure if this is something you would like to do...
BbIKTOP commentedon Sep 29, 2021
Exactly. At least to 16, as it won't require any changes in the idf cfg. But 20 would be better, of course, it's a network device, isn't it?
SuGlider commentedon Sep 29, 2021
Ok. I'll include this request on the Heap allocation study I'm currently working.
Anyway, I guess that currently you are using a modified liblwip.a with a number sockets you need for your project, right?
BbIKTOP commentedon Sep 29, 2021
Yes, among with httpd libs, as httpd checks for CONFIG_LWIP_MAX_SOCKETS -3 and failed to start if this isn't satisfied: https://github.com/espressif/esp-idf/blob/3e370c4296247b349aa3b9a0076c05b9946d47dc/components/esp_http_server/src/httpd_main.c#L410
19 remaining items