Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appreciation letter to code author #2

Open
woodlist opened this issue May 10, 2020 · 0 comments
Open

Appreciation letter to code author #2

woodlist opened this issue May 10, 2020 · 0 comments

Comments

@woodlist
Copy link

woodlist commented May 10, 2020

The code usage was successful on ESP8266 core platform too, as message originator and sender.
Problems took place on receiption side, relaized on ESP32, but not due to introduced library itself.
Most convenient and short interpretation of receiption job for me was the following code for message sending via UART:
for(uint i = 0; i < sizeof(encoded); i++) { mySerial.print(encoded[i]); } mySerial.print('\n');
and beneath for the receiption:
if (Serial1.available()) encoded = Serial1.readStringUntil('\n');
Byte by byte reading on receiption side was not successful and data integrity has been suffered with unknown reason. In meantime the "readStringUntil" function performed well enough.
Having sent for example, 10 byte (5 as original message content and 5 additional, which generates the encoder library) and termination EOL, I got 12 bytes on the rest. One byte is the NULL, which has every string by definition. On receiving side we are not able to use the string as decoding function argument, due to variable type itself and two additional bytes presence: NULL and EOL.
Neither of Ardunio or C++ string to char array function were able to convert the string to char array.

1. Arduino: myString.toCharArray(buf, len)
2. C++: sprintf(rawleft, "%.9s", encodedleft.c_str());
3. C++: strncpy(rawleft, encodedleft.c_str(), 9);

Even encoded bytes were not possiple to copy and transfer to somewhere by computer's clipboard from serial monitor terminal. An simple task, namely, the string to char convertation became as a BIG trouble.
The solution found accidentally, upon some days long hardwork.
if (Serial1.available()) encodedleft = Serial1.readStringUntil('\n'); for (uint i = 0; i < 10; i++) { rawleft[i] = encodedleft[i]; }
The "rawleft" has been declared globally, as char array and the "encodedleft"-as a string variable accordingly. It is was an eyeopening subject for me that the string can be accessed char by char, by index. So, this method has solved the task, having copied the string to char array, bypassed last two bytes transfer to char array.
Thanks to author for good job.
A question however I have to bring up. What is the optimal relation between original message lenght and additional bytes lenght?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant