espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.44k stars 7.25k forks source link

ESP-NOW: allow maximum number of encrypted peers to be set at runtime (IDFGH-10447) #11697

Open anecdata opened 1 year ago

anecdata commented 1 year ago

The number of hardware keys for encryption is fixed. And the espnow and SoftAP share the same hardware keys. So this configuration will affect the maximum connection number of SoftAP. Maximum espnow encrypted peers number + maximum number of connections of SoftAP = Max hardware keys number.

link

Currently, CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM can be 0-17, but it is a build-time option, whereas the maximum number of connections of SoftAP is a runtime option, 0-10 presumably under the assumption of ESP-NOW's default 7.

Solution: have a runtime API for maximum espnow encrypted peers, so that with a given firmware, user code (e.g., MicroPython, CircuitPython) can configure both SoftAP and ESP-NOW encryption key counts at runtime as appropriate for their applications.

zhangyanjiaoesp commented 1 year ago

@anecdata I think it's enough to set the ESP-NOW encrypt num in the menuconfig for the customer's applications. Do you have any application scenarios where you need to change the encryption number of ESPNOW at any time?

anecdata commented 1 year ago

Do you have any application scenarios where you need to change the encryption number of ESPNOW at any time?

Yes. In the case of CircuitPython and MicroPython (and perhaps other environments), a single firmware build is used by most customers for each particular board. Those customers write their applications in Python and don't have access to menuconfig or the esp-idf build environment. Instead, the esp-idf APIs of interest get exposed to a Python library for those customers to use in their applications. Some of these customers may favor more Wi-Fi Access Point connections. Some of these customers may favor more than 7 ESP-NOW encrypted pairs. Some may not need either. Each customer has unique application requirements and needs the flexibility to implement features at runtime from the same build.

zhangyanjiaoesp commented 7 months ago

@anecdata Since we won't consider to add a new API, you can set a large number of encrypted peers in the menuconfig, and use an API at the application layer to limit the number that customers can set.

anecdata commented 6 months ago

But is it possible to set CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM = 17 at build time, and also allow the maximum of 15 stations for an AP at build time?

https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/wifi.html#ap-basic-configuration

The goal would be to support for the customer any values within the maximum ranges, as long as the sum of the two aren't more than the number of encryption keys: • encrypted ESP-NOW pairs: 0-17 • stations connecting to an AP: 0-15

For example, using the same build, one customer may want all 17 ESP-NOW encrypted pairs and 0 AP stations. A second customer may want all 15 AP stations and can live with <= 2 ESP-NOW encrypted pairs. A third customer may want 12 ESP-NOW encrypted pairs and a max of 5 AP stations.

zhangyanjiaoesp commented 6 months ago

ok, we will consider this.

anecdata commented 6 months ago

Thank you!