Skip to content

Commit 444a622

Browse files
Merge branch 'espressif:master' into master
2 parents 226230f + 21640ac commit 444a622

24 files changed

+195
-151
lines changed

.github/workflows/publishsizes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
path: ./artifacts/sizes-report/pr_num.txt
6767

6868
- name: Report results
69-
uses: P-R-O-C-H-Y/report-size-deltas@2043188c68f483a7b50527c4eacf609d05bb67a5 # sizes_v2
69+
uses: P-R-O-C-H-Y/report-size-deltas@bea91d2c99ca80c88a883b39b1c4012f00ec3d09 # sizes_v2
7070
with:
7171
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
7272
github-token: ${{ env.GITHUB_TOKEN }}

cores/esp32/esp32-hal-spi.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,15 @@ struct spi_struct_t {
7979

8080
#if CONFIG_IDF_TARGET_ESP32S2
8181
// ESP32S2
82-
#define SPI_COUNT (3)
82+
#define SPI_COUNT (2)
8383

84-
#define SPI_CLK_IDX(p) ((p == 0) ? SPICLK_OUT_MUX_IDX : ((p == 1) ? FSPICLK_OUT_MUX_IDX : ((p == 2) ? SPI3_CLK_OUT_MUX_IDX : 0)))
85-
#define SPI_MISO_IDX(p) ((p == 0) ? SPIQ_OUT_IDX : ((p == 1) ? FSPIQ_OUT_IDX : ((p == 2) ? SPI3_Q_OUT_IDX : 0)))
86-
#define SPI_MOSI_IDX(p) ((p == 0) ? SPID_IN_IDX : ((p == 1) ? FSPID_IN_IDX : ((p == 2) ? SPI3_D_IN_IDX : 0)))
84+
#define SPI_CLK_IDX(p) ((p == 0) ? FSPICLK_OUT_MUX_IDX : ((p == 1) ? SPI3_CLK_OUT_MUX_IDX : 0))
85+
#define SPI_MISO_IDX(p) ((p == 0) ? FSPIQ_OUT_IDX : ((p == 1) ? SPI3_Q_OUT_IDX : 0))
86+
#define SPI_MOSI_IDX(p) ((p == 0) ? FSPID_IN_IDX : ((p == 1) ? SPI3_D_IN_IDX : 0))
8787

88-
#define SPI_SPI_SS_IDX(n) ((n == 0) ? SPICS0_OUT_IDX : ((n == 1) ? SPICS1_OUT_IDX : 0))
89-
#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : SPI3_CS0_OUT_IDX)))
90-
#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : FSPICS0_OUT_IDX)))
91-
#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_SPI_SS_IDX(n) : ((p == 1) ? SPI_SPI_SS_IDX(n) : ((p == 2) ? SPI_HSPI_SS_IDX(n) : 0)))
88+
#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : 0)))
89+
#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : 0)))
90+
#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0))
9291

9392
#elif CONFIG_IDF_TARGET_ESP32S3
9493
// ESP32S3
@@ -98,8 +97,8 @@ struct spi_struct_t {
9897
#define SPI_MISO_IDX(p) ((p == 0) ? FSPIQ_OUT_IDX : ((p == 1) ? SPI3_Q_OUT_IDX : 0))
9998
#define SPI_MOSI_IDX(p) ((p == 0) ? FSPID_IN_IDX : ((p == 1) ? SPI3_D_IN_IDX : 0))
10099

101-
#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : 0))
102-
#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : 0))
100+
#define SPI_HSPI_SS_IDX(n) ((n == 0) ? SPI3_CS0_OUT_IDX : ((n == 1) ? SPI3_CS1_OUT_IDX : ((n == 2) ? SPI3_CS2_OUT_IDX : 0)))
101+
#define SPI_FSPI_SS_IDX(n) ((n == 0) ? FSPICS0_OUT_IDX : ((n == 1) ? FSPICS1_OUT_IDX : ((n == 2) ? FSPICS2_OUT_IDX : 0)))
103102
#define SPI_SS_IDX(p, n) ((p == 0) ? SPI_FSPI_SS_IDX(n) : ((p == 1) ? SPI_HSPI_SS_IDX(n) : 0))
104103

105104
#elif CONFIG_IDF_TARGET_ESP32P4
@@ -151,11 +150,7 @@ struct spi_struct_t {
151150
#define SPI_MUTEX_UNLOCK()
152151
// clang-format off
153152
static spi_t _spi_bus_array[] = {
154-
#if CONFIG_IDF_TARGET_ESP32S2
155-
{(volatile spi_dev_t *)(DR_REG_SPI1_BASE), 0, -1, -1, -1, -1, false},
156-
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 1, -1, -1, -1, -1, false},
157-
{(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 2, -1, -1, -1, -1, false}
158-
#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4
153+
#if CONFIG_IDF_TARGET_ESP32S2 ||CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4
159154
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), 0, -1, -1, -1, -1, false},
160155
{(volatile spi_dev_t *)(DR_REG_SPI3_BASE), 1, -1, -1, -1, -1, false}
161156
#elif CONFIG_IDF_TARGET_ESP32C2
@@ -179,11 +174,7 @@ static spi_t _spi_bus_array[] = {
179174
#define SPI_MUTEX_UNLOCK() xSemaphoreGive(spi->lock)
180175

181176
static spi_t _spi_bus_array[] = {
182-
#if CONFIG_IDF_TARGET_ESP32S2
183-
{(volatile spi_dev_t *)(DR_REG_SPI1_BASE), NULL, 0, -1, -1, -1, -1, false},
184-
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 1, -1, -1, -1, -1, false},
185-
{(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 2, -1, -1, -1, -1, false}
186-
#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4
177+
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4
187178
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false}, {(volatile spi_dev_t *)(DR_REG_SPI3_BASE), NULL, 1, -1, -1, -1, -1, false}
188179
#elif CONFIG_IDF_TARGET_ESP32C2
189180
{(volatile spi_dev_t *)(DR_REG_SPI2_BASE), NULL, 0, -1, -1, -1, -1, false}
@@ -621,6 +612,7 @@ void spiStopBus(spi_t *spi) {
621612

622613
spi_t *spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) {
623614
if (spi_num >= SPI_COUNT) {
615+
log_e("SPI bus index %d is out of range", spi_num);
624616
return NULL;
625617
}
626618

cores/esp32/esp32-hal-spi.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,13 @@ extern "C" {
2727
#include <stdbool.h>
2828

2929
#define SPI_HAS_TRANSACTION
30-
31-
#ifdef CONFIG_IDF_TARGET_ESP32S2
32-
#define FSPI 1 //SPI 1 bus. ESP32S2: for external memory only (can use the same data lines but different SS)
33-
#define HSPI 2 //SPI 2 bus. ESP32S2: external memory or device - it can be matrixed to any pins
34-
#define SPI2 2 // Another name for ESP32S2 SPI 2
35-
#define SPI3 3 //SPI 3 bus. ESP32S2: device only - it can be matrixed to any pins
36-
#elif CONFIG_IDF_TARGET_ESP32
30+
#ifdef CONFIG_IDF_TARGET_ESP32
3731
#define FSPI 1 //SPI 1 bus attached to the flash (can use the same data lines but different SS)
3832
#define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins
3933
#define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins
4034
#else
41-
#define FSPI 0 // ESP32C2, C3, C6, H2, S3, P4 - SPI 2 bus
42-
#define HSPI 1 // ESP32S3, P4 - SPI 3 bus
35+
#define FSPI 0 // ESP32C2, C3, C6, H2, S2, S3, P4 - SPI 2 bus
36+
#define HSPI 1 // ESP32S2, S3, P4 - SPI 3 bus
4337
#endif
4438

4539
// This defines are not representing the real Divider of the ESP32

cores/esp32/esp32-hal-uart.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ static bool _uartTrySetIomuxPin(uart_port_t uart_num, int io_num, uint32_t idx)
305305
}
306306

307307
// Assign the correct function to the GPIO.
308-
assert(upin->iomux_func != -1);
308+
if (upin->iomux_func == -1) {
309+
log_e("IO#%d has bad IOMUX internal information. Switching to GPIO Matrix UART function.", io_num);
310+
return false;
311+
}
309312
if (uart_num < SOC_UART_HP_NUM) {
310313
gpio_iomux_out(io_num, upin->iomux_func, false);
311314
// If the pin is input, we also have to redirect the signal, in order to bypass the GPIO matrix.

docs/conf_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
from esp_docs.conf_docs import * # noqa: F403,F401
44

5+
# Used for substituting variables in the documentation
6+
rst_prolog = """
7+
.. |version| replace:: 3.2.0
8+
.. |idf_version| replace:: 5.4
9+
"""
10+
511
languages = ["en"]
612

713
# idf_targets = [
@@ -27,6 +33,7 @@
2733
extensions += [ # noqa: F405
2834
"sphinx_copybutton",
2935
"sphinx_tabs.tabs",
36+
"sphinx_substitution_extensions", # For allowing substitutions inside code blocks
3037
"esp_docs.esp_extensions.dummy_build_system",
3138
]
3239

docs/en/contributing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Documentation
222222
-------------
223223

224224
If you are contributing to the documentation, please follow the instructions described in the
225-
`documentation guidelines <guides/docs_contributing>`_ to properly format and test your changes.
225+
`documentation guidelines <guides/docs_contributing.html>`_ to properly format and test your changes.
226226

227227
Testing and CI
228228
--------------
@@ -435,7 +435,7 @@ Documentation Checks
435435
^^^^^^^^^^^^^^^^^^^^
436436

437437
The CI also checks the documentation for any compilation errors. This is important to ensure that the documentation layout is not broken.
438-
To build the documentation locally, please refer to the `documentation guidelines <guides/docs_contributing>`_.
438+
To build the documentation locally, please refer to the `documentation guidelines <guides/docs_contributing.html>`_.
439439

440440
Code Style Checks
441441
^^^^^^^^^^^^^^^^^

docs/en/esp-idf_component.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ For a simplified method, see `Installing using Boards Manager <https://docs.espr
1414
If you plan to use these modified settings multiple times, for different projects and targets, you can recompile the Arduino core with the new settings using the Arduino Static Library Builder.
1515
For more information, see the `Lib Builder documentation <lib_builder.html>`_.
1616

17-
.. note:: Latest Arduino Core ESP32 version (3.0.X) is now compatible with `ESP-IDF v5.1 <https://github.com/espressif/esp-idf/tree/release/v5.1>`_. Please consider this compatibility when using Arduino as a component in ESP-IDF.
17+
.. note:: Latest Arduino Core ESP32 version (|version|) is now compatible with ESP-IDF v\ |idf_version|\ . Please consider this compatibility when using Arduino as a component in ESP-IDF.
1818

19-
For easiest use of Arduino framework as a ESP-IDF component, you can use the `IDF Component Manager <https://docs.espressif.com/projects/esp-idf/en/v5.1.4/esp32/api-guides/tools/idf-component-manager.html>`_ to add the Arduino component to your project.
19+
For easiest use of Arduino framework as a ESP-IDF component, you can use the `IDF Component Manager <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html>`_ to add the Arduino component to your project.
2020
This will automatically clone the repository and its submodules. You can find the Arduino component in the `ESP Registry <https://components.espressif.com/components/espressif/arduino-esp32>`_ together with dependencies list and examples.
2121

2222
Installation
@@ -32,14 +32,16 @@ Installing using IDF Component Manager
3232
To add the Arduino component to your project using the IDF Component Manager, run the following command in your project directory:
3333

3434
.. code-block:: bash
35+
:substitutions:
3536
36-
idf.py add-dependency "espressif/arduino-esp32^3.0.2"
37+
idf.py add-dependency "espressif/arduino-esp32^|version|"
3738
3839
Or you can start a new project from a template with the Arduino component:
3940

4041
.. code-block:: bash
42+
:substitutions:
4143
42-
idf.py create-project-from-example "espressif/arduino-esp32^3.0.2:hello_world"
44+
idf.py create-project-from-example "espressif/arduino-esp32^|version|:hello_world"
4345
4446
Manual installation of Arduino framework
4547
****************************************

docs/en/guides/docs_contributing.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ Before starting your collaboration, you need to get the documentation source cod
4949
Requirements
5050
************
5151

52-
To properly work with the documentation, you need to install some packages in your system.
52+
To build the documentation properly, you need to install some packages in your system. Note that depending on
53+
your system, you may need to use a virtual environment to install the packages.
5354

5455
.. code-block::
5556
56-
pip install -U Sphinx
5757
pip install -r requirements.txt
5858
5959
The requirements file is under the ``docs`` folder.
@@ -62,17 +62,14 @@ Using Visual Studio Code
6262
************************
6363

6464
If you are using the Visual Studio Code, you can install some extensions to help you while writing documentation.
65+
For reStructuredText, you can install the `reStructuredText Pack <https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack>`_ extension.
6566

66-
`reStructuredText Pack <https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack>`_
67-
68-
We also recommend you install to grammar check extension to help you to review English grammar.
69-
70-
`Grammarly <https://marketplace.visualstudio.com/items?itemName=znck.grammarly>`_
67+
We also recommend you to install some grammar check extension to help you to review English grammar.
7168

7269
Building
7370
********
7471

75-
To build the documentation and generate the HTML files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `_build/en/generic/html` folder.
72+
To build the documentation and generate the HTML files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the ``_build/en/generic/html`` folder.
7673

7774
.. code-block::
7875

docs/en/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Welcome to ESP32 Arduino Core's documentation
33
#############################################
44

55
Here you will find all the relevant information about the project.
6+
This documentation is valid for the Arduino Core for ESP32 version |version| based on ESP-IDF |idf_version|.
67

78
.. note::
89
This is a work in progress documentation and we will appreciate your help! We are looking for contributors!

docs/en/lib_builder.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ You have two options to run the Docker image to build the libraries. Manually or
293293
To run the Docker image manually, use the following command from the root of the ``arduino-esp32`` repository:
294294

295295
.. code-block:: bash
296+
:substitutions:
296297
297-
docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder:release-v5.1
298+
docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder:release-v|idf_version|
298299
299300
This will start the Lib Builder UI for compiling the libraries. The above command explained:
300301

@@ -304,7 +305,7 @@ This will start the Lib Builder UI for compiling the libraries. The above comman
304305
- ``-t`` Allocate a pseudo-TTY;
305306
- ``-e TERM=xterm-256color``: Optional. Sets the terminal type to ``xterm-256color`` to display colors correctly;
306307
- ``-v $PWD:/arduino-esp32``: Optional. Mounts the current folder at ``/arduino-esp32`` inside the container. If not provided, the container will not copy the compiled libraries to the host machine;
307-
- ``espressif/esp32-arduino-lib-builder:release-v5.1``: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag ``release-v5.1``.
308+
- :substitution-code:`espressif/esp32-arduino-lib-builder:release-v|idf_version|`: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag :substitution-code:`release-v|idf_version|`.
308309
The ``latest`` tag is implicitly added by Docker when no tag is specified. It is recommended to use a specific version tag to ensure reproducibility of the build process.
309310

310311
.. warning::
@@ -324,24 +325,27 @@ By default the docker container will run the user interface script. If you want
324325
For example, to run a terminal inside the container, you can run:
325326

326327
.. code-block:: bash
328+
:substitutions:
327329
328-
docker run -it espressif/esp32-arduino-lib-builder:release-v5.1 /bin/bash
330+
docker run -it espressif/esp32-arduino-lib-builder:release-v|idf_version| /bin/bash
329331
330332
Running the Docker image using the provided run script will depend on the host OS.
331333
Use the following command from the root of the ``arduino-esp32`` repository to execute the image in a Linux or macOS environment for
332-
the ``release-v5.1`` tag:
334+
the :substitution-code:`release-v|idf_version|` tag:
333335

334336
.. code-block:: bash
337+
:substitutions:
335338
336-
curl -LJO https://rg.gosu.cc/espressif/esp32-arduino-lib-builder/refs/heads/release/v5.1/tools/docker/run.sh
339+
curl -LJO https://rg.gosu.cc/espressif/esp32-arduino-lib-builder/refs/heads/release/v|idf_version|/tools/docker/run.sh
337340
chmod +x run.sh
338341
./run.sh $PWD
339342
340343
For Windows, use the following command in PowerShell from the root of the ``arduino-esp32`` repository:
341344

342345
.. code-block:: powershell
346+
:substitutions:
343347
344-
Invoke-WebRequest -Uri "https://rg.gosu.cc/espressif/esp32-arduino-lib-builder/refs/heads/release/v5.1/tools/docker/run.ps1" -OutFile "run.ps1"
348+
Invoke-WebRequest -Uri "https://rg.gosu.cc/espressif/esp32-arduino-lib-builder/refs/heads/release/v|idf_version|/tools/docker/run.ps1" -OutFile "run.ps1"
345349
.\run.ps1 $pwd
346350
347351
As the script is unsigned, you may need to change the execution policy of the current session before running the script.

docs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
sphinx==4.5.0
12
esp-docs>=1.4.0
23
sphinx-copybutton==0.5.0
34
sphinx-tabs==3.2.0
45
numpydoc==1.5.0
56
standard-imghdr==3.13.0
7+
Sphinx-Substitution-Extensions==2022.2.16

idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ dependencies:
105105
rules:
106106
- if: "target in [esp32s3]"
107107
espressif/esp_hosted:
108-
version: "^0.0.25"
108+
version: "^2.0.12"
109109
rules:
110110
- if: "target == esp32p4"
111111
espressif/esp_wifi_remote:
112-
version: "^0.4.1"
112+
version: "^0.13.0"
113113
rules:
114114
- if: "target == esp32p4"
115115
espressif/libsodium:

libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ESP_NOW_Broadcast_Master.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public:
5858
uint32_t msg_count = 0;
5959

6060
// Create a broadcast peer object
61-
ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL);
61+
ESP_NOW_Broadcast_Peer broadcast_peer(ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, nullptr);
6262

6363
/* Main */
6464

libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave/ESP_NOW_Broadcast_Slave.ino

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public:
5252
/* Global Variables */
5353

5454
// List of all the masters. It will be populated when a new master is registered
55-
std::vector<ESP_NOW_Peer_Class> masters;
55+
// Note: Using pointers instead of objects to prevent dangling pointers when the vector reallocates
56+
std::vector<ESP_NOW_Peer_Class *> masters;
5657

5758
/* Callbacks */
5859

@@ -62,13 +63,14 @@ void register_new_master(const esp_now_recv_info_t *info, const uint8_t *data, i
6263
Serial.printf("Unknown peer " MACSTR " sent a broadcast message\n", MAC2STR(info->src_addr));
6364
Serial.println("Registering the peer as a master");
6465

65-
ESP_NOW_Peer_Class new_master(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, NULL);
66-
67-
masters.push_back(new_master);
68-
if (!masters.back().add_peer()) {
66+
ESP_NOW_Peer_Class *new_master = new ESP_NOW_Peer_Class(info->src_addr, ESPNOW_WIFI_CHANNEL, WIFI_IF_STA, nullptr);
67+
if (!new_master->add_peer()) {
6968
Serial.println("Failed to register the new master");
69+
delete new_master;
7070
return;
7171
}
72+
masters.push_back(new_master);
73+
Serial.printf("Successfully registered master " MACSTR " (total masters: %zu)\n", MAC2STR(new_master->addr()), masters.size());
7274
} else {
7375
// The slave will only receive broadcast messages
7476
log_v("Received a unicast message from " MACSTR, MAC2STR(info->src_addr));
@@ -103,11 +105,23 @@ void setup() {
103105
}
104106

105107
// Register the new peer callback
106-
ESP_NOW.onNewPeer(register_new_master, NULL);
108+
ESP_NOW.onNewPeer(register_new_master, nullptr);
107109

108110
Serial.println("Setup complete. Waiting for a master to broadcast a message...");
109111
}
110112

111113
void loop() {
112-
delay(1000);
114+
// Print debug information every 10 seconds
115+
static unsigned long last_debug = 0;
116+
if (millis() - last_debug > 10000) {
117+
last_debug = millis();
118+
Serial.printf("Registered masters: %zu\n", masters.size());
119+
for (size_t i = 0; i < masters.size(); i++) {
120+
if (masters[i]) {
121+
Serial.printf(" Master %zu: " MACSTR "\n", i, MAC2STR(masters[i]->addr()));
122+
}
123+
}
124+
}
125+
126+
delay(100);
113127
}

libraries/ESP_NOW/examples/ESP_NOW_Network/ESP_NOW_Network.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public:
123123
}
124124

125125
bool send_message(const uint8_t *data, size_t len) {
126-
if (data == NULL || len == 0) {
126+
if (data == nullptr || len == 0) {
127127
log_e("Data to be sent is NULL or has a length of 0");
128128
return false;
129129
}
@@ -169,9 +169,12 @@ public:
169169

170170
/* Peers */
171171

172-
std::vector<ESP_NOW_Network_Peer *> peers; // Create a vector to store the peer pointers
173-
ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, NULL); // Register the broadcast peer (no encryption support for the broadcast address)
174-
ESP_NOW_Network_Peer *master_peer = nullptr; // Pointer to peer that is the master
172+
// Create a vector to store the peer pointers
173+
std::vector<ESP_NOW_Network_Peer *> peers;
174+
// Register the broadcast peer (no encryption support for the broadcast address)
175+
ESP_NOW_Network_Peer broadcast_peer(ESP_NOW.BROADCAST_ADDR, 0, nullptr);
176+
// Pointer to the peer that is the master
177+
ESP_NOW_Network_Peer *master_peer = nullptr;
175178

176179
/* Helper functions */
177180

@@ -279,7 +282,7 @@ void setup() {
279282
}
280283

281284
// Register the callback to be called when a new peer is found
282-
ESP_NOW.onNewPeer(register_new_peer, NULL);
285+
ESP_NOW.onNewPeer(register_new_peer, nullptr);
283286

284287
Serial.println("Setup complete. Broadcasting own priority to find the master...");
285288
memset(&new_msg, 0, sizeof(new_msg));

0 commit comments

Comments
 (0)