Notifications
Clear all

Convert struct_message myData back to original format

6 Posts
2 Users
0 Likes
598 Views
 Otto
(@otto)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

Have two ESP32 units, using sketch Code from DroneBot Workshop.  Sending myData successfully to receiving unit and printing on LCD screen successfully.  How do I get the "myData.x" converted back to the original form so I can make decisions/calculations within the receiving unit?

 

// Define a data structure

typedef struct struct_message {

  char a[32];

  int b;

  float c;

  bool d;

} struct_message;




// Create a structured object

struct_message myData;

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

Posted by: @otto

Have two ESP32 units, using sketch Code from DroneBot Workshop.  Sending myData successfully to receiving unit and printing on LCD screen successfully.  How do I get the "myData.x" converted back to the original form so I can make decisions/calculations within the receiving unit?

 

// Define a data structure

typedef struct struct_message {

  char a[32];

  int b;

  float c;

  bool d;

} struct_message;




// Create a structured object

struct_message myData;

Not sure what you mean, if you mean working with the individual fields, then syntax like myData.b can be read or changed if on other side of the equation. Is that what you wanted to know?

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
 Otto
(@otto)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

Not quite following your reply.  Please give an example about the "other side of the equation".  e.g. : a=myData.a


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@otto To retrieve data from the structure you would code

b = myData.b;

To store data in the structure you would code

myData.b = b;

Where b is int and myData.b is int

Clear?

of course the char array a requires a little more work, but by now you should understand what is needed.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
 Otto
(@otto)
Member
Joined: 3 years ago
Posts: 6
Topic starter  

Ron, thanx very much.  Have put the equations into the code, but haven't had time to test yet, thanks again


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@otto Just remember the char array will need appropriate strxxxx or memxxx helpers depending on if the array is really just a char array or is actually a string. Then you must deal with if the string is /0 terminated or not. I am old school but understand there are C++ things to deal with that situation that I am only vaguely aware of. Perhaps one of our C++ members will chime in.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote