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

Reading strings and converting C++ structs #25

Open
stoopfrench opened this issue Oct 19, 2020 · 2 comments
Open

Reading strings and converting C++ structs #25

stoopfrench opened this issue Oct 19, 2020 · 2 comments
Labels
question Further information is requested

Comments

@stoopfrench
Copy link

Do you have any insight into how to use this library to read strings sent from a radio on an arduino? It's simple enough to read an integer sent from the arduino radio but I cant figure out how to convert the buffer in node back into a string - I've tried node Buffers .toString() method but nothing gets returned.

I was also wondering if you have any idea how to send something from this library that could be used as a struct on the arduino side? I've passed structs between different radios running on arduinos but I cant figure out how to create a buffer in node that could be used as a struct when sent to an arduino.

So far the library is great! Thanks for any help.

@ludiazv ludiazv added the question Further information is requested label Oct 19, 2020
@ludiazv
Copy link
Owner

ludiazv commented Oct 19, 2020

Hi @stoopfrench
The library works at link level. It only enable to send/receive frames. The frame payload is a binary blob. How to treat it is application specific. Converting a C null-terminated string in ascii is easy, iterate over the received buffer until you find '\0' and don't forget to send the null char from the Arduino.

I do not recommend to send C/C++ structs directly over the radio. There are many factors that affect the result: mcu/compiler endianess, struct alignment, struct packaging. This depend on the compiler options and pragmas used in the Arduino. There are ,however, npm modules that enable you to interpret the buffer with a struct semantic like python pack/unpack.

I prefer to define the format of the frame and construct the frame explicitly. And then decode it explicitly on the other side. I use this library for sensors and I use standard CayenneLPP format. There are nodejs decoders/encoders and arduino libraries to encode/decode this format.

@stoopfrench
Copy link
Author

@ludiazv

Thanks for the info! CayenneLPP was the key to solving my problems - i had never heard of it. Again, thanks for the library!

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

No branches or pull requests

2 participants