-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New examples Demonstrate: Fragmentation and Reassembly: - nrf24l01+ radios can tx/rx 32 bytes of data per transmission - RF24Network will fragment and re-assemble payloads of any size - Use of differing sized payloads using peek() function Also removed unneeded printf.h files (Located in RF24 library now)
- Loading branch information
Showing
7 changed files
with
179 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
examples/helloworld_rx_advanced/helloworld_rx_advanced.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright (C) 2020 TMRh20([email protected]) | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
*/ | ||
|
||
/** | ||
* More advanced example of using RF24Network: | ||
* Fragmentation and Reassembly: | ||
* - nrf24l01+ radios can tx/rx 32 bytes of data per transmission | ||
* - RF24Network will fragment and re-assemble payloads of any size | ||
* Demonstrates use of differing sized payloads using peek() function | ||
* | ||
* RECEIVER NODE | ||
* Every X milliseconds, send a payload to the receiver node. | ||
*/ | ||
|
||
#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 = 00; // Address of our node in Octal format ( 04,031, etc) | ||
const uint16_t other_node = 01; // Address of the other node in Octal format | ||
|
||
/**** Create a large array for data to be received **** | ||
* MAX_PAYLOAD_SIZE is defined in RF24Network_config.h | ||
* Payload sizes of ~1-2 KBytes or more are practical when radio conditions are good | ||
*/ | ||
uint8_t dataBuffer[MAX_PAYLOAD_SIZE]; //MAX_PAYLOAD_SIZE is defined in RF24Network_config.h | ||
|
||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("RF24Network/examples/helloworld_rx_advanced/"); | ||
printf_begin(); //Used to enable printf on AVR devices | ||
|
||
radio.begin(); | ||
network.begin(/*channel*/ 90, /*node address*/ this_node); | ||
radio.printDetails(); | ||
} | ||
|
||
// Variable for calculating how long between RX | ||
uint32_t timeBetweenPackets = 0; | ||
|
||
void loop(void){ | ||
|
||
network.update(); // Check the network regularly | ||
|
||
while ( network.available() ) { // Is there anything ready for us? | ||
|
||
RF24NetworkHeader header; // If so, grab it and print it out | ||
uint16_t payloadSize = network.peek(header); // Use peek() to get the size of the payload | ||
network.read(header,&dataBuffer,payloadSize); // Get the data | ||
Serial.print("Received packet, size "); // Print info about received data | ||
Serial.print(payloadSize); | ||
Serial.print("("); | ||
Serial.print(millis()-timeBetweenPackets); | ||
Serial.println("ms since last)"); | ||
timeBetweenPackets = millis(); | ||
// Uncomment below to print the entire payload | ||
/*for(uint32_t i=0;i<payloadSize;i++){ | ||
Serial.print(dataBuffer[i]); | ||
Serial.print(":"); | ||
if(i%50 == 49){Serial.println();} //Add a line break every 50 characters | ||
} Serial.println();*/ | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
examples/helloworld_tx_advanced/helloworld_tx_advanced.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright (C) 2020 TMRh20([email protected]) | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
*/ | ||
|
||
/** | ||
* More advanced example of using RF24Network: | ||
* Fragmentation and Reassembly: | ||
* - nrf24l01+ radios can tx/rx 32 bytes of data per transmission | ||
* - RF24Network will fragment and re-assemble payloads of any size | ||
* Demonstrates use of differing sized payloads using peek() function | ||
* | ||
* TRANSMITTER NODE | ||
* Every X milliseconds, send a payload to the receiver node. | ||
*/ | ||
|
||
#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 | ||
|
||
const unsigned long interval = 500; //ms // How often to send 'hello world to the other unit | ||
|
||
unsigned long last_sent; // When did we last send? | ||
|
||
/**** Create a large array for data to be sent **** | ||
* MAX_PAYLOAD_SIZE is defined in RF24Network_config.h | ||
* Payload sizes of ~1-2 KBytes or more are practical when radio conditions are good | ||
*/ | ||
uint8_t dataBuffer[MAX_PAYLOAD_SIZE]; | ||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("RF24Network/examples/helloworld_tx_advanced/"); | ||
printf_begin(); //Used to enable printf on AVR devices | ||
|
||
radio.begin(); | ||
network.begin(/*channel*/ 90, /*node address*/ this_node); | ||
radio.printDetails(); | ||
|
||
// Load our data buffer with numbered data | ||
for(uint16_t i=0;i<MAX_PAYLOAD_SIZE;i++){ | ||
dataBuffer[i] = i % 256; //Ensure the max value is 255 | ||
} | ||
} | ||
|
||
uint16_t sizeofSend = 0; //Variable to indicate how much data to send | ||
bool stopSending = 0; //Used to stop/start sending of data | ||
|
||
void loop() { | ||
|
||
//User input anything via Serial to stop/start data transmission | ||
if(Serial.available()){ | ||
Serial.read(); | ||
stopSending = !stopSending; | ||
} | ||
|
||
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 && !stopSending ){ | ||
last_sent = now; | ||
Serial.print("Sending size "); | ||
Serial.print(sizeofSend ); | ||
|
||
// Fragmentation/reassembly is transparent. Just send payloads as usual. | ||
RF24NetworkHeader header(/*to node*/ other_node); | ||
bool ok = network.write(header,&dataBuffer,sizeofSend++); | ||
|
||
// If the size of data to be sent is larger than max payload size, reset at 0 | ||
if(sizeofSend > MAX_PAYLOAD_SIZE){ | ||
sizeofSend = 0; | ||
} | ||
|
||
if (ok) | ||
Serial.println(" ok."); | ||
else | ||
Serial.println(" failed."); | ||
} | ||
} |