| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- |
# ESPNOW Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example shows how to use ESPNOW of wifi. Example does the following steps:
* Start WiFi.
* Initialize ESPNOW.
* Register ESPNOW sending or receiving callback function.
* Add ESPNOW peer information.
* Send and receive ESPNOW data.
This example need at least two ESP devices:
* In order to get the MAC address of the other device, Device1 firstly send broadcast ESPNOW data with 'state' set as 0.
* When Device2 receiving broadcast ESPNOW data from Device1 with 'state' as 0, adds Device1 into the peer list.
Then start sending broadcast ESPNOW data with 'state' set as 1.
* When Device1 receiving broadcast ESPNOW data with 'state' as 1, compares the local magic number with that in the data.
If the local one is bigger than that one, stop sending broadcast ESPNOW data and starts sending unicast ESPNOW data to Device2.
* If Device2 receives unicast ESPNOW data, also stop sending broadcast ESPNOW data.
In practice, if the MAC address of the other device is known, it's not required to send/receive broadcast ESPNOW data first,
just add the device into the peer list and send/receive unicast ESPNOW data.
There are a lot of "extras" on top of ESPNOW data, such as type, state, sequence number, CRC and magic in this example. These "extras" are
not required to use ESPNOW. They are only used to make this example to run correctly. However, it is recommended that users add some "extras"
to make ESPNOW data more safe and more reliable.
## How to use example
### Configure the project
```
idf.py menuconfig
```
* Set WiFi mode (station or SoftAP) under Example Configuration Options.
* Set ESPNOW primary master key under Example Configuration Options.
This parameter must be set to the same value for sending and recving devices.
* Set ESPNOW local master key under Example Configuration Options.
This parameter must be set to the same value for sending and recving devices.
* Set Channel under Example Configuration Options.
The sending device and the recving device must be on the same channel.
* Set Send count and Send delay under Example Configuration Options.
* Set Send len under Example Configuration Options.
* Set Enable Long Range Options.
When this parameter is enabled, the ESP32 device will send data at the PHY rate of 512Kbps or 256Kbps
then the data can be transmitted over long range between two ESP32 devices.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(To exit the serial monitor, type ``Ctrl-]``.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
## Example Output
Here is the example of ESPNOW receiving device console output.
```
I (898) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0
I (898) wifi: mode : sta (30:ae:a4:80:45:68)
I (898) espnow_example: WiFi started
I (898) ESPNOW: espnow [version: 1.0] init
I (5908) espnow_example: Start sending broadcast data
I (6908) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (7908) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (52138) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (52138) espnow_example: Receive 0th broadcast data from: 30:ae:a4:0c:34:ec, len: 200
I (53158) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (53158) espnow_example: Receive 1th broadcast data from: 30:ae:a4:0c:34:ec, len: 200
I (54168) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (54168) espnow_example: Receive 2th broadcast data from: 30:ae:a4:0c:34:ec, len: 200
I (54168) espnow_example: Receive 0th unicast data from: 30:ae:a4:0c:34:ec, len: 200
I (54678) espnow_example: Receive 1th unicast data from: 30:ae:a4:0c:34:ec, len: 200
I (55668) espnow_example: Receive 2th unicast data from: 30:ae:a4:0c:34:ec, len: 200
```
Here is the example of ESPNOW sending device console output.
```
I (915) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0
I (915) wifi: mode : sta (30:ae:a4:0c:34:ec)
I (915) espnow_example: WiFi started
I (915) ESPNOW: espnow [version: 1.0] init
I (5915) espnow_example: Start sending broadcast data
I (5915) espnow_example: Receive 41th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (5915) espnow_example: Receive 42th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (5925) espnow_example: Receive 44th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (5935) espnow_example: Receive 45th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (6965) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (6965) espnow_example: Receive 46th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (7975) espnow_example: send data to ff:ff:ff:ff:ff:ff
I (7975) espnow_example: Receive 47th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (7975) espnow_example: Start sending unicast data
I (7975) espnow_example: send data to 30:ae:a4:80:45:68
I (9015) espnow_example: send data to 30:ae:a4:80:45:68
I (9015) espnow_example: Receive 48th broadcast data from: 30:ae:a4:80:45:68, len: 200
I (10015) espnow_example: send data to 30:ae:a4:80:45:68
I (16075) espnow_example: send data to 30:ae:a4:80:45:68
I (17075) espnow_example: send data to 30:ae:a4:80:45:68
I (24125) espnow_example: send data to 30:ae:a4:80:45:68
```
## Troubleshooting
If ESPNOW data can not be received from another device, maybe the two devices are not
on the same channel or the primary key and local key are different.
In real application, if the receiving device is in station mode only and it connects to an AP,
modem sleep should be disabled. Otherwise, it may fail to revceive ESPNOW data from other devices.
没有合适的资源?快使用搜索试试~ 我知道了~
源码:esp-now-ble- tesecode-20241214.rar
共2000个文件
obj:1430个
cmake:158个
a:99个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 121 浏览量
2024-12-14
17:32:40
上传
评论
收藏 124.56MB RAR 举报
温馨提示
源码:esp-now-ble- tesecode-20241214.rar
资源推荐
资源详情
资源评论
收起资源包目录
源码:esp-now-ble- tesecode-20241214.rar (2000个子文件)
libbt.a 15.36MB
libdriver.a 7.67MB
libwpa_supplicant.a 6.89MB
libmbedcrypto.a 6.49MB
liblwip.a 4.55MB
liblwip.a 4.54MB
libesp_hw_support.a 2.65MB
libhal.a 2.43MB
libnvs_flash.a 1.89MB
libmbedtls.a 1.72MB
libesp_system.a 1.4MB
libesp_system.a 1.4MB
libfreertos.a 1.14MB
libfreertos.a 1.14MB
libprotocomm.a 1.11MB
libconsole.a 1.06MB
libwifi_provisioning.a 1.05MB
libmbedx509.a 1.05MB
libspiffs.a 1.04MB
libspi_flash.a 1.01MB
libfatfs.a 900KB
libbootloader_support.a 884KB
libvfs.a 849KB
libbootloader_support.a 784KB
libbootloader_support.a 783KB
libheap.a 674KB
libesp_hid.a 672KB
libesp_netif.a 616KB
libnewlib.a 614KB
libsdmmc.a 608KB
libesp_adc.a 600KB
libesp_adc.a 600KB
libesp_http_server.a 589KB
libesp_http_server.a 589KB
libmqtt.a 575KB
libmqtt.a 575KB
libesp_lcd.a 546KB
libjson.a 531KB
libefuse.a 495KB
libefuse.a 495KB
libtcp_transport.a 491KB
libefuse.a 488KB
libesp_hw_support.a 478KB
libprotobuf-c.a 478KB
libprotobuf-c.a 478KB
libesp_eth.a 472KB
libesp_eth.a 472KB
libesp_http_client.a 453KB
libwear_levelling.a 434KB
libesp_wifi.a 407KB
libhal.a 380KB
libesp-tls.a 368KB
libesp_local_ctrl.a 357KB
libmain.a 345KB
libunity.a 335KB
libmicro-ecc.a 326KB
libhttp_parser.a 288KB
libpthread.a 281KB
libesp_gdbstub.a 279KB
libesp_gdbstub.a 279KB
libesp_ringbuf.a 243KB
libesp_mm.a 228KB
libesp_timer.a 210KB
libesp_event.a 201KB
libesp_phy.a 165KB
libesp_phy.a 165KB
libsoc.a 158KB
libsoc.a 156KB
libapp_update.a 156KB
libsoc.a 156KB
libesp_partition.a 140KB
libesp_https_ota.a 139KB
libmbedtls.a 129KB
libapp_trace.a 122KB
libesp_pm.a 103KB
liblog.a 100KB
libcxx.a 96KB
liblog.a 90KB
libespcoredump.a 51KB
libnvs_sec_provider.a 46KB
libnvs_sec_provider.a 46KB
libesp_coex.a 41KB
libriscv.a 33KB
libspi_flash.a 29KB
libesp_rom.a 29KB
libesp_rom.a 29KB
libesp_rom.a 28KB
libesp_common.a 28KB
libesp_common.a 28KB
libcmock.a 27KB
libcmock.a 27KB
libmain.a 22KB
libesp_system.a 17KB
libesp_common.a 14KB
libesp_app_format.a 14KB
libeverest.a 8KB
libesp_bootloader_format.a 6KB
libp256m.a 6KB
libesp_bootloader_format.a 6KB
app-flash_args 96B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Naiva
- 粉丝: 3w+
- 资源: 255
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- video_20241214_202420.mp4
- <数据集>种子发芽识别数据集<目标检测>
- a linux vmdk file
- nkhnjkgbjuhjg
- sjknxcjsdncxjk
- 海洋垃圾检测27-YOLO(v5至v9)数据集合集.rar
- 海洋垃圾检测25-YOLOv9数据集合集.rar
- 利用ESP-01S中继实现STM32F103C8T6与MQTT服务器的串口双向通信
- 海洋垃圾检测15-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- 海洋垃圾检测14-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功