1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想结合 ESP-NOW 和 deepSleep 将数据从传感器发送到基本控制器。我的代码是:
代码:全选/******************************************************************** * ESP-NOW Sender using ESP8266 * ESP8266 Deep sleep mode, GPIO 16 connected to the RESET (RST) pin ********************************************************************/ #include #include #include // RECEIVER MAC Address uint8_t broadcastAddress[] = {0x18, 0xFE, 0x34, 0xD3, 0xB0, 0x4A}; // ESP8266 No.2: 18:FE:34:D3:B0:4A // Structure example to send data. Must match the receiver structure typedef struct struct_message { float Temp; float Pres; float Hum; } struct_message; // Create a struct_message called myData struct_message myData; // Callback when data is sent void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) { char macStr[18]; Serial.print(\"Packet to:\"); snprintf(macStr, sizeof(macStr), \"%02x:%02x:%02x:%02x:%02x:%02x\", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); Serial.print(macStr); Serial.print(\" Send status: \"); Serial.print(sendStatus); if (sendStatus == 0) { Serial.println(\" Delivery success\"); } else { Serial.println(\" Delivery fail\"); } } void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != 0) { Serial.println(\"Error initializing ESP-NOW\"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER); esp_now_register_send_cb(OnDataSent); // Register peer esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0); //esp_now_add_peer(broadcastAddress2, ESP_NOW_ROLE_SLAVE, 1, NULL, 0); // Set values to send myData.Temp = 25.1; myData.Pres = 1012.5; myData.Hum = 48.7; // Send message via ESP-NOW esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); // Deep sleep mode for 60 seconds, the ESP8266 wakes up by itself Serial.println(\"Going into deep sleep mode for 60 seconds\"); ESP.deepSleep(60e6); } void loop() {} 串行监视器上的输出片段是: 17:04:53.651 -> Packet to:18:fe:34:d3:b0:4a Send status: 1 Delivery fail 但是,当指令 ESP.deepSleep(60e6); 注释输出为: 15:52:42.622 -> Packet to:18:fe:34:d3:b0:4a send status: 0 Delivery success 有趣的是,在这两种情况下,接收方都能正确获取数据。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1143 浏览 1 评论
578浏览 6评论
479浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
463浏览 5评论
464浏览 4评论
440浏览 4评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 08:20 , Processed in 0.769441 second(s), Total 45, Slave 39 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号