We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在onReceive的回调函数中的数据貌似有点奇怪?和随机?请看截图
// ESP_NOW_Broadcast_Peer.h #ifndef ESP_NOW_BROADCAST_PEER_H #define ESP_NOW_BROADCAST_PEER_H
#include "ESP32_NOW.h" #include "lvgl/gui_ctl.h" #include "logger.h"
// DeviceType enum DeviceType { READER, // 读卡器 GATEWAY, // 网关 METER, // 流量计 CONFIG_TOOL // 配置工具 };
// 数据结构体 typedef struct struct_espnow_data { int id; // 包编号 DeviceType type = READER; // 设备类型 char card_id[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // 卡号 double flowSpeed = 0.0; // 流量速度l/min bool recvOk = false; // 接受成功 int channel = 0; // 信道 char mac[18] = "FF:FF:FF:FF:FF:FF"; // Mac
} struct_espnow_data;
// 创建一个新的类继承自ESP_NOW_Peer类 class ESP_NOW_Peer_Class : public ESP_NOW_Peer { private: public: // 类的构造函数 ESP_NOW_Peer_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) : ESP_NOW_Peer(mac_addr, channel, iface, lmk) {}
// 类的析构函数 ~ESP_NOW_Peer_Class() {} const esp_now_recv_info_t *info; // 函数用于注册主机 bool add_peer() { if (!add()) { Serial.printf("注册广播主机失败\n"); return false; } return true; } // 向对等点设备发送消息 bool send_message(const uint8_t *data, size_t len) { if (!send(data, len)) { Serial.printf("单播消息失败\n"); return false; } return true; } // 函数用于打印从主机接收到的消息 void onReceive(const uint8_t *data, size_t len, bool broadcast) { for (size_t i = 0; i < 64; i++) { Serial.printf("%d ", i); } Serial.println(); } // 显示发送状态 void onSent(bool success) { if (success) { Logger::log("Send Success\n"); Gui_Add_List_Text(guider_ui.blueCounter_list_Info, "Send Success", 26, COLOR_GREEN); } else { Logger::log("Send Failed\n"); Gui_Add_List_Text(guider_ui.blueCounter_list_Info, "Send Failed", 26, COLOR_RED); } }
}; #endif // ESP_NOW_BROADCAST_PEER_H
The text was updated successfully, but these errors were encountered:
@lnsane-G
Serial.printf("%d ", i);
Should this be Serial.printf("%d ", data[i]); ?
Serial.printf("%d ", data[i]);
Sorry, something went wrong.
zhangyanjiaoesp
No branches or pull requests
Answers checklist.
General issue report
在onReceive的回调函数中的数据貌似有点奇怪?和随机?请看截图
// ESP_NOW_Broadcast_Peer.h
#ifndef ESP_NOW_BROADCAST_PEER_H
#define ESP_NOW_BROADCAST_PEER_H
#include "ESP32_NOW.h"
#include "lvgl/gui_ctl.h"
#include "logger.h"
// DeviceType
enum DeviceType
{
READER, // 读卡器
GATEWAY, // 网关
METER, // 流量计
CONFIG_TOOL // 配置工具
};
// 数据结构体
typedef struct struct_espnow_data
{
int id; // 包编号
DeviceType type = READER; // 设备类型
char card_id[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // 卡号
double flowSpeed = 0.0; // 流量速度l/min
bool recvOk = false; // 接受成功
int channel = 0; // 信道
char mac[18] = "FF:FF:FF:FF:FF:FF"; // Mac
} struct_espnow_data;
// 创建一个新的类继承自ESP_NOW_Peer类
class ESP_NOW_Peer_Class : public ESP_NOW_Peer
{
private:
public:
// 类的构造函数
ESP_NOW_Peer_Class(const uint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, const uint8_t *lmk) : ESP_NOW_Peer(mac_addr, channel, iface, lmk) {}
};
#endif // ESP_NOW_BROADCAST_PEER_H
The text was updated successfully, but these errors were encountered: