RF24network don't route the message from 011 to 00
hi... trying explain issue
i'm working rf24network based security alarm system
actually have 6 sensors pir , switch contact door on board send bool values base.
due limitation of 5 child communicate directly base have necessity of route grandchild message...
node 01,02,03 etc ok , communicate every event 00 base.
but 011 don't communicate base...
maybe wrong in code....
i report 3 of devices.. base 00 child 01 , grandchild 011
this sketch of base 00
this sketch of 01 node
and sketch of 011 node
connected serial monitor of receiver mode can see headers data received 01 node....
i cannot see data received 011 node. after try switch on , off contact sensor of 011 appears on rx very rare. 1 time of 50 switch....
where error in opinion?
thank you
i'm working rf24network based security alarm system
actually have 6 sensors pir , switch contact door on board send bool values base.
due limitation of 5 child communicate directly base have necessity of route grandchild message...
node 01,02,03 etc ok , communicate every event 00 base.
but 011 don't communicate base...
maybe wrong in code....
i report 3 of devices.. base 00 child 01 , grandchild 011
this sketch of base 00
code: [select]
#include <rf24network.h>
#include <rf24.h>
#include <spi.h>
// constants identify nodes
const uint16_t pi_node = 0;
const uint16_t sensor_node1 = 1;
const uint16_t sensor_node2 = 011;
// ce pin, csn pin, spi speed
rf24 radio(9, 10);
rf24network network(radio);
// time between checking packets (in ms)
const unsigned long interval = 100;
int ledpin1 = 6;
int ledpin2 = 7;
int ledpin3 = 4;
int ledpin4 = 5;
// structure of our messages
struct message_sensor {
bool motion;
bool dooropen;
};
message_sensor message;
void setup ()
{
// initialize radio related modules
serial.begin(115200);
radio.begin();
delay(5);
network.begin(90, pi_node);
pinmode (ledpin1, output);
pinmode (ledpin2, output);
pinmode (ledpin3, output);
pinmode (ledpin4, output);
radio.setpalevel(rf24_pa_low);
serial.println("ready");
network.update();
}
void loop()
{
network.update();
// enter loop if there data available read,
// , continue long there more data read
while ( network.available() ) {
rf24networkheader header;
message_sensor sensormessage;
// have peek @ data see header type
network.read(header, &sensormessage, sizeof(sensormessage));
network.peek(header);
serial.println ("data received node ");
serial.println(header.from_node);
if (header.type == '1') {
// read message
network.read(header, &sensormessage, sizeof(sensormessage));
// print node wich sent message
// serial.println ("data received node ");
// serial.println(header.from_node);
char buffer [50];
switch (header.from_node) {
case sensor_node1:
system(buffer);
digitalwrite(ledpin1,sensormessage.motion ? 1 : 0);
system(buffer);
digitalwrite(ledpin2,sensormessage.dooropen ? 1 : 0);
system(buffer);
break;
// read other sensor data node 2 here
case sensor_node2:
system(buffer);
digitalwrite(ledpin3,sensormessage.motion ? 1 : 0);
system(buffer);
digitalwrite(ledpin4,sensormessage.dooropen ? 1 : 0);
system(buffer);
break;
default:
printf ("unknown node %i\n", header.from_node);
break;
}
} else {
// not type recognize
network.read(header, &sensormessage, sizeof(sensormessage));
printf("unknown message received node %i\n", header.from_node);
}
}
}
this sketch of 01 node
code: [select]
#include <rf24network.h>
#include <rf24.h>
#include <spi.h>
#include <avr/sleep.h>
#include <avr/power.h>
// pir variables
byte pirpin = 7;
int pircalibrationtime = 30;
int pirwake = 3;
int contactwake = 2;
// magnetic door sensor variable
byte switchpin = 6;
// radio ce & csn connected
rf24 radio(9, 10);
rf24network network(radio);
// constants identify node , node send data to
uint16_t this_node = 01;
uint16_t parent_node = 0;
// time between packets (in ms)
const unsigned long interval = 100; // every sec
// structure of our message
struct message_1 {
bool motion;
bool dooropen;
};
message_1 message;
// network header initialized node
rf24networkheader header(parent_node);
void setup(void)
{
// set serial monitor
serial.begin(115200);
// initialize radio related modules
spi.begin();
radio.begin();
delay(5);
network.begin(90, this_node);
radio.setpalevel(rf24_pa_low);
radio.setretries(8,15);
network.txtimeout = 553;
pinmode(switchpin, input);
pinmode(contactwake, input_pullup);
pinmode(pirwake,input);
pinmode(pirpin, input);
digitalwrite(pirpin, low);
serial.println(" done");
delay(50);
network.update();
}
void loop() {
// update network data
network.update();
// read door sensor: high means door open (the magnet far enough switch)
bool d = (digitalread(switchpin) == high);
// read motion: high means motion detected
bool m = (digitalread(pirpin) == high);
// headers type 1 node
// set again each loop iteration because fragmentation of messages might change between loops
header.type = '1';
// send values if of them different enough last time sent:
if (m != message.motion ||
d != message.dooropen) {
// construct message we'll send
message = (message_1){m, d };
// writing message network means sending it
if (network.write(header, &message, sizeof(message))) {
serial.print("message sent\n");
} else {
serial.print("could not send message\n");
}
}
// wait bit before start on again
delay(interval);
// }
}
and sketch of 011 node
code: [select]
#include <rf24network.h>
#include <rf24.h>
#include <spi.h>
#include <avr/sleep.h>
#include <avr/power.h>
// pir variables
byte pirpin = 7;
int pircalibrationtime = 30;
int pirwake = 3;
int contactwake = 2;
// magnetic door sensor variable
byte switchpin = 6;
// radio ce & csn connected
rf24 radio(9, 10);
rf24network network(radio);
// constants identify node , node send data to
uint16_t this_node = 011;
uint16_t parent_node = 0;
// time between packets (in ms)
const unsigned long interval = 100; // every sec
// structure of our message
struct message_1 {
bool motion;
bool dooropen;
};
message_1 message;
// network header initialized node
rf24networkheader header(parent_node);
void setup(void)
{
// set serial monitor
serial.begin(115200);
// initialize radio related modules
spi.begin();
radio.begin();
delay(5);
network.begin(90, this_node);
radio.setpalevel(rf24_pa_low);
radio.setretries(8,15);
network.txtimeout = 553;
pinmode(switchpin, input);
pinmode(contactwake, input_pullup);
pinmode(pirwake,input);
pinmode(pirpin, input);
digitalwrite(pirpin, low);
serial.println(" done");
delay(50);
network.update();
}
void loop() {
// update network data
network.update();
// read door sensor: high means door open (the magnet far enough switch)
bool d = (digitalread(switchpin) == high);
// read motion: high means motion detected
bool m = (digitalread(pirpin) == high);
// headers type 1 node
// set again each loop iteration because fragmentation of messages might change between loops
header.type = '1';
// send values if of them different enough last time sent:
if (m != message.motion ||
d != message.dooropen) {
// construct message we'll send
message = (message_1){m, d };
// writing message network means sending it
if (network.write(header, &message, sizeof(message))) {
serial.print("message sent\n");
} else {
serial.print("could not send message\n");
}
}
// wait bit before start on again
delay(interval);
// }
}
connected serial monitor of receiver mode can see headers data received 01 node....
i cannot see data received 011 node. after try switch on , off contact sensor of 011 appears on rx very rare. 1 time of 50 switch....
where error in opinion?
thank you
Arduino Forum > Using Arduino > Programming Questions > RF24network don't route the message from 011 to 00
arduino
Comments
Post a Comment