I can transfer data between 2 arduino using rf24network library. Now, i want to add another arduino, so i will have the base 00, the parent 01 and the leaf 011. I have anything to control on the parent arduino, except to pass the communication from the leaf or from the base. The question is: What should i put in the loop ? I tried to put only network.update(), but it didn't work. I am new to programming this thing. Is there somebody to give me help please ?
All you should need in the loop is network.update(); for a relay node. Probably best to test all the nodes, double check addressing, etc.
I think you're right, it must be an addressing problem, but i still can't see what i am doing wrong ?
in the master i put that:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t node0 = 0;
// Address of the other node
const uint16_t node11 = 11;
const uint16_t node1 = 1;
// Structure of our payload
struct payload_t
{
unsigned long ms;
unsigned long counter;
};
void setup(void)
{
Serial.begin(9600);
Serial.println("RF24Network/examples/helloworld_rx/");
SPI.begin();
radio.begin();
network.begin(/channel/ 90, /node address/ node0);
}
void loop(void)
{
// Pump the network regularly
network.update();
// Is there anything ready for us?
while ( network.available() )
{
// If so, grab it and print it out
RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload));
Serial.print("Received packet #");
Serial.print(payload.counter);
Serial.print(" at ");
Serial.println(payload.ms);
}
}
in the node 1 i have this:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(9,10);
RF24Network network(radio);
const uint16_t node1 = 1;
const uint16_t node0 = 0;
const uint16_t node11 = 11;
void setup(void)
{
Serial.begin(9600);
Serial.println("Rf24Network Relay");
SPI.begin();
radio.begin();
network.begin(/channel/ 90, /node address/ node1);
}
void loop(void)
{
network.update();
}
and in the node 11
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t node11 = 11;
const uint16_t node1 = 1;
// Address of the other node
const uint16_t node0 = 0;
// How often to send 'hello world to the other unit
const unsigned long interval = 2000; //ms
// When did we last send?
unsigned long last_sent;
// How many have we sent already
unsigned long packets_sent;
// Structure of our payload
struct payload_t
{
unsigned long ms;
unsigned long counter;
};
void setup(void)
{
Serial.begin(9600);
Serial.println("RF24Network/examples/helloworld_tx/");
SPI.begin();
radio.begin();
network.begin(/channel/ 90, /node address/ node11);
}
void loop(void)
{
// Pump the network regularly
network.update();
// If it's time to send a message, send it!
unsigned long now = millis();
if ( now - last_sent >= interval )
{
last_sent = now;
Serial.print("Sending...");
payload_t payload = { millis(), packets_sent++ };
RF24NetworkHeader header(/to node/ node0);
bool ok = network.write(header,&payload,sizeof(payload));
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
}
}
Do you have any idea what could be my problem ?
It looks like it is probably just a small issue with the addressing.
The RF24Network addresses must be specified in Octal format.
In order to specify an octal number, it must begin with a 0.
Incorrect Addressing:
const uint16_t node11 = 11; // This sets the address to the decimal value 11
const uint16_t node1 = 1; // This sets the address to the decimal value 1
const uint16_t node12 = 12; // This sets the address to the decimal value 12
Correct addressing:
const uint16_t node11 = 011; // This sets the address to the decimal value 9
const uint16_t node1 = 01; // This sets the address to the decimal value 1
const uint16_t node12 = 012; // This sets the address to the decimal value 10
It works. I think i would have never think of it myself because in most example i found, they used 0 and 1 addressing. That's
the first time i see that kind of addressing on multiple nodes. Anyway, you solved my problem. Thank you very very much.