Author Topic: RFM69 lib correction regarding the max message length [addressed]  (Read 4705 times)

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
I was a little bit confused when playing with various message lengths, so I presume a small correction may be necessary in the RFM69.h library.

In the RFM69.h the maximum length is defined as:

#define RF69_MAX_DATA_LEN       61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2

The actual values (from the specs) are:
For variable length packets with AES, no Address filtering, and Address Byte enable(?), the maximum payload is 66 Bytes with a minimum 2 Bytes
The RFM69 header takes:
- 1 Byte by default used for the Payload length and 1 Bytes for the Address Byte (the "To address")  (so far 2 Bytes)
- 2 other Bytes are used; 1 for the the "From Address" and one for the "Control Byte" (so 2 extra Bytes)
- CRC is not part of the payload!

The result is 66-4 = 62 Bytes and not 61 as stated!

Now if address filtering is used the maximum payload is limited to 50 Bytes and taking into account the RFM69 Header (4 Bytes),the actual data message is limited to 46 Bytes.

At least this is my understanding of the specifications, and the result of my tests.

Regard,
Robert
« Last Edit: July 22, 2015, 07:53:46 AM by Felix »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Small correction proposed regarding the maximum message length
« Reply #1 on: July 20, 2015, 07:48:09 AM »
I think you neglected to include the Network Id in your summary of header bytes, hence 61.  Address filtering isn't used.
This link has the entire packet identified near the bottom of the page: http://lowpowerlab.com/blog/2013/06/20/rfm69-library/#more-917

Tom
« Last Edit: July 20, 2015, 07:52:41 AM by TomWS »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Small correction proposed regarding the maximum message length
« Reply #3 on: July 20, 2015, 09:10:01 AM »
Felix
The Network ID is part of the SYNC bytes not part of the payload.

See also HopeRF document  (see attached image)

Robert

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Small correction proposed regarding the maximum message length
« Reply #4 on: July 20, 2015, 10:45:20 AM »
Reading from that spec I can say that address filtering is not used.
But I see your point that there might be a debate about 1 byte here. I would need to investigate but back when I implemented this I think I've already done it, It's possible I missed something, but I think I arrived at 61 bytes for a good reason.
I would not really advise to use the lib to send the max possible data at 1 time though, it's a lot of bytes and better chances of corruption etc. However 61 vs 62 bytes is not a big difference.
Another thing I have been wanting to enable is data whitening. That would break any deployed nodes, but would help make the messages DC-free, but beside the point of this thread.

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Small correction proposed regarding the maximum message length
« Reply #5 on: July 20, 2015, 11:45:39 AM »
Felix,
I agree that the documentation is unclear about "how to enable the Address Byte", but I know it is used while testing the address filtering option.
An easy test is to send 61, 62, 63 bytes (with encryption), you will see that the script stops ending with a size of 63, not 62 Bytes (so 62 is a valid value).
The same is true with address filtering, 46 is OK, 47 is too much.
Robert

NB: Regarding data whitening or  manchester coding I think it should be a good idea (look at the RadioHead (RF_69) library which allows a lot of possible combinations)
See
http://www.ti.com/lit/an/swra322/swra322.pdf
 http://www.silabs.com/Support%20Documents/TechnicalDocs/AN537.pdf

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Small correction proposed regarding the maximum message length
« Reply #6 on: July 20, 2015, 08:14:55 PM »
To give finality to this thread, the conclusion based on my tests is that 61 is actually the real max length of the data part of the payload based on the header I presented above. Trying to send a 62 byte payload with RF69_MAX_DATA_LEN=62 does not work.
If you want to implement your own encryption you can go up to 255 bytes. Also you may drop a header byte or two if you need 62 or 63 bytes.

For reference, from section 5.5.5.2. Rx Processing:

In Fixed length mode the Message part of the payload that can be encrypted/decrypted can be 64 bytes long. If the
address filtering is enabled, the length of the payload should be at max 65 bytes in this case.
In Variable length mode the Max message size that can be encrypted/decrypted is also 64 bytes when address filtering is
disabled, else it is 48 bytes. Thus, including length byte, the length of the payload is max 65 or 50 bytes (the latter when
address filtering is enabled).
« Last Edit: July 21, 2015, 09:52:58 AM by Felix »

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Small correction proposed regarding the maximum message length
« Reply #7 on: July 22, 2015, 03:30:12 AM »
Felix,

You are right, the size of the FIFO is limited to 65 Bytes when Address filtering is disabled (RFM69 Library default configuration). With a header of 4 Bytes (Length, To address, From address, CTRL Byte) the maximum message length is then 61 Bytes.

The FIFO size is extend to 66 Bytes when Address filtering is enabled (case I was tested! and the reason of my confusion).

Sorry about that.
Robert