Hi... trying to explain my issue
I'm working to rf24network based security alarm system
actually i have 6 sensors with pir and switch contact for door on board that send their bool values to the base.
due to the limitation of 5 child to communicate directly with the base i have the necessity of route some grandchild message...
node 01,02,03 etc are ok and communicate successfully every event to 00 base.
but 011 don't communicate with the base...
maybe something wrong in my code....
i will report only 3 of my devices.. the base 00 the child 01 and the grandchild 011
this is the sketch of the base 00
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// Constants that 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 for 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 all 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 this loop if there is data available to be read,
// and continue it as long as there is more data to read
while ( network.available() ) {
RF24NetworkHeader header;
message_sensor sensormessage;
// Have a peek at the data to see the header type
network.read(header, &sensormessage, sizeof(sensormessage));
network.peek(header);
Serial.println ("Data received from node ");
Serial.println(header.from_node);
if (header.type == '1') {
// Read the message
network.read(header, &sensormessage, sizeof(sensormessage));
// Print the node wich sent the message
// Serial.println ("Data received from 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 from 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 {
// This is not a type we recognize
network.read(header, &sensormessage, sizeof(sensormessage));
printf("Unknown message received from node %i\n", header.from_node);
}
}
}
This is the sketch of 01 node
#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 with CE & CSN connected
RF24 radio(9, 10);
RF24Network network(radio);
// Constants that identify this node and the node to 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;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup(void)
{
// Set up the Serial Monitor
Serial.begin(115200);
// Initialize all 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 is open (the magnet is far enough from the switch)
bool d = (digitalRead(switchPin) == HIGH);
// Read motion: HIGH means motion is detected
bool m = (digitalRead(pirPin) == HIGH);
// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';
// Only send values if any of them are different enough from the last time we sent:
if (m != message.motion ||
d != message.dooropen) {
// Construct the message we'll send
message = (message_1){m, d };
// Writing the message to the 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 a bit before we start over again
delay(interval);
// }
}
and finally This is the sketch of 011 node
#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 with CE & CSN connected
RF24 radio(9, 10);
RF24Network network(radio);
// Constants that identify this node and the node to 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;
// The network header initialized for this node
RF24NetworkHeader header(parent_node);
void setup(void)
{
// Set up the Serial Monitor
Serial.begin(115200);
// Initialize all 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 is open (the magnet is far enough from the switch)
bool d = (digitalRead(switchPin) == HIGH);
// Read motion: HIGH means motion is detected
bool m = (digitalRead(pirPin) == HIGH);
// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';
// Only send values if any of them are different enough from the last time we sent:
if (m != message.motion ||
d != message.dooropen) {
// Construct the message we'll send
message = (message_1){m, d };
// Writing the message to the 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 a bit before we start over again
delay(interval);
// }
}
connected to the serial monitor of receiver mode i can see the headers data received from 01 node....
i cannot see the data received from 011 node. really after i try to switch on and off the contact sensor of 011 it appears on RX but is very very very rare. one time of 50 switch....
where is the error in your opinion?
thank you