nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
Loading...
Searching...
No Matches
examples/RF24Network/helloworld_txEncryption/helloworld_txEncryption.ino
#include <nrf_to_nrf.h>
#include <RF24Network.h>
//Set up our encryption key
uint8_t myKey[16] = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6};
nrf_to_nrf radio; // nRF24L01(+) radio attached using Getting Started board
RF52Network network(radio); // Network uses that radio
const uint16_t this_node = 01; // Address of our node in Octal format
const uint16_t other_node = 00; // Address of the other node in Octal format
const unsigned long interval = 2000; // How often (in ms) to send 'hello world' to the other unit
unsigned long last_sent; // When did we last send?
unsigned long packets_sent; // How many have we sent already
struct payload_t { // Structure of our payload
unsigned long ms;
unsigned long counter;
};
void setup(void) {
Serial.begin(115200);
while (!Serial) {
// some boards need this because of native USB capability
}
Serial.println(F("RF24Network/examples/helloworld_tx/"));
if (!radio.begin()) {
Serial.println(F("Radio hardware not responding!"));
while (1) {
// hold in infinite loop
}
}
radio.setKey(myKey); // Set our key and IV
radio.enableEncryption = true; // Enable encryption
radio.enableDynamicPayloads(123); //This is important to call so the encryption overhead will not be included in the 32-byte limit
//To overcome the 32-byte limit, edit RF24Network.h and set MAX_FRAME_SIZE to 111
radio.setChannel(90);
network.begin(/*node address*/ this_node);
}
void loop() {
network.update(); // Check the network regularly
unsigned long now = millis();
// If it's time to send a message, send it!
if (now - last_sent >= interval) {
last_sent = now;
Serial.print(F("Sending... "));
payload_t payload = { millis(), packets_sent++ };
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header, &payload, sizeof(payload));
Serial.println(ok ? F("ok.") : F("failed."));
}
}
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition nrf_to_nrf.h:115
void setChannel(uint8_t channel)
void setKey(uint8_t key[CCM_KEY_SIZE])
bool begin()
bool enableEncryption
Definition nrf_to_nrf.h:470
void enableDynamicPayloads(uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE)