example Radio Range Extender

Dario Di Maio edited this page Aug 18, 2017 · 9 revisions

Introduction

In this example we will look at a implementation of a Souliss network, where we have a set of nodes communicating via the nRF24L01 radio using the wireless extender functionality. The network architecture is composed of four nodes:

  • The gateway node which has an Ethernet (W5100) and a nRF24L01 radio interface, this is node 0.
  • A peer node based on nRF24L01 radio in listening range with the gateway one, this is node 1.
  • The range extender, this is node 2.
  • The out of range node (lets call it remote) which cannot communicate directly with the gateway (too far) and route its data through the range extender, this is node 3.

For all nodes is assumed the use of an AVR based Arduino like (UNO, Duemilanove, Mega, Leonardo, Mini or Micro) both W5100 and nRF24L01 use the SPI peripheral to communicate with the Arduino microcontroller, use pin 10 as CS for W5100 and pin 7 and 8 as EN and CS for nRF24L01.

The code below is an example and need additional headers where ... are placed, this may change based on the release of the IDE, look for examples bundled with the library to complete the code.

Gateway node:

// Configuration options
#include "bconf/StandardArduino.h" 
#include "conf/ethW5100.h" 
#include "conf/nRF24L01.h"
#include "conf/Gateway.h"

...

// Define the network configuration according to your router settings
uint8_t ip_address[4]  = {192, 168, 1, 77};
uint8_t subnet_mask[4] = {255, 255, 255, 0};
uint8_t ip_gateway[4]  = {192, 168, 1, 1};
#define Gateway_address 77
#define myvNet_address  ip_address[3]       // The last byte of the IP address (77) is also the vNet address
#define myvNet_subnet   0xFF00
#define myvNet_supern   Gateway_address
#define rf24_bridge     0x6501              // RF24 address on this node must be 0x6501 to bridge interfaces

// define the shared memory map
#define SWITCH_GATEWAY          0           // This is the memory slot used for a dummy switch
#define SWITCH_NODE1            1           // This is the memory slot used for a dummy switch
#define SWITCH_NODE2            2           // This is the memory slot used for a dummy switch
#define SWITCH_NODE3            3           // This is the memory slot used for a dummy switch


//*************************************************************************
/* Setup
 //*************************************************************************/
void setup()
{   
    pinMode(3, INPUT);

    // Set network parameters
    SetIPAddress(ip_address, subnet_mask, ip_gateway);
    SetAsGateway(myvNet_address);                                   // Set this node as gateway for SoulissApp  	
    
    SetAddress(rf24_bridge, myvNet_subnet, myvNet_supern);

    // The gateway is always node 0, so remote nodes begin at node 1, nodes has to be numbered without gaps.
    SetAsPeerNode(0x6502, 1); // Node on same subnet this is node 1
    SetAsPeerNode(0x6601, 2); // Supernode on different subnet acting as a range extender this is node 2
    SetAsPeerNode(0x6602, 3); // Remote node on range extender subnet this is node 3

    // Set the typical to use
    Set_T13(SWITCH_GATEWAY);

}

//*************************************************************************
/* Main loop
 //*************************************************************************/
void loop()
{ 
    // The Souliss methods are scheduled in phases, this allow load
    // balance and proper timing.

    EXECUTEFAST() {                     
        UPDATEFAST();  
		
        // Execute the code every 510 milliseconds
        FAST_510ms() {
            // Dummy input
            DigIn2State(3, Souliss_T1n_OnCmd, Souliss_T1n_OffCmd, SWITCH_GATEWAY);
            Logic_T13(SWITCH_GATEWAY);
        }

		// Communication is processed here
		FAST_GatewayComms();  
    }
}

A Souliss network needs a gateway node, this node keeps track of other nodes and acts as a gateway for interaction via interfaces, like the SoulissApp or other user interfaces. It is therefore practical to have this node defined as both gateway and a bridge between different interfaces. In the gateway code the remote nodes are defined statically in the setup routine, it is also possible to have them join dynamically, thus removing the need to have to change the code when there are changes in the node networks. This is done simply by commenting out the SetAsPeerNode calls in the setup routine and including a dynamic setup. You can mix statically defined nodes and dynamic nodes as you wish.

The gateway is always node 0, so remote nodes begin at node 1, nodes has to be numbered without gaps.

Now its time to add the nodes.

Simple node on same subnet:

A simple node on the same subnet of the gateway.

// Configuration options
#include "bconf/StandardArduino.h" 
#include "conf/nRF24L01.h"

...

// define the shared memory map
#define SWITCH_GATEWAY          0           // This is the memory slot used for a dummy switch
#define SWITCH_NODE1            1           // This is the memory slot used for a dummy switch
#define SWITCH_NODE2            2           // This is the memory slot used for a dummy switch
#define SWITCH_NODE3            3           // This is the memory slot used for a dummy switch

