I have connected two nrf24l01+
modules using tmrh20 library. I'd like to implement the following scenario:
1. A sends a payload packet to B
2. B receives the payload packet
3. B responds with an ACK packet
4. A receives the ACK packet
5. A sends an ACK packet to B
6. B receives the ACK packet
Right now I can implement this up to step 4 by simply using this code on the sender:
bool delivered = radio.read(&message, sizeof(Message));
Is there a way to implement other steps without changing roles and writing lots of additional code? Or does the library provides some easy way of doing this?
You can send the ACK (which is described in step5) by putting in the payload. It might be necessaray to wrap your payload with a tiny header. This header can be used to indicate that it is data or second ACK.
#define MAX_PAYLOAD_DATA_SIZE (10u)
typedef enum packet_type{
DATA_PACKET,
ACK_PACKET,
PACKET_MAX
}packet_type_t;
typedef struct payload{
packet_type_t packetType;
uint8_t len;
uint8_t data[MAX_PAYLOAD_DATA_SIZE];
}payload_t;