/*
  Requires the following libraries:
  RF24 by TMRh20, Avamander

  Connections:
    Arduino Board | NRF24L01+
    Pin 7         | CE
    Pin 8         | CSN
    3.3V          | V+
    GND           | GND
    // For the following pins check a pinout of your board
    SCK           | SCK
    MISO          | MISO
    MOSI          | MOSI
*/

#include <SPI.h>
#include "RF24.h"

// Radio Transmitter - NRF24

RF24 radio(7, 8); // using pin 7 for the CE pin, and pin 8 for the CSN pin
uint8_t rocketAddress[] = "ROCKT";

const int payloadSize = 12; // *
const int payloadSizeP1 = payloadSize + 1;

char data[payloadSizeP1];

void setup() {
  Serial.begin(115200);

  data[payloadSize] = 10;

  // Configure Radio Transmitter - NRF24
  
  if (!radio.begin()) {
    Serial.println(F("Radio hardware not responding"));
    while (1) {} // hold in infinite loop
  }

  if (!radio.isChipConnected()){
    Serial.println("NRF24L01 connection failed");
    while (1) {}; 
  }
  
  radio.setPALevel(RF24_PA_LOW);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);

  // This node receives data
  radio.openReadingPipe(1, rocketAddress);

  radio.startListening();

  delay(500);
}

void loop() {
  if (radio.available()){
    radio.read(data, payloadSize);
    Serial.write(data, payloadSizeP1);
  }
}
