使用ESP_NOW发送数据

发布于 2025-01-28 05:48:41 字数 1179 浏览 5 评论 0原文

通常,当我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极度宠爱 2025-02-04 05:48:41

如果您只是尝试发送100个双重精确浮子,这将做到这一点:

int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));

for (int i=0; i < sizee; i++) {
    by[i]=i;
    Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) by, sizee*sizeof(double));

接收器必须是回调,对吗?这样的事情:

void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  double *by=(double*)incomingData;
  Serial.print("rearray=: ");
  for(int i=0;i<100;i++){
    Serial.print(by[i]);
  }
  Serial.println();
} 

我不知道serial.print可以处理双打。您必须检查一下。

If you are simply trying to send 100 double-precision floats, this will do it:

int sizee=100;
double *by=(double*)malloc(sizee*sizeof(double));

for (int i=0; i < sizee; i++) {
    by[i]=i;
    Serial.println(by[i]);
}
esp_err_t result = esp_now_send(0, (uint8_t *) by, sizee*sizeof(double));

The receiver has to be a callback, right? Something like this:

void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
  double *by=(double*)incomingData;
  Serial.print("rearray=: ");
  for(int i=0;i<100;i++){
    Serial.print(by[i]);
  }
  Serial.println();
} 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文