#define network_address     0x6502        // Local address
#define network_my_subnet   0xFF00
#define network_my_supern   0x6501        // RF24 gateway address

//*******************************************************
// setup, called once on startup
//*******************************************************
void setup() {

    pinMode(3, INPUT);

    // Setup the network configuration
    SetAddress(network_address, network_my_subnet, network_my_supern);

    // Set the typical to use
    Set_T13(SWITCH_NODE1);
}

//*******************************************************
// main loop
//*******************************************************
void loop()
{
    // The Souliss methods are scheduled in phases, this allow load
    // balance and proper timing.

    EXECUTEFAST() {                     
        UPDATEFAST();  
		
        // Execute the code every 510 milliseconds
        FAST_510ms() {
            
			// Dummy input
            DigIn2State(3, Souliss_T1n_OnCmd, Souliss_T1n_OffCmd, SWITCH_NODE1);
            Logic_T13(SWITCH_NODE1);
        }
		
		// Here we process all communication
		FAST_PeerComms();
    }
}

The network addresses defined for this node are:

#define network_address     0x6502        // Local address 
#define network_my_subnet   0xFF00 
#define network_my_supern   0x6501        // RF24 gateway address , same subnet

After uploading the sketch you will have a node with id=1.

Range extender node:

// Configuration options
#include "bconf/StandardArduino.h" 
#include "conf/nRF24L01.h"
#include "conf/WirelessExtender.h"

...

#define network_address         0x6601      // Local address must be the first address in the subnet
#define network_my_subnet       0xFF00
#define network_my_supern       0x6501      // RF24 gateway address

// define the shared memory map
#define SWITCH_GATEWAY          0           // This is the memory slot used for a dummy switch
#define SWITCH_NODE1            1           // This is the memory slot used for a dummy switch
#define SWITCH_NODE2            2           // This is the memory slot used for a dummy switch
#define SWITCH_NODE3            3           // This is the memory slot used for a dummy switch

//*******************************************************
// setup, called once on startup
//*******************************************************
void setup() {

    pinMode(3, INPUT);

    // Setup the network configuration
    SetAddress(network_address, network_my_subnet, network_my_supern);
    
	// Set the typical to use
    Set_T13(SWITCH_NODE2);
}

//*******************************************************
// main loop
//*******************************************************
void loop() {

    // The Souliss methods are scheduled in phases, this allow load
    // balance and proper timing.

    EXECUTEFAST() {                     
        UPDATEFAST();  
		
        // Execute the code every 510 milliseconds
        FAST_510ms() {
            
			// Dummy input
            DigIn2State(3, Souliss_T1n_OnCmd, Souliss_T1n_OffCmd, SWITCH_NODE1);
            Logic_T13(SWITCH_NODE1);
        }
		
		Here we process all communication
        FAST_BridgeComms();
    }
}

This node will act as a relay between the gateway and the remote node. In order to do this we have to include ```#include "conf/WirelessExtender.h". After uploading the sketch you will have a node with id=2, as defined in the gateway sketch.

Remote node:

// Configuration options
#include "bconf/StandardArduino.h" 
#include "conf/nRF24L01.h"

...

// define the shared memory map
#define SWITCH_GATEWAY          0           // This is the memory slot used for a dummy switch
#define SWITCH_NODE1            1           // This is the memory slot used for a dummy switch
#define SWITCH_NODE2            2           // This is the memory slot used for a dummy switch
#define SWITCH_NODE3            3           // This is the memory slot used for a dummy switch

#define network_address     0x6602        // Local address
#define network_my_subnet   0xFF00
#define network_my_supern   0x6601        // RF24 address of range extender/supernode.

//*******************************************************
// setup, called once on startup
//*******************************************************
void setup() {

    pinMode(3, INPUT);

    // Setup the network configuration
    SetAddress(network_address, network_my_subnet, network_my_supern);

    // Set the typical to use
    Set_T13(SWITCH_NODE3);
}

//*******************************************************
// main loop
//*******************************************************
void loop()
{
    // The Souliss methods are scheduled in phases, this allow load
    // balance and proper timing.

    EXECUTEFAST() {                     
        UPDATEFAST();  
		
        // Execute the code every 510 milliseconds
        FAST_510ms() {
            
			// Dummy input
            DigIn2State(3, Souliss_T1n_OnCmd, Souliss_T1n_OffCmd, SWITCH_NODE1);
            Logic_T13(SWITCH_NODE1);
        }
		
		// Here we process all communication
		FAST_PeerComms();
    }
}

This node is the remote node that communicate via the range extender node.

The network addresses defined for this node are:

#define network_address     0x6602        // Local address 
#define network_my_subnet   0xFF00 
#define network_my_supern   0x6601        // RF24 address of range extender/supernode.

After uploading the sketch you will have a node with id=3, as defined in the gateway sketch.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.