As Robin2 suggested, here is some details on the project.
The main idea is to create a kind of a "capture the flag" system based on a central remote and flag nodes displayed on a playing area.
Each node can be activated randomly, one at a time, until a player "capture it" or because the "activation time" has runned off.
when a flag has to be deactivated (captured or exhausted time) it sends a signal to the remote to allow it to activated another node (and score points in case of capture).
But, to secure the system, i had to use the "autoresponse" to validate the selected node, or to jump to another if not the case on the remote side, and that capture and scores have been aknowledged by the remote when sended by a node.
here is the code for the remote :
/*
Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
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.
Update 2014 - TMRh20
*/
/**
Simplest possible example of using RF24Network
TRANSMITTER NODE
Every 2 seconds, send a payload to the receiver node.
*/
#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 radio(9, 10); // 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
const uint16_t other_node1 = 01;
const uint16_t other_node3 = 03; // Address of the other node in Octal format
const uint16_t other_node2 = 02;
const uint16_t other_node4 = 04;
boolean active = 0;
boolean ok=0;
int node = 0;
const unsigned long interval = 2000; //ms // How often to send 'hello world to the other unit
unsigned long last_sent; // When did we last send?
unsigned long packets_sent; // How many have we sent already
struct payload_t { // Structure of our payload
unsigned long ms;
unsigned long counter;
};
void setup(void)
{
Serial.begin(115200);
Serial.println("RF24Network/examples/helloworld_tx/");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
randomSeed(analogRead(A0));
}
void loop() {
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 )
{
last_sent = now;
node = random(1, 5);
Serial.println(node);
if (node==1) {
Serial.print("Sending to node 01...");
active = 1;
RF24NetworkHeader header1(/*to node*/ other_node1);
ok = network.write(header1, &active, sizeof(active));
if (ok) {
Serial.println("ok node 1.");
active = 0;
ok=0;
}
else {
Serial.println("failed.");}
}
else if (node==2) {
Serial.print("Sending to node 02...");
active = 1;
RF24NetworkHeader header2(/*to node*/ other_node2);
ok = network.write(header2, &active, sizeof(active));
if (ok) {
Serial.println("ok node 2.");
active = 0;
ok=0;
}
else {
Serial.println("failed."); }
}
else if (node== 3) {
Serial.print("Sending to node 03...");
active = 1;
RF24NetworkHeader header3(/*to node*/ other_node3);
ok = network.write(header3, &active, sizeof(active));
if (ok) {
Serial.println("ok node 3.");
active = 0;
ok=0;
}
else {
Serial.println("failed."); }
}
else if (node==4) {
Serial.print("Sending to node 04...");
active = 1;
RF24NetworkHeader header4(/*to node*/ other_node4);
ok = network.write(header4, &active, sizeof(active));
if (ok) {
Serial.println("ok node 4.");
active = 0;
ok=0;
}
else {
Serial.println("failed."); }
}
}
}
and the code for a node :
/*
Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
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.
Update 2014 - TMRh20
*/
/**
* Simplest possible example of using RF24Network,
*
* RECEIVER NODE
* Listens for messages from the transmitter and prints them out.
*/
#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 radio(9,10); // 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 ( 04,031, etc) - others are 02,03,04
const uint16_t other_node = 00; // Address of the other node in Octal format
boolean active = 0;
int ledB = 2;
struct payload_t { // Structure of our payload
unsigned long ms;
unsigned long counter;
};
void setup(void)
{
Serial.begin(115200);
Serial.println("RF24Network/examples/helloworld_rx/");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
pinMode (ledB, LOW);
}
void loop(void){
network.update(); // Check the network regularly
while ( network.available() ) { // Is there anything ready for us?
RF24NetworkHeader header1; // If so, grab it and print it out
//payload_t payload1;
network.read(header1,&active,sizeof(active));
if (active) {
digitalWrite (ledB, HIGH);
delay (1500);
digitalWrite (ledB, LOW);
}
// Serial.print("Received packet #");
// Serial.print(payload1.counter);
// Serial.print(" at ");
// Serial.println(payload1.ms);
}
}