uploaded 10 months ago
This package provides enhanced ESP-NOW functions which will be easy to integrate into product.

readme

# ESP-NOW Component

[![Component Registry](https://components.espressif.com/components/espressif/esp-now/badge.svg)](https://components.espressif.com/components/espressif/esp-now)

- [User Guide](https://github.com/espressif/esp-now/tree/master/User_Guide.md)

esp-now supports one-to-many and many-to-many device connection and control which can be used for the mass data transmission, like network config, firmware upgrade and debugging etc.

### Add component to your project

Please use the component manager command `add-dependency` to add the `esp-now` to your project's dependency, during the `CMake` step the component will be downloaded automatically.

```
idf.py add-dependency "espressif/esp-now=*"
```

## Example

Please use the component manager command `create-project-from-example` to create the project from example template.

```
idf.py create-project-from-example "espressif/esp-now=*:coin_cell_demo/bulb"
```

Then the example will be downloaded in current folder, you can check into it for build and flash.

> You can use this command to download other examples. Or you can download examples from esp-now repository: 
1. [coin_cell_demo/bulb](https://github.com/espressif/esp-now/tree/master/examples/coin_cell_demo/bulb)
2. [coin_cell_demo/switch](https://github.com/espressif/esp-now/tree/master/examples/coin_cell_demo/switch)
3. [control](https://github.com/espressif/esp-now/tree/master/examples/control)
4. [get-started](https://github.com/espressif/esp-now/tree/master/examples/get-started)
5. [ota](https://github.com/espressif/esp-now/tree/master/examples/ota)
6. [security](https://github.com/espressif/esp-now/tree/master/examples/security)
7. [solution](https://github.com/espressif/esp-now/tree/master/examples/solution)
8. [wireless_debug](https://github.com/espressif/esp-now/tree/master/examples/wireless_debug)

### Q&A

Q1. I encountered the following problems when using the package manager

```
  HINT: Please check manifest file of the following component(s): main

  ERROR: Because project depends on esp-now (2.*) which doesn't match any
  versions, version solving failed.
```

A1. For the examples downloaded by using this command, you need to comment out the override_path line in the main/idf_component.yml of each example.

Q2. I encountered the following problems when using the package manager

```
Executing action: create-project-from-example
CMakeLists.txt not found in project directory /home/username
```

A2. This is because an older version packege manager was used, please run `pip install -U idf-component-manager` in ESP-IDF environment to update.

changelog

# v2.3.0

Features:
- Increase wait ack config range and reduce wait ack duration for button.
- Use random IV at the end of the payload for gain a lot of security. [#40](https://github.com/espressif/esp-now/issues/40)
- Add option for enable/disable security on all components. [#71](https://github.com/espressif/esp-now/issues/71)
- Add sec event for application to get the result. [#73](https://github.com/espressif/esp-now/issues/73)

Fixed:
- Fix an issue for light sleep after backup the channel
- Fix an issue of missnamed. [#72](https://github.com/espressif/esp-now/issues/72)
- Update readme of miss actual path. [#76](https://github.com/espressif/esp-now/issues/76)

# v2.2.0

Features:
- Add an option to enable/disable responder forwarding.

Fixed:
- Fix the bug with bindlist cleanup when unbinding.
- Fix compile issue when enbale Anti-rollback option.
- Fix the bug that prevents sending clear data when security is enabled. [#63](https://github.com/espressif/esp-now/issues/63)
- Fix the bug where ESPNOW_INIT_CONFIG_DEFAULT does not match its declaration in C++. [#65](https://github.com/espressif/esp-now/issues/65)

# v2.1.1

Fix:
- Fix a bug of compile fail when use component registry

# v2.1.0

Features:
- Add light sleep configuration for the low power application.
- Add auto control the channel of ESP-NOW package sending, so application data transmission will have less time.

Fix:
- Fix a bug of init function which cause security sample can't work. [#60](https://github.com/espressif/esp-now/issues/60)

Examples:
- coin_cell_demo: Provides a low power solution to achieve wireless control between `SWITCH` and `BULB`.

# v2.0.0

This is the first release version for ESP-NOW component in Espressif Component Registry, more detailed descriptions about the project, please refer to [User_Guide](https://github.com/espressif/esp-now/tree/master/User_Guide.md).

Features:
- Control: Support the simple data communication between `initiator device` and `responder devices`.
- Provision: Support to do WiFi provision for multiple devices over ESP-NOW at the same time.
- Security: Support to encrypt the application level data by ECDH and AES128-CCM.
- Debug: Support to receive the running log from responder devices for debugging.
- Upgrade: Support to upgrade multiple devices over ESP-NOW at the same time.

readme of control example

                                        
                                        # Control Example

This example demonstrates the interaction process between the devices.

## Functionality

By using the `BOOT` button and `RGB LED` on the development boards, the initiator device sends the control commands and the responder devices change the LED status when receiving the control commands.

- Press the `BOOT` button to send control commands
- `RGB LED` will display the status after receiving the commands

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards (for example: ESP32-S2-Saola-1 or ESP32-C3-DevKitM-1) are required. You need to use the `BOOT` button and `RGB LED` on the development boards to demonstrate.

> Note: If you are using other boards, please modify the GPIOs accordingly.

<img src="../../docs/_static/en/esp32-s2-saola-1.png" width="550">

## How to Use the Example

### Binding

Double click the `BOOT` button on one device, this device will send the binding command. This device acts as the initiator. When other devices receive the binding command, the `RGB LED` on these devices will turn green, indicating that the devices have been successfully bound. Other devices act as the responders.

Output sample from the initiator:

```
I (60589) app_main: initiator bind press
```

Output sample from the responder:

```
I (40550) app_main: bind, uuid: 7c:df:a1:76:42:38, initiator_type: 513
```

### Control

Single click the `BOOT` button on the initiator device, this device will send the control command. When other devices receive the control command, the status of `RGB LED` (ON/OFF) will be controlled by the initiator device, and the color will be white.

> Note: The device can only control the bound devices, so it must be bound before control.

Output sample from the initiator:

```
I (111469) app_main: initiator send press
I (113279) app_main: initiator send press
I (116679) app_main: initiator send press
```

Output sample from the responder:

```
I (91430) app_main: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 1
I (93240) app_main: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 0
I (96640) app_main: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 1
```

### Unbind

Long press (more than 1.5 seconds) the `BOOT` button on the initiator device, this device will send the unbinding command. When other devices receive the unbinding command, the `RGB LED` on these devices will turn red, indicating that the devices have been unbound successfully.

Output sample from the initiator:

```
I (158709) app_main: initiator unbind press
```

Output sample from the responder:

```
I (138670) app_main: unbind, uuid: 7c:df:a1:76:42:38, initiator_type: 513
```

## Note

The roles of `initiator` and `responder` will be on the devices at the same time. When the user presses the `BOOT` button on one device, this device will act as the initiator to send commands to other devices. When other devices receive the commands, they will change the status of `RGB LED` to show that the command is handled.

                                    

readme of get-started example

                                        
                                        # Get Started Example

This example demonstrates how to use the ESP-NOW data to communicate.

## Functionality

One device receives data through the serial port and broadcasts it to all nodes through ESP-NOW data. The others will output the data through the serial port when receive the data.

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards are required.

## Configuration

Open the project configuration menu (`idf.py menuconfig`) to configure the packet retransmission counts and the UART port for data communication using (Refer to Kconfig file).

## Example Output

- Output sample from the receiving device:

<div align=center>
<img src="../../docs/_static/en/device_log.png" width="550">
<p> Packet receiving device log </p>
</div>

- Output sample from the sending device:

<div align=center>
<img src="../../docs/_static/en/serial_port.png" width="550">
<p> The log of the sending device </p>
</div>

                                    

readme of ota example

                                        
                                        # OTA Example

This example demonstrates how to use ESP-NOW OTA feature to help upgrading other devices.

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards are required, 1 works as initiator, and the others work as responders.

## Configuration

Open the project configuration menu (`idf.py menuconfig`) to configure the OTA mode and firmware upgrade URL (Refer to Kconfig file).

## How to Use the Example

<img src="../../docs/_static/en/OTA_workflow.png" width="550">

### Step 1: Connect to the router

Connect PC to the router, the `ESP-NOW OTA Initiator Device` will connect to this router later.

### Step 2: Run HTTP server

A built-in python HTTP server can be used as the server for the example upgrade.
Open a new terminal to run the HTTP server, and then run the below command to generate the firmware to be upgraded and start the server.
```shell
cd $IDF_PATH/examples/get-started/hello_world/
idf.py build
cd build
python -m http.server 8070
```

While the server is running, you may open this `http://localhost:8070/` in browse to check the build directory.

> Note:
	1. If there are firewall softwares that prevent any access to the port 8070, please grant the access while the example is running.

### Step 3: Build & Flash & Run the responders

Navigate to the OTA example directory, and type `idf.py menuconfig` to configure the OTA example.

Set following configurations under `Example Connection Configuration` Options:
* Set `WiFi SSID` of the Router (Access-Point).
* Set `WiFi Password` of the Router (Access-Point).

Set following configurations under `Example Configuration` Options:
* Set `ESP-NOW mode` to `Responder Mode`

When downloading the flash, it's recommend to use `erase_flash` to erase the entire flash memory (all the remaining data in ota_data partition will be deleted as well) for the first time, and then write the followings via a serial port:

```shell
idf.py erase_flash flash
```

When the example on the responder device starts up, it will:

1. Connect to the AP with configured SSID and password.
2. Create OTA task to receive OTA frames.
3. Response with OTA information if receives OTA request frame.
4. Write the image to flash if receives OTA image data. If receives all the image, configure the next boot from this image.
5. If reboot the device, it will run to the new image.

### Step 4: Build & Flash & Run the initiator

Navigate to the OTA example directory, and type `idf.py menuconfig` to configure the OTA example.

Set following configurations under `Example Connection Configuration` Options:
* Set `WiFi SSID` of the Router (Access-Point).
* Set `WiFi Password` of the Router (Access-Point).

Set following configurations under `Example Configuration` Options:
* Set `ESP-NOW mode` to `Initiator Mode`
* Set firmware upgrade URL
  
```
http://<host-ip-address>:<host-port>/<firmware-image-filename>

for e.g,
http://192.168.0.3:8070/hello-world.bin
```

When downloading the flash, it's recommend to use `erase_flash` to erase the entire flash memory (all the remaining data in ota_data partition will be deleted as well) for the first time, and then write the followings via a serial port:

```shell
idf.py erase_flash flash
```

When the example on the initiator device starts up, it will:

1. Connect to the AP with configured SSID and password.
2. Connect to the HTTP server and download the new image.
3. Scan OTA responders and get responder list.
4. Send the new image in ESP-NOW data to responders until all responders have finished upgrading or sending times reach CONFIG_ESPNOW_OTA_RETRY_COUNT.

## Example Output
Note that the output, in particular the order of the output, may vary depending on the environment.

Console output of the initiator:
```
I (4460) example_connect: Connected to example_connect: sta
I (4466) example_connect: - IPv4 address: 192.168.1.100
I (4472) example_connect: - IPv6 address: fe80:0000:0000:0000:7edf:a1ff:fe76:4238, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (4484) wifi:Set ps type: 0

I (4487) ESPNOW: espnow [version: 1.0] init
I (4491) app_main: Open HTTP connection: http://192.168.1.106:8070/hello-world.bin
I (6164) app_main: The service download firmware is complete, Spend time: 1s
I (6165) esp_image: segment 0: paddr=001f0020 vaddr=3c020020 size=05f48h ( 24392) map
I (6172) esp_image: segment 1: paddr=001f5f70 vaddr=3fc89c00 size=01a84h (  6788) 
I (6179) esp_image: segment 2: paddr=001f79fc vaddr=40380000 size=0861ch ( 34332) 
I (6189) esp_image: segment 3: paddr=00200020 vaddr=42000020 size=1516ch ( 86380) map
I (6203) esp_image: segment 4: paddr=00215194 vaddr=4038861c size=014b0h (  5296) 
I (6204) esp_image: segment 5: paddr=0021664c vaddr=50000000 size=00010h (    16) 
W (8321) app_main: espnow wait ota num: 1
I (8321) espnow_ota_initatior: [espnow_ota_initiator_send, 301]: total_size: 157312, packet_num: 697
I (9180) espnow_ota_initatior: count: 0, Upgrade_initiator_send, requested_num: 1, unfinished_num: 1, successed_num: 0
I (11260) espnow_ota_initatior: count: 1, Upgrade_initiator_send, requested_num: 1, unfinished_num: 1, successed_num: 0
I (11412) app_main: Firmware is sent to the device to complete, Spend time: 5s
I (11412) app_main: Devices upgrade completed, successed_num: 1, unfinished_num: 0

```
Console output of the responder:
```
I (4473) example_connect: Connected to example_connect: sta
I (4479) example_connect: - IPv4 address: 192.168.1.102
I (4485) example_connect: - IPv6 address: fe80:0000:0000:0000:7edf:a1ff:fe86:d824, type: ESP_IP6_ADDR_IS_LINK_LOCAL
I (4496) wifi:Set ps type: 0

I (4499) ESPNOW: espnow [version: 1.0] init
I (425039) espnow_ota_responder: The device starts to upgrade
I (427993) espnow_ota_responder: Write total_size: 157312, written_size: 157312, spend time: 2s
I (427994) espnow_ota_responder: Running firmware version: v1.0-beta1-10-gbb5d5ec-dirty
I (428000) espnow_ota_responder: Running firmware version: v4.3.1-dirty
I (428007) esp_image: segment 0: paddr=001f0020 vaddr=3c020020 size=05f48h ( 24392) map
I (428018) esp_image: segment 1: paddr=001f5f70 vaddr=3fc89c00 size=01a84h (  6788) 
I (428025) esp_image: segment 2: paddr=001f79fc vaddr=40380000 size=0861ch ( 34332) 
I (428036) esp_image: segment 3: paddr=00200020 vaddr=42000020 size=1516ch ( 86380) map
I (428050) esp_image: segment 4: paddr=00215194 vaddr=4038861c size=014b0h (  5296) 
I (428051) esp_image: segment 5: paddr=0021664c vaddr=50000000 size=00010h (    16) 
```
When responder device reboots, it will output: 
```
Hello world!
This is esp32c3 chip with 1 CPU core(s), WiFi/BLE, silicon revision 3, 4MB external flash
Minimum free heap size: 328644 bytes
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
```
## Troubleshooting

* Check your PC can ping the ESP32 at its IP, and that the IP, AP and other configuration settings are correct in menuconfig.
* Check if any firewall software is preventing incoming connections on the PC.
* Check whether you can get firmware (default hello-world.bin), by checking the output of following command:

 ```
 curl -v http:// <host-ip-address>:<host-port> / <firmware-image-filename>
 ```

* If you have another PC or a phone, try viewing the file listing from the separate host.

### errors “ota_begin error err = 0x104”

If you see this error then check that the configured (and actual) flash size is large enough for the partitions in the partition table. The default "two OTA slots" partition table only works with 4 MB flash size. To use OTA with smaller flash sizes, create a custom partition table CSV (look in components/partition_table) and configure it in menuconfig.

                                    

readme of provisioning example

                                        
                                        ## Provisioning Example

This example demonstrates how to use ESP-NOW provisioning feature to do WiFi provisioning for other devices.

## Hardware Required

This example can run on any ESP32 series development board and at least two development boards are required.

## How to Use the Example

### Configure the devices

Navigate to the provisioning example directory, and type `idf.py menuconfig` to configure the provisioning example.

At least 2 boards are needed. You need to set the corresponding options and to program firmware to the different boards.

For board 1, it will work as the initiator device. Set following configurations under `Example Configuration` Options:
* Set `ESP-NOW provisioning Mode` as `Initiator Mode`

For board 2, it will work as the responder device. Set following configurations under `Example Configuration` Options:
* Set `ESP-NOW provisioning Mode` as `Responder Mode`
* Set `WiFi SSID` of the Router (Access-Point)
* Set `WiFi Password` of the Router (Access-Point)

### Operating procedures

When this example on the initiator device starts up, it will:

1. Keep scanning the provision beacon until receive it.
2. Send device type provision frame to request WiFi credential which resides in the responder device.
3. If receive WiFi type provision frame, get WiFi credential from the frame and connect to the Router.

When this example on the responder device starts up, it will:

1. Broadcast provision beacons every 100 ms in 30 seconds.
2. If receive device type provision frame, response with the WiFi type provision frame which contains WiFi credential.

> Authenticating the device through the information of the initiator is not presented in the example.

## Example Output

Console output of the initiator device:

```
I (575) ESPNOW: espnow [version: 1.0] init
I (339495) app_main: MAC: 7c:df:a1:86:d8:24, Channel: 1, RSSI: -35, Product_id: responder_test, Device Name: 
I (339515) app_main: MAC: 7c:df:a1:86:d8:24, Channel: 1, RSSI: -36, wifi_mode: 0, ssid: myssid, password: , token: 
I (339525) wifi:new:<1,1>, old:<1,0>, ap:<255,255>, sta:<1,1>, prof:1
I (339525) wifi:state: init -> auth (b0)
I (339535) wifi:state: auth -> assoc (0)
I (339545) wifi:state: assoc -> run (10)
I (339545) wifi:connected with myssid, aid = 2, channel 1, 40U, bssid = 3c:46:d8:0e:4c:ac
I (339545) wifi:security: Open Auth, phy: bgn, rssi: -32
I (339555) wifi:pm start, type: 0

I (339555) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
W (339565) wifi:<ba-add>idx:0 (ifx:0, 3c:46:d8:0e:4c:ac), tid:0, ssn:0, winSize:64
I (339605) wifi:BcnInt:102400, DTIM:1
I (340345) esp_netif_handlers: sta ip: 192.168.1.100, mask: 255.255.255.0, gw: 192.168.1.253
```

Console output of the responder device:

```
I (578) ESPNOW: espnow [version: 1.0] init
I (588) espnow_prov: Responder beacon start, timer: 30s
I (688) app_main: MAC: 7c:df:a1:76:42:38, Channel: 1, RSSI: -39, Product_id: initiator_test, Device Name: , Auth Mode: 0, device_secret: 
I (30688) espnow_prov: Responder beacon end
```

                                    

readme of security example

                                        
                                        # Security Example

This example demonstrates how to use ESP-NOW security feature to configure encryption key to devices, so the transmitted ESP-NOW data will be encrypted automatically.

The basic functionality is same as get_start, but just have this extra security enhancement.

## Functionality

The workflow is as follows:

<img src="../../docs/_static/en/espnow_security_en.png" width="450">

- [Protocomm](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/protocomm.html) is used to provide simple callbacks to the application for setting the configuration.
- ECDH and confirm details refer to [security-schemes](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/provisioning.html#security-schemes)

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards are required, 1 works as initiator, and the others work as responders.

## Configuration

Open the project configuration menu (`idf.py menuconfig`) to configure the Proof of Possession (PoP) string. It is used to authorize session and derive shared key. Set the same in initiator and responder devices:

```
idf.py menuconfig
    Example Configuration  --->
        Proof of Possession  --->
            "espnow_pop"
```

## How to Use the Example

### Step 1: Build & Flash & Run the Responders

- Select the ESP-NOW security responder Mode:

```
idf.py menuconfig
    Example Configuration  --->
        ESP-NOW Mode  --->
            () Initiator Mode
            (X) Responder Mode
```

- When the responder devices start up, it will wait to receive security info.

### Step 2: Build & Flash & Run the Initiator

- Select the ESP-NOW security initiator Mode:

```
idf.py menuconfig
    Example Configuration  --->
        ESP-NOW Mode  --->
            (X) Initiator Mode
            () Responder Mode
```

- When the initiator starts up, it will
  * Scan the responders and get responder address list
  * Secure handshake (ECDH) with responders and confirm share key
  * Send app key encrypted by share key to responders

### Step 3: Send and Receive in secure mode

- When security state is over, encryption key derived from app key will be set.
- Then data is encrypted and decrypted in AES128-CCM.
- In the example, message will be received from the serial port and broadcast to others in encrypted mode.
- Other node receives the espnow message and decrypt the data.

## Example Output

Output sample from the responder device:

```
I (550) wifi:Set ps type: 0

I (553) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (642) wifi:mode : I (645) app_main: Uart read handle task is running
I (645) app_main: Uart write task is running
I (26512) espnow_sec_resp: Get APP key

I (716965) app_main: espnow_send, count: 43, size: 23, data: Message from responder.
I (751668) app_main: espnow_recv, <83> [24:0a:c4:d6:d3:00][1][-16][23]: Message from initiator.
```

Output sample from the initiator device:

```
I (564) wifi:Set ps type: 0

I (567) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (657) wifi:modeI (660) app_main: Uart read handle task is running
I (660) app_main: Uart write task is running
W (767) app_main: espnow wait security num: 1
I (767) espnow_sec_init: count: 0, Secure_initiator_send, requested_num: 1, unfinished_num: 1, successed_num: 0
I (1807) app_main: App key is sent to the device to complete, Spend time: 3629ms, Scan time: 2506ms
I (1807) app_main: Devices security completed, successed_num: 1, unfinished_num: 0

I (692257) app_main: espnow_recv, <43> [24:0a:c4:04:5d:3c][1][-19][23]: Message from responder.
I (726959) app_main: espnow_send, count: 83, size: 23, data: Message from initiator.
```

                                    

readme of solution example

                                        
                                        # Solution Example

This example provides the solution to use `ESP-NOW` multiple features in one project.

- Provision WiFi on initiator device through APP and then configure responders WiFi network by espnow provisioning.
- Control lights on responder devices through button on initiator device.
- Debug the responder devices through commands and get log from responder devices.
- Upgrade responder devices through ESP-NOW.
- Security handshake and communication between initiator device and responder devices.

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards are required.

A button needs to be connected to a GPIO pin to configure WiFi network.

A `RGB LED` is needed if the development board doesn't have the RGB LED component. The light is used to indicate WiFi status and control status.

The GPIO pins that drive the button or the light can be configured and modified in [app_main.c](main/app_main.c).

## Configuration

Open the project configuration menu (`idf.py menuconfig`) to set following configurations under `Example Configuration` Options:

* Set `ESP-NOW Mode` of example to be `Initiator Mode` or `Responder Mode`
* Set `Enable ESPNOW Control` to enable ESP-NOW `control` function
* Set `Enable ESPNOW Debug` to enable ESP-NOW `debug` function
* Set `Enable ESPNOW OTA` to enable ESP-NOW `OTA` function
* Set `Enable WiFi Provision over ESP-NOW` to enable ESP-NOW `provision` function
* Set `Enable ESPNOW Security` to enable ESP-NOW `security` function
  - Set `Proof  Possession` string to authorize session.
* Under `WIFI Provision Configuration`, set `BLE` or `SoftAP` provisioning.

> Note that, the initiator/responder board will enable some functions as default. Only the initiator board can enable `WiFi Provision` function, and enabled by default.

## How to Use the Example

Before program the firmware to flash, please firstly use `erase_flash` to erase the entire flash memory.

```shell
idf.py erase_flash flash
```

The following steps will show the default functions when using default configurations. If disable some functions, the steps will be different.

### Step 1: Build & Flash & Run responder boards

When build the project, you can change the firmware name by:

```
cd examples/solution/
rm -rf build/
export PROJECT_NAME=Resp
idf.py build
```

You can find the firmware in `build/Resp.bin`.

If the device runs for the first time, it doesn't have the APP key and can't encrypt/decrypt ESP-NOW data until getting key from initiator board. If the device has stored the APP key, it will read APP key from flash and use the key to encrypt/decrypt ESP-NOW data.

### Step 2: Build & Flash & Run initiator board

If `PROJECT_NAME` is not defined, the default firmware name is `Init.bin`. If you want to change the firmware name, please refer to Step 1.

When initiator board runs, it will start security handshake with responders.

If the initiator board runs for the first time, it will generate a random APP key and store it to flash. Or if it has stored the APP key, it will get the APP key from flash.

After handshake is success, responders will get APP key and store the key to flash.

Then the initiator and responders can communicate ESP-NOW application data in security mode.

### Step 3: WiFi Provision on initiator board

If the device runs for the first time, it has not stored the router info and will not connect to AP. If it has stored the AP info, it will connect to router when WiFi start.

Double click the provision button if the device is not configurated and the light will turn `white`.

Use APP to scan the QR code to provision the initiator board, please refer to [README](https://github.com/espressif/esp-idf/blob/v4.4.1/examples/provisioning/wifi_prov_mgr/README.md)

After initiator board has connected to router, the light will turn `green` , or turn `red` if connection failed. If connecting router succeeds, it will start 30s provision beacon broadcast.

If you want to erase the WiFi config info, please long press the provision button, it will restore WiFi config and restart the board.

### Step 4: WiFi Provision on responder board

Single click the provision button on initiator board, it will also start 30s provision beacon broadcast.

Double click the provision button on responder board, it will enter ESP-NOW provision status and the light will turn `white`. After connecting router succeeds, the light will turn `green` or turn `red` if connection failed.

If you want to erase the WiFi config info, please long press the provision button on responder board, it will restore WiFi config and restart the board.

### Step 5: Control responder boards

Use `Boot button` on initiator board to bind, control and unbind the responder light. Please refer to [README](../control/README.md)

### Step 6: Debug responder boards

The initiator board can debug responder boards through `Command` command running on other devices, and receives running log from responder devices. Please refer to [README](../wireless_debug/README.md)

The responder board will store log in flash and send through ESP-NOW data. It also implements the function of transferring log data to the TCP server on the HTTP network(Default closed. Open the function in `menuconfig`->`Example Configuration`).

### Step 7: OTA through Commands

The initiator board can download new firmware from HTTP server and sends the firmware to responder devices through ESP-NOW. Please refer to OTA command in [README](../wireless_debug/README.md).

## Example Output

Note that the output, in particular the order of the output, may vary depending on the environment.

Console output of the initiator:

```
I (669) wifi:Set ps type: 0

I (672) phy_init: phy_version 909,156dee4,Apr  7 2022,20:27:09
I (757) wifi:mode : sta (7c:df:a1:76:42:38)
I (757) wifi:enable tsf
I (758) ESPNOW: espnow [version: 1.0] init
I (759) phy: chan:1,max_power:80
I (760) phy: chan:2,max_power:80
... ...
I (807) phy: chan:14,max_power:80
I (812) gpio: GPIO[2]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (821) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (843) espnow_console: Partition size: total: 52961, used: 0
I (845) espnow_console: Command history enabled
esp32c3> W (3333) init: espnow wait security num: 1
I (3333) espnow_sec_init: count: 0, Secure_initiator_send, requested_num: 1, unfinished_num: 1, successed_num: 0
I (4096) init: App key is sent to the device to complete, Spend time: 3265ms, Scan time: 2502ms
I (4097) init: Devices security completed, successed_num: 1, unfinished_num: 0
[7c:df:a1:86:d8:24][1][-20]: I (12854) espnow_sec_resp: Get APP key
I (5566) restart_func: num: 12, reason: 1, crash: 1
esp32c3> 
esp32c3> I (148161) app: WiFi provisioning press
W (148161) BTDM_INIT: esp_bt_mem_release not implemented, return OK
I (148162) wifi_prov_scheme_ble: BT memory released
I (148173) prov: Starting provisioning
I (148174) wifi:Set ps type: 1

W (148175) BTDM_INIT: esp_bt_controller_mem_release not implemented, return OK
I (148186) BTDM_INIT: BT controller compile version [d913766]
I (148198) BTDM_INIT: Bluetooth MAC: 7c:df:a1:76:42:3a

I (148202) wifi_prov_mgr: Provisioning started with service name : PROV_764238 
I (148203) prov: Scan this QR code from the provisioning application for Provisioning.
I (148214) QRCODE: Encoding below text with ECC LVL 0 & QR Code Version 10
I (148225) QRCODE: {"ver":"v1","name":"PROV_764238","pop":"abcd1234","transport":"ble"}
                                    
  █▀▀▀▀▀█ ▀▀▀█▄█   ▀▀▄ ▀▄ █ █▀▀▀▀▀█   
  █ ███ █  ▀▄█ █▄ ▀▄█ ▄██▀  █ ███ █   
  █ ▀▀▀ █  ▄▀█▀▄▀ ▀█▄▀ ██▄▀ █ ▀▀▀ █   
  ▀▀▀▀▀▀▀ █▄▀ █▄█▄█ ▀ █ ▀▄▀ ▀▀▀▀▀▀▀   
  ▀█▄▀▀ ▀▄▄▀▄ ▀▄ ▄▀▀▀█  ▀▄▄ ▀▄▄ ▄▄▀   
   ▄▄▄▄█▀▄█▀  ▀▀▀▀▄▄█    ▀ █  ▄█▄█▀   
   █▄▄▀▀▀█▄▀█ ▄▄██▄ ▀▀▀▄█  ▄▀█ ▀▄▄▀   
  █ ▄▀█▀▀█▄▄  ▄ ▄█▄▀▀█▄▀█▄▀▄▄█  ▄   
  █▄▀▀█▀▀▄▄ ▄█▀▀ █▀▄▀▄▀ ▄█  ███▄ ██   
  ▄ ██▀█▀▀  ▄▄▀▄███▀▄▀█ ▀█ █▀▀ ▀▄▄▀   
  ██ █  ▀ ██ ▀▄▄█▄▀▀█▄█▄█▀▀█ ▀▄ ▄▀  
  █ ▀▄ ▄▀██▀ █▄  ▀█▄█▄▀▀█▀█ ▄█ ▀▄▄█   
  ▀▀▀▀▀▀▀▀▄  ▀▀▄▄██▄█▀█ ▀██▀▀▀█▄▄▀  
  █▀▀▀▀▀█   ██▀▀▀██ ▄▀▄ █▄█ ▀ █ ▄ ▄   
  █ ███ █ █▀▀▄█▀▀█▀▄█▄▄ ▀██▀▀▀▀▄▄▀▀   
  █ ▀▀▀ █ ▄ ▀▀ ▄█▀█ █▀ ▀▀███▄▀█ █▄█   
  ▀▀▀▀▀▀▀ ▀ ▀▀  ▀▀ ▀     ▀▀▀▀▀▀     
                                    

I (148421) prov: If QR code is not visible, copy paste the below URL in a browser.
https://espressif.github.io/esp-jumpstart/qrcode.html?data={"ver":"v1","name":"PROV_764238","pop":"abcd1234","transport":"ble"}
I (148203) protocomm_nimble: BLE Host Task Started
I (148447) NimBLE: GAP procedure initiated: stop advertising.

I (148459) NimBLE: GAP procedure initiated: advertise; 
I (148460) NimBLE: disc_mode=2
I (148470) NimBLE:  adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=256 adv_itvl_max=256
I (148471) NimBLE: 

I (148203) prov: Provisioning started
I (199375) protocomm_nimble: mtu update event; conn_handle=1 cid=4 mtu=256

I (226354) prov: Received Wi-Fi credentials
        SSID     : myssid
        Password : mypassword
I (228322) wifi:new:<5,1>, old:<1,0>, ap:<255,255>, sta:<5,1>, prof:1
I (228971) wifi:state: init -> auth (b0)
I (228993) wifi:state: auth -> assoc (0)
I (229009) wifi:state: assoc -> run (10)
I (229031) wifi:connected with myssid, aid = 7, channel 5, 40U, bssid = e8:9f:80:da:ab:8f
I (229032) wifi:security: WPA2-PSK, phy: bgn, rssi: -64
I (229046) wifi:pm start, type: 1

I (229047) wifi:set rx beacon pti, rx_bcn_pti: 14, bcn_timeout: 14, mt_pti: 25000, mt_time: 10000
I (229052) wifi:BcnInt:102400, DTIM:2
W (229063) wifi:<ba-add>idx:0 (ifx:0, e8:9f:80:da:ab:8f), tid:0, ssn:0, winSize:64
I (230563) prov: Connected with IP Address:192.168.0.42
I (230564) esp_netif_handlers: sta ip: 192.168.0.42, mask: 255.255.255.0, gw: 192.168.0.1
I (230575) init: got ip:192.168.0.42
I (230576) wifi_prov_mgr: STA Got IP
I (230577) prov: Provisioning successful
I (230577) espnow_prov: Responder beacon start, timer: 30s
I (232598) NimBLE: GAP procedure initiated: stop advertising.

I (232603) NimBLE: GAP procedure initiated: stop advertising.

I (232604) NimBLE: GAP procedure initiated: terminate connection; conn_handle=1 hci_reason=19

E (232676) protocomm_nimble: Error setting advertisement data; rc = 30
W (232679) Timer: Timer not stopped
W (232680) Timer: Timer not stopped
I (232685) wifi_prov_mgr: Provisioning stopped
W (232686) BTDM_INIT: esp_bt_mem_release not implemented, return OK
I (232697) wifi_prov_scheme_ble: BTDM memory released
I (232708) wifi:Set ps type: 0

I (260677) espnow_prov: Responder beacon end
I (273601) app: ESPNOW provisioning press
I (273601) espnow_prov: Responder beacon start, timer: 30s
I (274203) init: MAC: 7c:df:a1:86:d8:24, Channel: 5, RSSI: -22, Product_id: initiator_test, Device Name: , Auth Mode: 0, device_secret: 
[7c:df:a1:86:d8:24][5][-23]: I (282958) resp: MAC: 7c:df:a1:76:42:38, Channel: 5, RSSI: -25, Product_id: responder_test, Device Name: 
[7c:df:a1:86:d8:24][5][-29]: I (283485) wifi:[7c:df:a1:86:d8:24][5][-30]: new:<5,1>, old:<5,0>, ap:<255,255>, sta:<5,1>, prof:1[7c:df:a1:86:d8:24][5][-29]: 
[7c:df:a1:86:d8:24][5][-27]: I (284082) wifi:[7c:df:a1:86:d8:24][5][-27]: state: init -> auth (b0)[7c:df:a1:86:d8:24][5][-24]: 
[7c:df:a1:86:d8:24][5][-28]: I (284087) wifi:[7c:df:a1:86:d8:24][5][-31]: state: auth -> assoc (0)[7c:df:a1:86:d8:24][5][-35]: 
[7c:df:a1:86:d8:24][5][-36]: I (284114) wifi:[7c:df:a1:86:d8:24][5][-32]: state: assoc -> run (10)[7c:df:a1:86:d8:24][5][-31]: 
[7c:df:a1:86:d8:24][5][-29]: I (284293) wifi:[7c:df:a1:86:d8:24][5][-30]: connected with myssid, aid = 8, channel 5, 40U, bssid = e8:9f:80:da:ab:8f[7c:df:a1:86:d8:24][5][-30]: 
[7c:df:a1:86:d8:24][5][-31]: I (284295) wifi:[7c:df:a1:86:d8:24][5][-31]: security: WPA2-PSK, phy: bgn, rssi: -68[7c:df:a1:86:d8:24][5][-34]: 
[7c:df:a1:86:d8:24][5][-36]: I (284306) wifi:[7c:df:a1:86:d8:24][5][-38]: pm start, type: 0
[7c:df:a1:86:d8:24][5][-40]: 
[7c:df:a1:86:d8:24][5][-44]: I (284307) wifi:[7c:df:a1:86:d8:24][5][-42]: set rx beacon pti, rx_bcn_pti: 14, bcn_timeout: 14, mt_pti: 25000, mt_time: 10000[7c:df:a1:86:d8:24][5][-37]: 
[7c:df:a1:86:d8:24][5][-37]: I (284308) wifi:[7c:df:a1:86:d8:24][5][-37]: BcnInt:102400, DTIM:2[7c:df:a1:86:d8:24][5][-37]: 
[7c:df:a1:86:d8:24][5][-37]: W (284533) wifi:[7c:df:a1:86:d8:24][5][-37]: <ba-add>idx:0 (ifx:0, e8:9f:80:da:ab:8f), tid:0, ssn:0, winSize:64[7c:df:a1:86:d8:24][5][-35]: 
[7c:df:a1:86:d8:24][5][-33]: I (285584) esp_netif_handlers: sta ip: 192.168.0.45, mask: 255.255.255.0, gw: 192.168.0.1
[7c:df:a1:86:d8:24][5][-35]: I (285585) resp: got ip:192.168.0.45
esp32c3> 
esp32c3> 
esp32c3> I (303701) espnow_prov: Responder beacon end
I (307341) app: WiFi provisioning press
I (331541) app: initiator bind press
[7c:df:a1:86:d8:24][5][-22]: I (340306) espnow_ctrl: bind, esp_log_timestamp: 340306, timestamp: 30802, rssi: -25, rssi: -55
[7c:df:a1:86:d8:24][5][-22]: I (340307) control_func: addr: 7c:df:a1:76:42:38, initiator_type: 2, initiator_value: 1
[7c:df:a1:86:d8:24][5][-23]: I (340319) app: bind, uuid: 7c:df:a1:76:42:38, initiator_type: 513
I (336321) app: initiator send press
[7c:df:a1:86:d8:24][5][-20]: I (345086) app: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 0
I (338166) app: initiator send press
[7c:df:a1:86:d8:24][5][-19]: I (346931) app: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 1
... ...
I (346686) app: initiator unbind press
[7c:df:a1:86:d8:24][5][-20]: I (355451) app: unbind, uuid: 7c:df:a1:76:42:38, initiator_type: 513

```

Console output of the responder:

```I

I (653) phy_init: phy_version 909,156dee4,Apr  7 2022,20:27:09
I (738) wifi:mode : sta (7c:df:a1:86:d8:24)
I (738) wifi:enable tsf
I (739) ESPNOW: espnow [version: 1.0] init
I (740) phy: chan:1,max_power:80
I (741) phy: chan:2,max_power:80
... ...
I (788) phy: chan:14,max_power:80
I (793) gpio: GPIO[2]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (802) esp_timesync: Initializing SNTP. Using the SNTP server: pool.ntp.org
I (827) espnow_log_flash: LOG flash initialized successfully
I (828) espnow_log_flash: Log save partition subtype: label: log_info, addr:0x3d0000, offset: 0, size: 65536
I (839) espnow_log: log initialized successfully
esp32c3> I (5542) restart_func: num: 3, reason: 1, crash: 1
I (12854) espnow_sec_resp: Get APP key
esp32c3> 
esp32c3> I (269307) app: WiFi provisioning press
I (269310) phy: chan:1,max_power:80
I (269310) phy: chan:2,max_power:80
... ...
I (269358) phy: chan:14,max_power:80
I (282958) resp: MAC: 7c:df:a1:76:42:38, Channel: 5, RSSI: -25, Product_id: responder_test, Device Name: 
I (282994) resp: MAC: 7c:df:a1:76:42:38, Channel: 5, RSSI: -25, wifi_mode: 0, ssid: myssid, password: mypassword, token: 
I (283064) resp: provisioning initiator exit
I (283485) wifi:new:<5,1>, old:<5,0>, ap:<255,255>, sta:<5,1>, prof:1
I (284082) wifi:state: init -> auth (b0)
I (284087) wifi:state: auth -> assoc (0)
I (284114) wifi:state: assoc -> run (10)
I (284293) wifi:connected with myssid, aid = 8, channel 5, 40U, bssid = e8:9f:80:da:ab:8f
I (284295) wifi:security: WPA2-PSK, phy: bgn, rssi: -68
I (284306) wifi:pm start, type: 0

I (284307) wifi:set rx beacon pti, rx_bcn_pti: 14, bcn_timeout: 14, mt_pti: 25000, mt_time: 10000
I (284308) wifi:BcnInt:102400, DTIM:2
W (284533) wifi:<ba-add>idx:0 (ifx:0, e8:9f:80:da:ab:8f), tid:0, ssn:0, winSize:64
I (285584) esp_netif_handlers: sta ip: 192.168.0.45, mask: 255.255.255.0, gw: 192.168.0.1
I (285585) resp: got ip:192.168.0.45
esp32c3> 
esp32c3> 
esp32c3> I (340306) espnow_ctrl: bind, esp_log_timestamp: 340306, timestamp: 30802, rssi: -25, rssi: -55
I (340307) control_func: addr: 7c:df:a1:76:42:38, initiator_type: 2, initiator_value: 1
I (340319) app: bind, uuid: 7c:df:a1:76:42:38, initiator_type: 513
I (345086) app: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 0
I (346931) app: espnow_ctrl_responder_recv, initiator_attribute: 513, responder_attribute: 1, value: 1
... ...
I (355451) app: unbind, uuid: 7c:df:a1:76:42:38, initiator_type: 513
```

## Troubleshooting

* Errors `E (14798) espnow_sec: Failed at mbedtls_ccm_auth_decrypt with error code : -15`. It means authentication failed. Maybe initiator board erases its flash and generates a new security key, not the same with responder. If you see this error please erase responder board flash and reset responder board, the security handshake will execute again after reset initiator board. The responder board will get the security key to keep the same with initiator board.
* Build with ESP32-C3 failed with 'ADC_BUTTON_WIDTH' undeclared.
  Please change the defination as the following in [button_adc.c](managed_components/espressif__button/button_adc.c)

```
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3
#define ADC_BUTTON_WIDTH       ADC_WIDTH_BIT_12
#elif CONFIG_IDF_TARGET_ESP32S2
#define ADC_BUTTON_WIDTH       ADC_WIDTH_BIT_13
#endif

```

                                    

readme of wireless_debug example

                                        
                                        # ESP-NOW Debug Demo

This example demonstrates how to debug the ESP-NOW devices.

## Functionality

ESP-NOW debug receiver board or monitored device provides the following features through UART or espnow command:

- [Wi-Fi configuration](#Wi-Fi-Command): provides WiFi configuration, WiFi scan, WiFi ping commands.
- [ESP-NOW configuration](#ESP-NOW-Command): provides control, provisioning, OTA, configuration and iperf commands.
- [System command]: provides heap, version, restart, power save, reset, rollback, coredump commands.
- [Peripherals command]: provides GPIO, UART commands.
- [Command](#Command-Command): runs commands on specific devices.
- [General command](#Other-Command): includes help command to print all currently supported commands.

ESP-NOW debug receiver board also provides the following features:

- Receives running log from ESP-NOW devices via [ESP-NOW](https://esp-idf.readthedocs.io/en/latest/api-reference/wifi/esp_now.html) wireless transmission technology.
- [Web server](#Web-Server): starts a HTTP web server, and PC web browser can get running log and status from the server.

ESP-NOW monitored device also provides the following features:

- The device log data will be stored in flash and sent through ESP-NOW data.
- The monitored device also implements the function of transferring log data to the TCP server on the HTTP network.

> Note:
>
> 1. ESP-NOW debug receiver board can receive debugging data from devices only when the board is on the same Wi-Fi channel with the devices.
> 2. If the ESP-NOW debug receiver board is on the same channel with devices, you don't need to connect the board with the router.

## Hardware Required

This example can run on any ESP32 series boards and at least two development boards are required. One is the debug receiver board and others are monitored devices.

## Configuration

Open the project configuration menu (`idf.py menuconfig`) to configure "ESP-NOW debug monitor Mode" on debug receiver board or "ESP-NOW debug monitored Mode" on monitored devices.

For debug monitor mode, configure web server to debug devices through the web pages (Refer to Kconfig file).

For debug monitored mode, post monitored device log to HTTP server (Refer to Kconfig file).

## How to Use the Example

### Workflow

1. Compile and flash this project to an ESP32 development board;
2. Open serial port terminal and restart development board:

> Please use serial port terminals such as `minicom` to avoid some unexpected problems when using `idf.py monitor`.

3. Debug ESP-NOW by entering the following commands according to the prompts.

> The following describes the use of each command in sequence.

### Serial Port Commands

* ESP-NOW debug receiver board or monitored device supports the following serial port commands: help, wifi_config, wifi_scan, wifi_ping and command, provisioning, control, ota.
* The interaction of serial port commands follows the following rules:

  1. PC sends commands to ESP-NOW debug receiver board through serial port with a baud rate of 115200.
  2. In command definition, all characters are lowercase (some options are uppercase), and strings do not need to be quoted.
  3. The elements in angle brackets <> in command description should be taken as a parameter and be replaced as the case may be.
  4. The part contained in square brackets [] or brackets () in command description is the value range that can be filled in.
  5. The pattern of serial port commands is shown below, with each element separated by a space:

     ```
     Command + Option + Parameter,for example: wifi_config -c 1
     ```
  6. Serial port commands support line breaks: `\n` and `\r\n`.
  7. Serial port returns execution results at a baud rate of 115200.

### Wi-Fi Command

1. Wi-Fi configuration
   |                    |                                                                                                                   | Note                                                                              |
   | ------------------ | ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
   | Command definition | `wifi_config -i -c <channel (1 ~ 13)> -s <ssid> -b <bssid (xx:xx:xx:xx:xx:xx)> -p <password> -C <country_code>` |                                                                                   |
   | Command            | wifi_config -i                                                                                                    | Get Wi-Fi information                                                             |
   |                    | wifi_config -c -s -b -p -C                                                                                        | Set Wi-Fi configuration                                                           |
   | Parameter          | `-i` or `--info`                                                                                              | Wi-Fi information                                                                 |
   |                    | `-c` or `--channel`                                                                                           | Wi-Fi work channel                                                                |
   |                    | `-s` or `--ssid`                                                                                              | AP SSID                                                                           |
   |                    | `-b` or `--bssid`                                                                                             | AP BSSID                                                                          |
   |                    | `-p` or `--password`                                                                                          | AP password                                                                       |
   |                    | `-C` or `--country_code`                                                                                      | Set the current country code                                                      |
   | Example            | wifi_config -s ` "ssid"` -p ` "password"`                                                                     | Wi-Fi sets and connects to the AP with SSID as "ssid" and password as "password". |
   |                    | wifi_config -c 11                                                                                                 | Configure the working channel of the ESP-NOW device to be 11                      |
2. Scan command
   |                    |                                                                                            | Note                                                                                     |
   | ------------------ | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
   | Command definition | `wifi_scan -r <rssi (-120 ~ 0)> -s <ssid> -b <bssid (xx:xx:xx:xx:xx:xx)> -p <time (ms)>` |                                                                                          |
   | Command            | wifi_scan -r -s -b -p                                                                      | Scan APs                                                                                 |
   | Parameter          | `-r` or `--rssi`                                                                       | Filter devices by RSSI                                                                   |
   |                    | `-s` or `--ssid`                                                                       | Filter devices by SSID                                                                   |
   |                    | `-b` or `--bssid`                                                                      | Filter devices by BSSID                                                                  |
   |                    | `-p` or `--passive`                                                                    | Passive scan time of each channel                                                        |
   | Example            | wifi_scan                                                                                  | Scan all APs                                                                             |
   |                    | wifi_scan -r -60                                                                           | Scan devices with RSSI signal value within -60                                           |
   |                    | wifi_scan -p 600 -b 30:ae:a4:80:16:3c                                                      | Scan devices with BSSID 30:ae:a4:80:16:3c and set passive scan time 600 ms every channel |
3. Ping command
   |                    |                                                    | Note                                              |
   | ------------------ | -------------------------------------------------- | ------------------------------------------------- |
   | Command definition | `ping <host> -W <t> -i <t> -s <n> -c <n> -Q <n>` |                                                   |
   | Command            | `ping host -w -i -s -c -Q`                       | Send ICMP ECHO_REQUEST to network hosts           |
   | Parameter          | `host`                                           | Host address                                      |
   |                    | `-w` or `--timeout`                            | Time to wait for a response, in seconds           |
   |                    | `-i` or `--interval`                           | Wait interval seconds between sending each packet |
   |                    | `-s` or `--size`                               | Specify the number of data bytes to be sent       |
   |                    | `-c` or `--count`                              | Stop after sending count packets                  |
   |                    | `-Q` or `--tos`                                | Set Type of service related bits in IP datagrams  |
   | Example            | ping 192.168.0.1                                   | Ping host address 192.168.0.1                     |

### ESP-NOW Command

1. Scan
   |                    |                                                             | Note                                           |
   | ------------------ | ----------------------------------------------------------- | ---------------------------------------------- |
   | Command definition | `scan <addr (xx:xx:xx:xx:xx:xx)> -a -r <rssi (-120 ~ 0)>` |                                                |
   | Command            | `scan <addr> -a -r`                                       | Find devices that support ESP-NOW debug        |
   | Parameter          | `<addr>`                                                  | MAC of the monitored device                    |
   |                    | `-a` or `--all`                                         | Full channel scan                              |
   |                    | `-r` or `--rssi`                                        | Filter devices by RSSI                         |
   | Example            | scan -a                                                     | Scan all devices in all channel                |
   |                    | scan -r -60                                                 | Scan devices with RSSI signal value within -60 |
   |                    | scan 30:ae:a4:80:16:3c                                      | Scan devices with BSSID 30:ae:a4:80:16:3c      |
2. Provisioning
   |                    |                                                                   | Note                                                                               |
   | ------------------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
   | Command definition | `provisioning -er -i <beacon_time(s)> <ap_ssid> <app_password>` |                                                                                    |
   | Command            | provisioning -e -r -i                                             | Provisioning                                                                       |
   | Parameter          | `-e` or `--erase`                                             | Reset WiFi provisioning information and restart                                    |
   |                    | `-r` or `--responder`                                         | Responder devices start provisioning                                               |
   |                    | `-i` or `--initiator`                                         | Set provisioning beacon time                                                       |
   |                    | `ap_ssid` `ap_password`                                       | Configure network for devices                                                      |
   | Example            | provisioning -e                                                   | Reset WiFi provisioning information and restart                                    |
   |                    | provisioning -r                                                   | Responder devices start provisioning                                               |
   |                    | provisioning -i 30000 myssid mypassword                           | Send provisioning beacon for 30 s and send WiFi configuration to responder devices |
3. Control
   |                    |                                                                                                                                                                                                           | Note                                                                                              |
   | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
   | Command definition | `control  -lasC -b <initiator_attribute> -u <initiator_attribute> -c <initiator_attribute> -m <addr (xx:xx:xx:xx:xx:xx)> -t <responder_attribute> -v <responder_value> -b <count> -t <count> -r <rssi>` |                                                                                                   |
   | Command            | control -lasC -b -u -c -m -t -v -b -t -r                                                                                                                                                                  | Control devices by esp-now command                                                                |
   | Parameter          | `-l` or `--list`                                                                                                                                                                                      | Get device binding list                                                                           |
   |                    | `-a` or `--ack`                                                                                                                                                                                       | Wait for the receiving device to return ack                                                       |
   |                    | `-s` or `--filter_weak_signal`                                                                                                                                                                        | Discard packets which rssi is lower than forward_rssi                                             |
   |                    | `-C` or `--filter_adjacent_channel`                                                                                                                                                                   | Discard packets from adjacent channels                                                            |
   |                    | `-b` or `--bind`                                                                                                                                                                                      | Binding with response device                                                                      |
   |                    | `-u` or `--unbind`                                                                                                                                                                                    | Unbinding with response device                                                                    |
   |                    | `-c` or `--command`                                                                                                                                                                                   | Control command to bound device                                                                   |
   |                    | `-m` or `--mac`                                                                                                                                                                                       | MAC of the monitored device                                                                       |
   |                    | `-t` or `--responder_attribute`                                                                                                                                                                       | Responder's attribute                                                                             |
   |                    | `-v` or `--responder_value`                                                                                                                                                                           | Responder's value                                                                                 |
   |                    | `-b` or `--broadcast`                                                                                                                                                                                 | Broadcast packet                                                                                  |
   |                    | `-t` or `--forward_ttl`                                                                                                                                                                               | Number of hops in data transfer                                                                   |
   |                    | `-r` or `--forward_rssi`                                                                                                                                                                              | Discard packet which rssi is lower than forward_rssi                                              |
   | Example            | control -b 0x200                                                                                                                                                                                          | Bind device, initiator_attribute: 512                                                             |
   |                    | control -u 0x200                                                                                                                                                                                          | Unbind device, initiator_attribute: 512                                                           |
   |                    | control -c 0x200 -t 0x1 -v 0                                                                                                                                                                              | Send control command,initiator_attribute: 512, set responder_attribute: 1, responder_value: 0     |
   |                    | control -c 0x200 -t 0x101 -v 100                                                                                                                                                                          | Send control command,initiator_attribute: 512, set responder_attribute: 257, responder_value: 100 |
4. OTA
   |                    |                                                                            | Note                                         |
   | ------------------ | -------------------------------------------------------------------------- | -------------------------------------------- |
   | Command definition | `ota -d <url> -f <wait_tick> -s <xx:xx:xx:xx:xx:xx>,<xx:xx:xx:xx:xx:xx>` |                                              |
   | Command            | ota -d -f -s                                                               | Firmware update                              |
   | Parameter          | `-d` or `--download`                                                   | Firmware Download url                        |
   |                    | `-f` or `--find`                                                       | Find upgradeable devices                     |
   |                    | `-s` or `--send`                                                       | Send firmware to selected device             |
   | Example            | ota -d http://192.168.0.3:8070/hello-world.bin                             | Download Firmware                            |
   |                    | ota -f 3000                                                                | Find upgradeable devices for no more than 3s |
   |                    | ota -s 30:ae:a4:80:16:3c                                                   | Send firmware to 30:ae:a4:80:16:3c           |
5. Configuration
   |                    |                                                                                                                                                                   | Note                                            |
   | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
   | Command definition | `espnow_config -i -c <channel (1 ~ 13)> -r <rate (wifi_phy_rate_t)> -t <tx_power (8, 84)> -p <protocol_bitmap[1, 2, 4, 8]> -C <country_code ('CN', 'JP, 'US')>` |                                                 |
   | Command            | espnow_config -i -c -r -t -p -C                                                                                                                                   | ESP-NOW configuration                           |
   | Parameter          | `-i` or `--info`                                                                                                                                              | Print all configuration information             |
   |                    | `-c` or `--channel`                                                                                                                                           | Channel of ESP-NOW                              |
   |                    | `-r` or `--rate`                                                                                                                                              | Wi-Fi PHY rate encodings                        |
   |                    | `-t` or `--tx_power`                                                                                                                                          | Set maximum transmitting power after WiFi start |
   |                    | `-p` or `--protocol`                                                                                                                                          | Set protocol type of specified interface        |
   |                    | `-C` or `--country_code`                                                                                                                                      | Set the current country code                    |
   | Example            | espnow_config -i                                                                                                                                                  |                                                 |
   |                    | espnow_config -r 0x0B                                                                                                                                             | Config ESPNOW data rate 6 Mbps                  |
6. Iperf
   |                    |                                                                                                                           | Note                                                             |
   | ------------------ | ------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
   | Command definition | `espnow_iperf -spga -c <responder (xx:xx:xx:xx:xx:xx)> -i <interval (sec)> -l <len (Bytes)> -t <time (sec)> -b <count>` |                                                                  |
   | Command            | espnow_iperf -spga -c -i -l -t -b                                                                                         | ESP-NOW iperf                                                    |
   | Parameter          | `-s` or `--responder`                                                                                                 | Run in responder mode, receive from throughput or ping           |
   |                    | `-p` or `--ping`                                                                                                      | Run in ping mode, send to responder                              |
   |                    | `-g` or `--group`                                                                                                     | Send a package to a group                                        |
   |                    | `-a` or `--abort`                                                                                                     | Abort running espnow-iperf                                       |
   |                    | `-c` or `--initiator`                                                                                                 | Run in initiator mode, ping to`<responder>`                    |
   |                    | `-i` or `--interval`                                                                                                  | Seconds between periodic bandwidth reports (default 3 secs)      |
   |                    | `-l` or `--len`                                                                                                       | Length of buffer in bytes to read or write (Defaults: 230 Bytes) |
   |                    | `-t` or `--time`                                                                                                      | Time in seconds to transmit for (default 10 secs)                |
   |                    | `-b` or `--roadcast`                                                                                                  | Send package by broadcast                                        |
   | Example            | espnow_iperf -s                                                                                                           | Run in responder mode                                            |
   |                    | espnow_iperf -c 30:ae:a4:80:16:3c                                                                                         | Send iperf packages to responder mac                             |

### *Command* Command

1. Command
   |                    |                                                                               | Note                                                 |
   | ------------------ | ----------------------------------------------------------------------------- | ---------------------------------------------------- |
   | Command definition | `command  -a <addr_list (xx:xx:xx:xx:xx:xx,xx:xx:xx:xx:xx:xx)> <"Command">` |                                                      |
   | Command            | command addr_list "Command"                                                   | Let the console command run on the monitoring device |
   | Parameter          | `-a` or `--channel_all`                                                   | Send packets on all channels                         |
   |                    | `addr_list`                                                                 | Device MAC address                                   |
   |                    | `"Command"`                                                                 | The command to be executed on a specific device      |
   | Example            | command 30:ae:a4:80:16:3c "help"                                              | Run help command on device 30:ae:a4:80:16:3c         |

### Other Command

* `help`: prints all currently supported commands.

### Web Server

The function is disabled by default. If you want to use the function, please follow the steps.

- Open Web server under `Example Configuration` Options:
  * Set `Enable WebServer for ESP-NOW debug` to `y`, default is `n`.
  * Set `mDNS Host Name`, default is `espnow-webserver`
  * Set `WiFi SoftAP SSID`, default is `espnow-webserver`
  * Set `Website mount point in VFS`, default is `/www`
- Connect PC or phone to `Wi-Fi SoftAP`
- Open url `http://espnow-webserver` in web browser, and customer can debug devices through the web browser, like getting all devices log and status, controlling or upgrading the monitored devices.

<img src="../../docs/_static/zh_CN/web_server.png" width="1000">

### Post monitored device log to HTTP server

The function is disabled by default. If you want to use the function, please follow the steps.

1. Run HTTP server with follow command or start TCP server on PC or phone.

```shell
python -m http.server 8070
```

2. Configure the devices with `idf.py menuconfig` under `Example Configuration` Options:
   * Set `Post flash log to HTTP server` to `y`.
   * Set the server URL `Flash log URL endpoint`
3. Build & flash & Run the device, connect the device to the Router (Access-Point) by WiFi command or provision command.

After the device connected to the Router (Access-Point), it will post log to the HTTP server.

> Note:

1. ESP32 and phone should be connected to the same router, so that data information can be collected on the network assistant tool.

## Note

1. Impact on Performance. Since ESP-NOW uses a Wi-Fi interface to send and receive data packages, delay may occur in receiving commands or in data transmission if there is a large amount of data to be transmitted among ESP-NOW devices. By testing in a good network, we provide the following thresholds, and with such configuration parameters, the delay caused to devices is negligible.

   * Fifty ESP-NOW devices (The more the devices, the worse the network.)
   * Set logging level to `info` (The lower the level, the worse the network may be.)
2. It should also be noted that when using a new chip for burning, the chip needs to be erased and then burned.
3. The log_info area is added to the partition table in this example as a space to save logs. The chip needs to be erased before programming.
4. The head of the data is a timestamp. It is just an experiment and there is no real-time calibration. It can be modified according to the user's own needs.
5. Get the status of log mode `uart`, `flash`, `espnow` in the console command `log -i`. The `console` command can't be used to disable the log configuration, because the main program has been forced to be enabled. If the user do not want to use such a function, the main program can be disable.

   ```
   // espnow_log_init(&log_config);
   ```

                                    

Links

Supports all targets

License: Apache-2.0

To add this component to your project, run:

idf.py add-dependency "espressif/esp-now^2.3.0"

or download archive

Dependencies

  • espressif/cmake_utilities 0.*
  • ESP-IDF >=4.3
  • Examples:

    coin_cell_demo/bulb

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:coin_cell_demo/bulb"

    or download archive

    coin_cell_demo/switch

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:coin_cell_demo/switch"

    or download archive

    control

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:control"

    or download archive

    get-started

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:get-started"

    or download archive

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:ota"

    or download archive

    provisioning

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:provisioning"

    or download archive

    security

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:security"

    or download archive

    solution

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:solution"

    or download archive

    wireless_debug

    more details

    To create a project from this example, run:

    idf.py create-project-from-example "espressif/esp-now^2.3.0:wireless_debug"

    or download archive

    Stats

    • Downloaded in total
      Downloaded in total 5.5k times
    • Downloaded this version
      This version: 1.7k times

    Badge

    espressif/esp-now version: 2.3.0
    |