Close

Packet Structure

A project log for $0.87 WiFi for Raspberry Pi and Arduino Projects

My project goal is to make internet access for micro controllers dirt cheap and dead simple to implement in your own projects.

surfingstevesurfingsteve 08/20/2014 at 06:060 Comments

The maximum size that a RF24L01+ can transmit is 32 bytes.  An ethernet frame can contain up to 1500 bytes.  We need to define a very simple protocol that will allow us to transmit the larger 1500 byte ethernet frames over the limited 32 byte messages that are sent via the RF24L01+.  

The full Ethernet frame is broken up to small 29 byte size packets to transmit over the wireless link. The additional 3 bytes of overhead are used to help reassemble the frame on the receiving end of the link.  A random ID is generated to identify the packets belonging to the same frame.  We rely on the CRC that is already generated by the RF24L01+ to ensure the messages we receive are correct.  This is acceptable because the RF24L01+ has a mode that automatically calculates and sends a CRC with the transmission of every 32 byte packet.  When the 32 byte packet is received on the other end the CRC is checked, and if found to be incorrect it is automatically re-requested before passing the data to us.   An additional CRC in our code would be wasteful overhead.

Structure

*The count variable is an integer index for each of the RF24L01+ transmitted packets.  For example, [0,1,2,3...n].  This helps the receiving end place the data from each RF24L01+ packet into the correct location of the reassembled ethernet frame.  The only exception is with the "last" 29 byte packet.  If the last flag is set to 1, then the count variable identifies how many bytes are contained in this last packet.  The rest of the packet will be 0 padded.

Example - ethernet frame (the data used here is gibberish)

(0x00 repeated 29 times) (0x01 repeated 29 times) (0x02 repeated 4 times)

- or -

0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x02 0x02 0x02 0x02

This results in being parsed into:

nRF24 packet 0 - 0xba 0x02 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
nRF24 packet 1 - 0xba 0x02 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
nRF24 packet 2 - 0xba 0x02 0x44 0x02 0x02 0x02 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00


packet 1

0xba 0x02 - random packet id

0x80 - start bit 7 set, stop bit 6 cleared, count = 0 (packet index)

0x00 repeated 29 times - data payload


packet 2

0xba 0x02 - random packet id

0x01 - start bit 7 cleared, stop bit 6 cleared, count = 1 (packet index)

0x01 repeated 29 times - data payload


packet 3

0xba 0x02 - random packet id

0x01 - start bit 7 cleared, stop bit 6 set, count = 4 (valid bytes in this last packet)

0x02 0x02 0x02 0x02 (0x00 repeated 25 times)  - data payload, only first 4 bytes valid

Notice how the random packet id is the same id for each ethernet frame.  The packet only changes with each new ethernet frame.  This allows us to have multiple nodes broadcasting segments of different ethernet frames to the root node and still provide the root node with enough information to reassemble the frames.

Discussions