Optimized RF24Network Layer v2.0.0
2024 - Optimized RF24 Network Layer for NRF24L01 & NRF52x radios
Loading...
Searching...
No Matches
Network_Priority_TX.ino

An example of handling/prioritizing different types of data passing through the RF24Network

#include <RF24.h>
#include <RF24Network.h>
#include "printf.h"
RF24 radio(7, 8); // nRF24L01(+) radio attached using Getting Started board
RF24Network 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
uint8_t dataBuffer[33];
void setup() {
Serial.begin(115200);
printf_begin(); // needed for RF24* libs' internal printf() calls
while (!Serial) {
// some boards need this because of native USB capability
}
Serial.println(F("RF24Network/examples/Network_Separation_TX/"));
if (!radio.begin()) {
Serial.println(F("Radio hardware not responding!"));
while (1) {
// hold in infinite loop
}
}
radio.setChannel(90);
network.begin(/*node address*/ this_node);
radio.printDetails();
// Load our data buffer with numbered data
for (uint16_t i = 0; i < 33; i++) {
dataBuffer[i] = i;
}
} //setup
uint32_t sendTimer = 0;
/*
* The main loop sends two types of data to be processed with different priority per the RX
* example
*/
void loop() {
network.update();
if (millis() - sendTimer > 1000) {
sendTimer = millis();
Serial.println(F("Sending data..."));
// Sending of External data, which will be handled immediately
bool ok = network.write(header, &dataBuffer, 33);
Serial.println(ok ? F("OK 1") : F("Fail 1"));
// Sending normal user data, which may be buffered and handled later
RF24NetworkHeader header2(other_node, 32);
uint32_t someVariable = 1234;
ok = network.write(header2, &someVariable, sizeof(someVariable));
Serial.println(ok ? F("OK 2") : F("Fail 2"));
}
// Dummy operation to read 0 bytes from all incoming user payloads
// Ensures the buffer doesnt fill up
if (network.available()) {
network.read(header, &dataBuffer, 0);
}
} //loop
Definition RF24Network.h:384
#define EXTERNAL_DATA_TYPE
Definition RF24Network.h:103
Definition RF24Network.h:229