Getting the NodeID in a RF12 packet

I’m setting up a wsn and each sensor node will have a different packet. I’m using a bitwise field to define the packets. For example:

typedef struct{
 int temp1;
 int temp2;
 int temp3;
 int VBatt;
 int BattStatus;
 int retries;
}
Payload;
Payload m;  // m = measurement

So it is easy to send and decode at the main RF12-to-Ethernet board. The problem was trying to differentiate between packets at the receiver. I first used rf12_len to differentiate, but that isn’t scalable as I could easily get packets of the same size. In the end, I had to dig around to figure out how to send the sender’s node ID.

Turns out that the JCW@Jeelabs wants to keep everything light and minimal (a great viewpoint!). But sometimes, it means almost too light. The header packet can only have the senderID or the receiverID — not both. If you send a packet with the RF12_HDR_ACK like this:

 rf12_sendStart(RF12_HDR_ACK,&m,sizeof m);

Then the packet has the sending node’s ID in it. I would assume that this means it then is a broadcast packet, since it doesn’t have the receiver’s ID. Not too much of an issue in my case, since none of the other nodes are waiting for anything but ACKs.

On the receiving end, you can get the sender ID by:

int SenderID = (RF12_HDR_MASK & rf12_hdr);

Then you can do an if/else switch to handle the packets differently.

I would much prefer to have the sender and receiver IDs in the packet…seems worth it to add one more byte to the header so we can do that plus have a packet counter for retries.

Tags: ,