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

Sending array of bytes #3

Open
JMartinezEco opened this issue Nov 21, 2024 · 1 comment
Open

Sending array of bytes #3

JMartinezEco opened this issue Nov 21, 2024 · 1 comment

Comments

@JMartinezEco
Copy link

Hello!

First of all I want to thank you for the work you have done porting this library to Python for Raspberry Pi. You have done a great job.

I was already using your library for Arduino, which worked great, and I had to make one for Raspberry Pi. As soon as I saw this version I decided to make the effort to transfer everything I had to this library because I think it will be worth it.

The problem or doubt that I am having is the following:

My goal is to send an array of bytes from a Raspberry Pi to an Arduino and vice versa. The second part, from Arduino to Raspberry Pi was already working previously, and I used your library as follows.

//C++
// Send message via Lora
LoRa_Module.sendFixedMessage(addH, addL, chn, (uint8_t *)bytes_response, len_response);

where bytes_response is declared as:

byte bytes_response[70];

My target is the same on the Raspberry Pi, but I see that there are two methods implemented:

lora.send_fixed_message(add_h, add_l, ch, message).
y
lora.send_fixed_dict(ADDH, ADDL, CHAN, dict_message)

I understand that the dictionary version is not the one I am looking for, but the message version.

Is it possible to send an array of bytes from the Raspberry without String as it seems to be needed?

My objective in Python is something like:

# Python
full_request = [0x01, 0x034, 0x04]
response_code = lora.send_fixed_message(0x1, 0x9F, 0x06, full_request)

Thank you so much in advance.

@JMartinezEco
Copy link
Author

Well. I managed to get it work.

My code is like the following:

response_code = lora.send_fixed_message(add_h, add_l, channel, bytearray(full_request))

The problem comes inside the library:

`def _send_message(self, message, ADDH=None, ADDL=None, CHAN=None) -> ResponseStatusCode:
result = ResponseStatusCode.E32_SUCCESS

    size_ = len(message.encode('utf-8'))
    if size_ > MAX_SIZE_TX_PACKET:
        return ResponseStatusCode.ERR_E32_PACKET_TOO_BIG

Here, you can't encode as utf-8 a bytearray in "size_ = len(message.encode('utf-8'))"

If I just put the following:

      # If message is a byte array, we need to check the size
        if isinstance(message, bytearray):
            size_ = len(message)
        else:
            size_ = len(message.encode('utf-8'))

Do you consider this optimal?
Could be any other possible way to do it better or outside your library?

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