Home › Forums › The libraries hosted on the site › EByte LoRa e220 UART devices LLCC68 › Questions about possible memory leak when using “receiveInitialMessage”
- This topic has 1 reply, 2 voices, and was last updated 2 years, 5 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
3 May 2023 at 18:44 #25580
Hi Renzo
I’m about to do tests using your excellent library.
When reading the documentation, I got a doubt when usingreceiveInitialMessage.In the library example, the Struct
MessageTemperatureandMessageHumidityare used.
For the receiver to identify the message (if about temperature or humidity) it is necessary to read the first part of the structchar type[5];.struct MessageTemperature { char type[5]; char message[8]; byte temperature[4]; }; struct MessageHumidity { char type[5]; char message[8]; byte humidity; }; char type[5]; // first part of structure ResponseContainer rs = e220ttl.receiveInitialMessage(sizeof(type));However, if the developer creates a third struct to report the distance, but with 7 bytes in the identifier:
char type[7]:
That would cause a “memory leak” or a bug in “receiveInitialMessage”, correct?struct MessageDistance { char type[7]; char message[8]; byte distance; };If the answer is yes, wouldn’t it be interesting if
receiveInitialMessagehad a behavior similar toreceiveMessageUntil, which would allow creating a delimiter for the field identifying the message?ResponseContainer receiveInitialMessage(const uint8_t size);
ResponseContainer receiveMessageUntil(char delimiter = '\0');Something like:
ResponseContainer rs = e220ttl.receiveInitialMessage(char delimiter = '\0');struct MessageTemperature msg_t {“TEMP\0”, …};
struct MessageHumidity msg_h {“HUMI\0”, …};
struct MessageDistance msg_d {“distan\0”, …};With this approach, there would be no danger of “memory leak” if the developer used a struct with an identification field larger than the receiveInitialMessage would be configured to read.
Am I talking nonsense or a mistake?
-
16 May 2023 at 08:59 #25738
Hi George,
I think the simple solution is to send a fixed TYPE and decode it to the receiver.
The message isn’t applicable on binary stream.
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.



