• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP-NOW Size payload

Q&A Forum › Category: ESP32 › ESP-NOW Size payload
0 Vote Up Vote Down
Henk van Beek asked 5 years ago

1. Why equals the len of myData 56
2. myData.p points to a string. When length of string varies, why does len of myData is constant ?

Question Tags: ESP-NOW myData struct
7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi Henk.
I don’t know.
I need to see your particular example to understand what might be wrong.
Can you share more details?
Regards,
Sara

0 Vote Up Vote Down
Henk van Beek answered 5 years ago

@Sara
ESP32 Sender Sketch (ESP-NOW)
=============================
This is the definition of myData as in the original
typedef struct struct_message {
char a[32];
int b;
float c;
String d;
bool e;
} struct_message;
ESP32 Receiver Sketch (ESP-NOW)
===============================
This is the definition of myData as in the original
typedef struct struct_message {
char a[32];
int b;
float c;
String d;
bool e;
} struct_message;
Now it works like this:
=======================
When I send:
strcpy(myData.a, “THIS IS A CHAR”);
myData.b = random(1,20);
myData.c = 1.2;
myData.d = “Hello”;
myData.e = false;
I receive this
Bytes received: 56
Char: THIS IS A CHAR
Int: 6
Float: 1.20
String: Hello
Bool: 0
Now I change in Sender only the payload:
<myData.d = “Hello”;> into <myData.d = “Hello_1234”;>
I receive this
Bytes received: 56
Char: THIS IS A CHAR
Int: 6
Float: 1.20
String: Hello_1234
Bool: 0
I can’t figure it out how this is possible.
the string is lenghtenend by 5 chars, len does not change.

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Can you tell me the exact example that you’re using?
Regards,
Sara

0 Vote Up Vote Down
Henk van Beek answered 5 years ago

@Sara
It is from course “Learn ESP32 with Arduino IDE”,
module 8, Unit 1 ESP-NOW: Getting Started

ESP32 Sender Sketch (ESP-NOW)

and

ESP32 Receiver Sketch (ESP-NOW)

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.
I’m sorry, but I don’t know why that happens.
Is that a critical point for some project that you’re trying to develop?
Regards,
Sara

0 Vote Up Vote Down
Henk van Beek answered 5 years ago

Hello Sara,
No no, its not very important. I do this course and I want understand.
That’s all
Thanks.
 

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi.

I’ve experimented in several different ways and I think it has to do with the String format itself.
I think when you try to send a string inside a structure it reserves a certain space for the string that is fixed. If you try to send a bigger string, you’ll see that it won’t receive it properly. And if you change the size of the string, the structure size will be the same.

However, if you change the size of the char variable inside the structure, you’ll see that it changes size.

I don’t know why this happens. But, we should avoid sending string variables and use char instead.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.