使用ESP_NOW发送数据
通常,当我使用send_now
发送和接收数据时,我会使用本教程代码。通过这种方式,我面临一个问题,该问题正在声明一个数组,我需要在结构内声明大小,以确保发送和接收过程正确完成。虽然有时我需要发送一个数组,但我不知道它的大小是多少,例如,这个数组
double *arry=(double*)malloc(size*sizeof(double));
可以在不使用struct的情况下发送吗?还是我可以在结构内部宣布Arry []没有大小?然后指定尺寸?
发件人结构:
typedef struct test_struct {
int arry[]; I need to send this array but I do not know its size yet
} test_struct;
接收器结构:
typedef struct test_struct {
int arry[];
} test_struct;
更新: 我试图这样做,但我收到了不正确的价值 发件人中
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
for (int i=0; i < 100; i++) {
by[i]=i;
Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) &by, sizeof(double));
在接收器中
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
Serial.print("rearray=: ");
for(int i=0;i<100;i++){
Serial.print(by[i]);
}
Serial.println();
}
Normally when I send and receive data using a send_now
I use a structure as in this tutorial code. In this way, I face a problem, which is declaring an array where I need to declare size inside the structure to ensure that the sending and receiving process is done correctly. While sometimes I need to send an array I don't know what its size is, for example, this array
double *arry=(double*)malloc(size*sizeof(double));
So can I send without using struct? or can I declare the arry[] inside struct without its size? and then specify it size?
sender struct:
typedef struct test_struct {
int arry[]; I need to send this array but I do not know its size yet
} test_struct;
receiver struct:
typedef struct test_struct {
int arry[];
} test_struct;
UPDATE:
I trying to like this but I received uncorrect values
in sender
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
for (int i=0; i < 100; i++) {
by[i]=i;
Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) &by, sizeof(double));
In receiver
int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));
Serial.print("rearray=: ");
for(int i=0;i<100;i++){
Serial.print(by[i]);
}
Serial.println();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只是尝试发送100个双重精确浮子,这将做到这一点:
接收器必须是回调,对吗?这样的事情:
我不知道
serial.print
可以处理双打。您必须检查一下。If you are simply trying to send 100 double-precision floats, this will do it:
The receiver has to be a callback, right? Something like this:
I don't know whether
Serial.print
can handle doubles. You'll have to check that.ESP-NOW版本2允许1490字节。
更改您的图书馆并重新编译。
多一点 - V2将自动调整功率和TX速率,或者您可以过度骑行并选择缓慢的高功率连接,如果有足够的电源可用,或者如果电池从附近的电池运行,可以选择快速,低功率。
或任何适合您项目的东西。
Version 2 of ESP-NOW allows 1490 bytes.
Change your library and re-compile.
A little more - V2 will automatically adjust power and TX rate, OR you can over-ride this and choose a slow, high power connection if plenty of power is available, or choose fast, low power if battery operation from nearby.
Or whatever suits your project.