Binary encoding

I'm working under a project limitation that only allows me to send 10 bytes packages to communicate two components. I was wondering how could I use these 10 bytes more efficiently since I am only using integer numbers. My idea was to write it all in binary format so that instead of having only 10 ASCII characters per package I could have approx. 20 numbers per package. How can I do it and which problems I could expect to run into?

Thank you for your help!!

What ASCII characters are you sending?

If they are number only, you could send a nibble (1/2 byte) per number so that '255' for example could be 0x0255, 2 bytes instead of 3.

Well, I am trying to send packages through a LoRa WAN calling a function LoRa.print(number) that basically "writes" the 'number' variable on the network for a second device to read it. By doing this with '255' my package would contain 3 bytes and what I aim to do is to use only 12 bits for this specific case, like '0010 0101 0101' (character by character) or even '11111111' (whole value). This would allow me to pack more data into each package.
But I don't intend to mess with the LoRa library to solve this. I was wondering if it exists on Arduino something like:

package = DecToBinary(255);
LoRa.print(package);

Then on the other device:

received = LoRa.read();
package = BinaryToDec(received);

255 can fit in one byte

Try

LoRa.write(255);

Which LoRa library are you using. Doing this with write() and read() seems pretty low-level. I wouldn't be surprised if the library has higher-level functions allowing you to send an entire struct at once (as binary). If it doesn't, check out the RadioHead Library.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.