完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我们正在进行一个需要 ESP8266 之间通信的项目。我们使用 ESPNOW 在我们的 ESP 之间发送 MAC 地址。我们的目标是分享这一点,并为其他人提供一种在 ESP8266 上使用 ESPNOW 的简单方法。我们期待阅读您对此主题的评论。
代码:全选/* Super Simple Minimalist Easy ESPNOW This is an easy way to communicate between ESP8266s. *no error checking *no encryption *broadcast only *unlimited number of transceivers *Six bits+Five bytes of sender id and/or payload(two low order bits of first byte are reserved) *250 bytes of optional payload Aaron Chand Tim Hayward License: MIT License */ #include #include uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; /* Optional Custom MAC Address uint8_t newMACAddress[] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44}; */ bool OkayToSend; //Sending is Complete typedef struct struct_message { //structure example to send data //must match the receiver structure char a[250]; } struct_message; struct_message myData; // create a data structure called myData char s [32]; void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) { //receive data memcpy(&myData, incomingData, sizeof(myData)); char macStr[18]; Serial.print("Data received"); snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); Serial.print(macStr); Serial.print("\t"); Serial.println(myData.a); } void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) { OkayToSend = true; } void setup() { Serial.begin(115200); //Init Serial Monitor Serial.println("Super Simple Minimalist Easy ESPNOW"); WiFi.mode(WIFI_STA); //Set Device as a WiFi Station WiFi.disconnect(); /* Uncomment to Set Custom MAC Address wifi_set_macaddr(STATION_IF, &newMACAddress[0]); */ esp_now_init(); //init ESPNOW esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(OnDataSent); esp_now_register_recv_cb(OnDataRecv); esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0); //add peer } void loop() { strcpy(myData.a,"THIS IS THE PAYLOAD"); //set values to send while (!OkayToSend){} OkayToSend = false; esp_now_send(0, (uint8_t*) &myData, sizeof(myData)); // send a message delay(100); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
180个成员聚集在这个小组
加入小组448 浏览 1 评论
1443 浏览 1 评论
615浏览 6评论
511浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
489浏览 5评论
493浏览 4评论
478浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-2-1 03:56 , Processed in 0.594587 second(s), Total 45, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号