#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <RF24/RF24.h>
using namespace std;
//
// Hardware configuration
//
// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS1,
BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0,
BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0,
BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate.
const uint8_t pipes[][6] = {"1Node"};
int main(int argc, char** argv){
// Setup and configure rf radio
radio.begin();
// Enable Payload with Ack function
radio.enableAckPayload(); //
Enable dynamic payload on pipes 0 & 1
radio.enableDynamicPayloads(); // Enable dynamic
payload on all pipes
radio.openReadingPipe(0,pipes[0]);
radio.startListening();
radio.printDetails();
// forever loop
unsigned long got_time;
uint8_t pipe;
static uint32_t message_count = 0;
while (1) {
if(radio.available(&pipe)){
radio.writeAckPayload( pipe, &message_count,
sizeof(message_count) );
message_count++;
radio.read(&got_time,
sizeof(unsigned long));
printf("pipe=%d
payload=%lu\n",pipe, got_time);
}
} // end while
}
|