fd

Dependents:   xtoff3 CYS_Receiver

Fork of RF24Network by Akash Vibhute

Committer:
pietor
Date:
Thu Sep 13 09:14:42 2018 +0000
Revision:
7:d72e1d8f5355
Parent:
3:dfc8da7ac18c
Child:
4:75c5aa56411f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 0:c3db0798d9aa 1 /*
akashvibhute 0:c3db0798d9aa 2 Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
akashvibhute 0:c3db0798d9aa 3
akashvibhute 0:c3db0798d9aa 4 This program is free software; you can redistribute it and/or
akashvibhute 0:c3db0798d9aa 5 modify it under the terms of the GNU General Public License
akashvibhute 0:c3db0798d9aa 6 version 2 as published by the Free Software Foundation.
akashvibhute 0:c3db0798d9aa 7 */
akashvibhute 0:c3db0798d9aa 8
akashvibhute 3:dfc8da7ac18c 9 /*
akashvibhute 3:dfc8da7ac18c 10 * Mbed support added by Akash Vibhute <akash.roboticist@gmail.com>
akashvibhute 3:dfc8da7ac18c 11 * Porting completed on Nov/05/2015
akashvibhute 3:dfc8da7ac18c 12 *
akashvibhute 3:dfc8da7ac18c 13 * Updated with TMRh20's RF24 library on Nov/04/2015 from https://github.com/TMRh20
akashvibhute 3:dfc8da7ac18c 14 *
akashvibhute 3:dfc8da7ac18c 15 */
akashvibhute 3:dfc8da7ac18c 16
akashvibhute 0:c3db0798d9aa 17 #ifndef __RF24NETWORK_H__
akashvibhute 0:c3db0798d9aa 18 #define __RF24NETWORK_H__
akashvibhute 0:c3db0798d9aa 19
akashvibhute 0:c3db0798d9aa 20 /**
akashvibhute 0:c3db0798d9aa 21 * @file RF24Network.h
akashvibhute 0:c3db0798d9aa 22 *
akashvibhute 0:c3db0798d9aa 23 * Class declaration for RF24Network
akashvibhute 0:c3db0798d9aa 24 */
akashvibhute 2:a5f8e04bd02b 25 #define min(a,b) (a<b?a:b)
akashvibhute 0:c3db0798d9aa 26 #include <stddef.h>
akashvibhute 0:c3db0798d9aa 27 #include <stdint.h>
akashvibhute 2:a5f8e04bd02b 28 #include "RF24Network_config.h"
akashvibhute 2:a5f8e04bd02b 29
akashvibhute 2:a5f8e04bd02b 30 /* Header types range */
akashvibhute 2:a5f8e04bd02b 31 #define MIN_USER_DEFINED_HEADER_TYPE 0
akashvibhute 2:a5f8e04bd02b 32 #define MAX_USER_DEFINED_HEADER_TYPE 127
akashvibhute 2:a5f8e04bd02b 33
akashvibhute 3:dfc8da7ac18c 34 /**
akashvibhute 2:a5f8e04bd02b 35
akashvibhute 2:a5f8e04bd02b 36 */
akashvibhute 3:dfc8da7ac18c 37
akashvibhute 2:a5f8e04bd02b 38 // ACK Response Types
akashvibhute 2:a5f8e04bd02b 39 /**
akashvibhute 2:a5f8e04bd02b 40 * **Reserved network message types**
akashvibhute 2:a5f8e04bd02b 41 *
akashvibhute 2:a5f8e04bd02b 42 * The network will determine whether to automatically acknowledge payloads based on their general type <br>
akashvibhute 3:dfc8da7ac18c 43 *
akashvibhute 2:a5f8e04bd02b 44 * **User types** (1-127) 1-64 will NOT be acknowledged <br>
akashvibhute 2:a5f8e04bd02b 45 * **System types** (128-255) 192 through 255 will NOT be acknowledged<br>
akashvibhute 2:a5f8e04bd02b 46 *
akashvibhute 2:a5f8e04bd02b 47 * @defgroup DEFINED_TYPES Reserved System Message Types
akashvibhute 2:a5f8e04bd02b 48 *
akashvibhute 2:a5f8e04bd02b 49 * System types can also contain message data.
akashvibhute 2:a5f8e04bd02b 50 *
akashvibhute 2:a5f8e04bd02b 51 * @{
akashvibhute 2:a5f8e04bd02b 52 */
akashvibhute 2:a5f8e04bd02b 53
akashvibhute 2:a5f8e04bd02b 54 /**
akashvibhute 2:a5f8e04bd02b 55 * A NETWORK_ADDR_RESPONSE type is utilized to manually route custom messages containing a single RF24Network address
akashvibhute 3:dfc8da7ac18c 56 *
akashvibhute 2:a5f8e04bd02b 57 * Used by RF24Mesh
akashvibhute 3:dfc8da7ac18c 58 *
akashvibhute 2:a5f8e04bd02b 59 * If a node receives a message of this type that is directly addressed to it, it will read the included message, and forward the payload
akashvibhute 2:a5f8e04bd02b 60 * on to the proper recipient. <br>
akashvibhute 2:a5f8e04bd02b 61 * This allows nodes to forward multicast messages to the master node, receive a response, and forward it back to the requester.
akashvibhute 2:a5f8e04bd02b 62 */
akashvibhute 3:dfc8da7ac18c 63 #define NETWORK_ADDR_RESPONSE 128
akashvibhute 2:a5f8e04bd02b 64 //#define NETWORK_ADDR_CONFIRM 129
akashvibhute 2:a5f8e04bd02b 65
akashvibhute 2:a5f8e04bd02b 66 /**
akashvibhute 3:dfc8da7ac18c 67 * Messages of type NETWORK_PING will be dropped automatically by the recipient. A NETWORK_ACK or automatic radio-ack will indicate to the sender whether the
akashvibhute 2:a5f8e04bd02b 68 * payload was successful. The time it takes to successfully send a NETWORK_PING is the round-trip-time.
akashvibhute 2:a5f8e04bd02b 69 */
akashvibhute 2:a5f8e04bd02b 70 #define NETWORK_PING 130
akashvibhute 2:a5f8e04bd02b 71
akashvibhute 2:a5f8e04bd02b 72 /**
akashvibhute 3:dfc8da7ac18c 73 * External data types are used to define messages that will be passed to an external data system. This allows RF24Network to route and pass any type of data, such
akashvibhute 2:a5f8e04bd02b 74 * as TCP/IP frames, while still being able to utilize standard RF24Network messages etc.
akashvibhute 2:a5f8e04bd02b 75 *
akashvibhute 2:a5f8e04bd02b 76 * **Linux**
akashvibhute 3:dfc8da7ac18c 77 * Linux devices (defined RF24_LINUX) will buffer all data types in the user cache.
akashvibhute 2:a5f8e04bd02b 78 *
akashvibhute 2:a5f8e04bd02b 79 * **Arduino/AVR/Etc:** Data transmitted with the type set to EXTERNAL_DATA_TYPE will not be loaded into the user cache. <br>
akashvibhute 2:a5f8e04bd02b 80 * External systems can extract external data using the following process, while internal data types are cached in the user buffer, and accessed using network.read() :
akashvibhute 2:a5f8e04bd02b 81 * @code
akashvibhute 2:a5f8e04bd02b 82 * uint8_t return_type = network.update();
akashvibhute 2:a5f8e04bd02b 83 * if(return_type == EXTERNAL_DATA_TYPE){
akashvibhute 3:dfc8da7ac18c 84 * uint16_t size = network.frag_ptr->message_size;
akashvibhute 2:a5f8e04bd02b 85 * memcpy(&myDataBuffer,network.frag_ptr->message_buffer,network.frag_ptr->message_size);
akashvibhute 3:dfc8da7ac18c 86 * }
akashvibhute 2:a5f8e04bd02b 87 * @endcode
akashvibhute 2:a5f8e04bd02b 88 */
akashvibhute 2:a5f8e04bd02b 89 #define EXTERNAL_DATA_TYPE 131
akashvibhute 2:a5f8e04bd02b 90
akashvibhute 2:a5f8e04bd02b 91 /**
akashvibhute 2:a5f8e04bd02b 92 * Messages of this type designate the first of two or more message fragments, and will be re-assembled automatically.
akashvibhute 2:a5f8e04bd02b 93 */
akashvibhute 2:a5f8e04bd02b 94 #define NETWORK_FIRST_FRAGMENT 148
akashvibhute 2:a5f8e04bd02b 95
akashvibhute 2:a5f8e04bd02b 96 /**
akashvibhute 2:a5f8e04bd02b 97 * Messages of this type indicate a fragmented payload with two or more message fragments.
akashvibhute 2:a5f8e04bd02b 98 */
akashvibhute 2:a5f8e04bd02b 99 #define NETWORK_MORE_FRAGMENTS 149
akashvibhute 2:a5f8e04bd02b 100
akashvibhute 2:a5f8e04bd02b 101 /**
akashvibhute 2:a5f8e04bd02b 102 * Messages of this type indicate the last fragment in a sequence of message fragments.
akashvibhute 2:a5f8e04bd02b 103 * Messages of this type do not receive a NETWORK_ACK
akashvibhute 2:a5f8e04bd02b 104 */
akashvibhute 3:dfc8da7ac18c 105 #define NETWORK_LAST_FRAGMENT 150
akashvibhute 2:a5f8e04bd02b 106 //#define NETWORK_LAST_FRAGMENT 201
akashvibhute 2:a5f8e04bd02b 107
akashvibhute 2:a5f8e04bd02b 108 // NO ACK Response Types
akashvibhute 2:a5f8e04bd02b 109 //#define NETWORK_ACK_REQUEST 192
akashvibhute 2:a5f8e04bd02b 110
akashvibhute 2:a5f8e04bd02b 111 /**
akashvibhute 2:a5f8e04bd02b 112 * Messages of this type are used internally, to signal the sender that a transmission has been completed.
akashvibhute 2:a5f8e04bd02b 113 * RF24Network does not directly have a built-in transport layer protocol, so message delivery is not 100% guaranteed.<br>
akashvibhute 2:a5f8e04bd02b 114 * Messages can be lost via corrupted dynamic payloads, or a NETWORK_ACK can fail, while the message was actually successful.
akashvibhute 3:dfc8da7ac18c 115 *
akashvibhute 2:a5f8e04bd02b 116 * NETWORK_ACK messages can be utilized as a traffic/flow control mechanism, since transmitting nodes will be forced to wait until
akashvibhute 3:dfc8da7ac18c 117 * the payload is transmitted across the network and acknowledged, before sending additional data.
akashvibhute 2:a5f8e04bd02b 118 *
akashvibhute 2:a5f8e04bd02b 119 * In the event that the transmitting device will be waiting for a direct response, manually sent by the recipient, a NETWORK_ACK is not required. <br>
akashvibhute 2:a5f8e04bd02b 120 * User messages utilizing a 'type' with a decimal value of 64 or less will not be acknowledged across the network via NETWORK_ACK messages.
akashvibhute 2:a5f8e04bd02b 121 */
akashvibhute 2:a5f8e04bd02b 122 #define NETWORK_ACK 193
akashvibhute 2:a5f8e04bd02b 123
akashvibhute 2:a5f8e04bd02b 124 /**
akashvibhute 2:a5f8e04bd02b 125 * Used by RF24Mesh
akashvibhute 2:a5f8e04bd02b 126 *
akashvibhute 2:a5f8e04bd02b 127 * Messages of this type are used with multi-casting , to find active/available nodes.
akashvibhute 2:a5f8e04bd02b 128 * Any node receiving a NETWORK_POLL sent to a multicast address will respond directly to the sender with a blank message, indicating the
akashvibhute 2:a5f8e04bd02b 129 * address of the available node via the header.
akashvibhute 3:dfc8da7ac18c 130 */
akashvibhute 2:a5f8e04bd02b 131 #define NETWORK_POLL 194
akashvibhute 2:a5f8e04bd02b 132
akashvibhute 2:a5f8e04bd02b 133 /**
akashvibhute 2:a5f8e04bd02b 134 * Used by RF24Mesh
akashvibhute 2:a5f8e04bd02b 135 *
akashvibhute 2:a5f8e04bd02b 136 * Messages of this type are used to request information from the master node, generally via a unicast (direct) write.
akashvibhute 2:a5f8e04bd02b 137 * Any (non-master) node receiving a message of this type will manually forward it to the master node using an normal network write.
akashvibhute 2:a5f8e04bd02b 138 */
akashvibhute 2:a5f8e04bd02b 139 #define NETWORK_REQ_ADDRESS 195
akashvibhute 2:a5f8e04bd02b 140 //#define NETWORK_ADDR_LOOKUP 196
akashvibhute 2:a5f8e04bd02b 141 //#define NETWORK_ADDR_RELEASE 197
akashvibhute 2:a5f8e04bd02b 142 /** @} */
akashvibhute 2:a5f8e04bd02b 143
akashvibhute 2:a5f8e04bd02b 144 #define NETWORK_MORE_FRAGMENTS_NACK 200
akashvibhute 2:a5f8e04bd02b 145
akashvibhute 2:a5f8e04bd02b 146 /** Internal defines for handling written payloads */
akashvibhute 2:a5f8e04bd02b 147 #define TX_NORMAL 0
akashvibhute 2:a5f8e04bd02b 148 #define TX_ROUTED 1
akashvibhute 2:a5f8e04bd02b 149 #define USER_TX_TO_PHYSICAL_ADDRESS 2 //no network ACK
akashvibhute 2:a5f8e04bd02b 150 #define USER_TX_TO_LOGICAL_ADDRESS 3 // network ACK
akashvibhute 2:a5f8e04bd02b 151 #define USER_TX_MULTICAST 4
akashvibhute 2:a5f8e04bd02b 152
akashvibhute 2:a5f8e04bd02b 153 #define MAX_FRAME_SIZE 32 //Size of individual radio frames
akashvibhute 2:a5f8e04bd02b 154 #define FRAME_HEADER_SIZE 10 //Size of RF24Network frames - data
akashvibhute 2:a5f8e04bd02b 155
akashvibhute 2:a5f8e04bd02b 156 #define USE_CURRENT_CHANNEL 255 // Use current radio channel when setting up the network
akashvibhute 2:a5f8e04bd02b 157
akashvibhute 2:a5f8e04bd02b 158 /** Internal defines for handling internal payloads - prevents reading additional data from the radio
akashvibhute 2:a5f8e04bd02b 159 * when buffers are full */
akashvibhute 3:dfc8da7ac18c 160 #define FLAG_HOLD_INCOMING 1
akashvibhute 3:dfc8da7ac18c 161 /** FLAG_BYPASS_HOLDS is mainly for use with RF24Mesh as follows:
akashvibhute 3:dfc8da7ac18c 162 * a: Ensure no data in radio buffers, else exit
akashvibhute 3:dfc8da7ac18c 163 * b: Address is changed to multicast address for renewal
akashvibhute 3:dfc8da7ac18c 164 * c: Holds Cleared (bypass flag is set)
akashvibhute 3:dfc8da7ac18c 165 * d: Address renewal takes place and is set
akashvibhute 3:dfc8da7ac18c 166 * e: Holds Enabled (bypass flag off)
akashvibhute 3:dfc8da7ac18c 167 */
akashvibhute 3:dfc8da7ac18c 168 #define FLAG_BYPASS_HOLDS 2
akashvibhute 3:dfc8da7ac18c 169
akashvibhute 3:dfc8da7ac18c 170 #define FLAG_FAST_FRAG 4
akashvibhute 0:c3db0798d9aa 171
akashvibhute 0:c3db0798d9aa 172 class RF24;
akashvibhute 0:c3db0798d9aa 173
akashvibhute 0:c3db0798d9aa 174 /**
akashvibhute 0:c3db0798d9aa 175 * Header which is sent with each message
akashvibhute 0:c3db0798d9aa 176 *
akashvibhute 0:c3db0798d9aa 177 * The frame put over the air consists of this header and a message
akashvibhute 2:a5f8e04bd02b 178 *
akashvibhute 2:a5f8e04bd02b 179 * Headers are addressed to the appropriate node, and the network forwards them on to their final destination.
akashvibhute 0:c3db0798d9aa 180 */
akashvibhute 3:dfc8da7ac18c 181 struct RF24NetworkHeader {
akashvibhute 3:dfc8da7ac18c 182 uint16_t from_node; /**< Logical address where the message was generated */
akashvibhute 3:dfc8da7ac18c 183 uint16_t to_node; /**< Logical address where the message is going */
akashvibhute 3:dfc8da7ac18c 184 uint16_t id; /**< Sequential message ID, incremented every time a new frame is constructed */
akashvibhute 3:dfc8da7ac18c 185 /**
akashvibhute 3:dfc8da7ac18c 186 * Message Types:
akashvibhute 3:dfc8da7ac18c 187 * User message types 1 through 64 will NOT be acknowledged by the network, while message types 65 through 127 will receive a network ACK.
akashvibhute 3:dfc8da7ac18c 188 * System message types 192 through 255 will NOT be acknowledged by the network. Message types 128 through 192 will receive a network ACK. <br>
akashvibhute 3:dfc8da7ac18c 189 * <br><br>
akashvibhute 3:dfc8da7ac18c 190 */
akashvibhute 3:dfc8da7ac18c 191 unsigned char type; /**< <b>Type of the packet. </b> 0-127 are user-defined types, 128-255 are reserved for system */
akashvibhute 0:c3db0798d9aa 192
akashvibhute 3:dfc8da7ac18c 193 /**
akashvibhute 3:dfc8da7ac18c 194 * During fragmentation, it carries the fragment_id, and on the last fragment
akashvibhute 3:dfc8da7ac18c 195 * it carries the header_type.<br>
akashvibhute 3:dfc8da7ac18c 196 */
akashvibhute 3:dfc8da7ac18c 197 unsigned char reserved; /**< *Reserved for system use* */
akashvibhute 3:dfc8da7ac18c 198
akashvibhute 3:dfc8da7ac18c 199 static uint16_t next_id; /**< The message ID of the next message to be sent (unused)*/
akashvibhute 0:c3db0798d9aa 200
akashvibhute 3:dfc8da7ac18c 201 /**
akashvibhute 3:dfc8da7ac18c 202 * Default constructor
akashvibhute 3:dfc8da7ac18c 203 *
akashvibhute 2:a5f8e04bd02b 204
akashvibhute 3:dfc8da7ac18c 205 * Simply constructs a blank header
akashvibhute 3:dfc8da7ac18c 206 */
akashvibhute 3:dfc8da7ac18c 207 RF24NetworkHeader() {}
akashvibhute 0:c3db0798d9aa 208
akashvibhute 3:dfc8da7ac18c 209 /**
akashvibhute 3:dfc8da7ac18c 210 * Send constructor
akashvibhute 3:dfc8da7ac18c 211 *
akashvibhute 3:dfc8da7ac18c 212 * @note Now supports automatic fragmentation for very long messages, which can be sent as usual if fragmentation is enabled.
akashvibhute 3:dfc8da7ac18c 213 *
akashvibhute 3:dfc8da7ac18c 214 * Fragmentation is enabled by default for all devices except ATTiny <br>
akashvibhute 3:dfc8da7ac18c 215 * Configure fragmentation and max payload size in RF24Network_config.h
akashvibhute 3:dfc8da7ac18c 216 *
akashvibhute 3:dfc8da7ac18c 217 * Use this constructor to create a header and then send a message
akashvibhute 3:dfc8da7ac18c 218 *
akashvibhute 3:dfc8da7ac18c 219 * @code
akashvibhute 3:dfc8da7ac18c 220 * uint16_t recipient_address = 011;
akashvibhute 3:dfc8da7ac18c 221 *
akashvibhute 3:dfc8da7ac18c 222 * RF24NetworkHeader header(recipient_address,'t');
akashvibhute 3:dfc8da7ac18c 223 *
akashvibhute 3:dfc8da7ac18c 224 * network.write(header,&message,sizeof(message));
akashvibhute 3:dfc8da7ac18c 225 * @endcode
akashvibhute 3:dfc8da7ac18c 226 *
akashvibhute 3:dfc8da7ac18c 227 * @param _to The Octal format, logical node address where the message is going
akashvibhute 3:dfc8da7ac18c 228 * @param _type The type of message which follows. Only 0-127 are allowed for
akashvibhute 3:dfc8da7ac18c 229 * user messages. Types 1-64 will not receive a network acknowledgement.
akashvibhute 3:dfc8da7ac18c 230 */
akashvibhute 0:c3db0798d9aa 231
akashvibhute 3:dfc8da7ac18c 232 RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), type(_type) {}
akashvibhute 3:dfc8da7ac18c 233 /**
akashvibhute 3:dfc8da7ac18c 234 * Create debugging string
akashvibhute 3:dfc8da7ac18c 235 *
akashvibhute 3:dfc8da7ac18c 236 * Useful for debugging. Dumps all members into a single string, using
akashvibhute 3:dfc8da7ac18c 237 * internal static memory. This memory will get overridden next time
akashvibhute 3:dfc8da7ac18c 238 * you call the method.
akashvibhute 3:dfc8da7ac18c 239 *
akashvibhute 3:dfc8da7ac18c 240 * @return String representation of this object
akashvibhute 3:dfc8da7ac18c 241 */
akashvibhute 3:dfc8da7ac18c 242 const char* toString(void) const;
akashvibhute 0:c3db0798d9aa 243 };
akashvibhute 0:c3db0798d9aa 244
akashvibhute 2:a5f8e04bd02b 245
akashvibhute 0:c3db0798d9aa 246 /**
akashvibhute 2:a5f8e04bd02b 247 * Frame structure for internal message handling, and for use by external applications
akashvibhute 2:a5f8e04bd02b 248 *
akashvibhute 2:a5f8e04bd02b 249 * The actual frame put over the air consists of a header (8-bytes) and a message payload (Up to 24-bytes)<br>
akashvibhute 2:a5f8e04bd02b 250 * When data is received, it is stored using the RF24NetworkFrame structure, which includes:
akashvibhute 3:dfc8da7ac18c 251 * 1. The header
akashvibhute 3:dfc8da7ac18c 252 * 2. The size of the included message
akashvibhute 2:a5f8e04bd02b 253 * 3. The 'message' or data being received
akashvibhute 3:dfc8da7ac18c 254 *
akashvibhute 2:a5f8e04bd02b 255 *
akashvibhute 2:a5f8e04bd02b 256 */
akashvibhute 2:a5f8e04bd02b 257
akashvibhute 3:dfc8da7ac18c 258 struct RF24NetworkFrame {
akashvibhute 3:dfc8da7ac18c 259 RF24NetworkHeader header; /**< Header which is sent with each message */
akashvibhute 3:dfc8da7ac18c 260 uint16_t message_size; /**< The size in bytes of the payload length */
akashvibhute 2:a5f8e04bd02b 261
akashvibhute 3:dfc8da7ac18c 262 /**
akashvibhute 3:dfc8da7ac18c 263 * On Arduino, the message buffer is just a pointer, and can be pointed to any memory location.
akashvibhute 3:dfc8da7ac18c 264 * On Linux the message buffer is a standard byte array, equal in size to the defined MAX_PAYLOAD_SIZE
akashvibhute 3:dfc8da7ac18c 265 */
akashvibhute 3:dfc8da7ac18c 266
akashvibhute 3:dfc8da7ac18c 267 uint8_t *message_buffer; //< Pointer to the buffer storing the actual message
akashvibhute 3:dfc8da7ac18c 268
akashvibhute 3:dfc8da7ac18c 269 /**
akashvibhute 3:dfc8da7ac18c 270 * Default constructor
akashvibhute 3:dfc8da7ac18c 271 *
akashvibhute 3:dfc8da7ac18c 272 * Simply constructs a blank frame. Frames are generally used internally. See RF24NetworkHeader.
akashvibhute 3:dfc8da7ac18c 273 */
akashvibhute 3:dfc8da7ac18c 274 //RF24NetworkFrame() {}
akashvibhute 2:a5f8e04bd02b 275
akashvibhute 3:dfc8da7ac18c 276 RF24NetworkFrame() {}
akashvibhute 3:dfc8da7ac18c 277 /**
akashvibhute 3:dfc8da7ac18c 278 * Constructor - create a network frame with data
akashvibhute 3:dfc8da7ac18c 279 * Frames are constructed and handled differently on Arduino/AVR and Linux devices (defined RF24_LINUX)
akashvibhute 3:dfc8da7ac18c 280 *
akashvibhute 3:dfc8da7ac18c 281 * <br>
akashvibhute 3:dfc8da7ac18c 282 * **Linux:**
akashvibhute 3:dfc8da7ac18c 283 * @param _header The RF24Network header to be stored in the frame
akashvibhute 3:dfc8da7ac18c 284 * @param _message The 'message' or data.
akashvibhute 3:dfc8da7ac18c 285 * @param _len The size of the 'message' or data.
akashvibhute 3:dfc8da7ac18c 286 *
akashvibhute 3:dfc8da7ac18c 287 * <br>
akashvibhute 3:dfc8da7ac18c 288 * **Arduino/AVR/Etc.**
akashvibhute 3:dfc8da7ac18c 289 * @see RF24Network.frag_ptr
akashvibhute 3:dfc8da7ac18c 290 * @param _header The RF24Network header to be stored in the frame
akashvibhute 3:dfc8da7ac18c 291 * @param _message_size The size of the 'message' or data
akashvibhute 3:dfc8da7ac18c 292 *
akashvibhute 3:dfc8da7ac18c 293 *
akashvibhute 3:dfc8da7ac18c 294 * Frames are used internally and by external systems. See RF24NetworkHeader.
akashvibhute 3:dfc8da7ac18c 295 */
akashvibhute 2:a5f8e04bd02b 296
akashvibhute 3:dfc8da7ac18c 297
akashvibhute 3:dfc8da7ac18c 298 RF24NetworkFrame(RF24NetworkHeader &_header, uint16_t _message_size):
akashvibhute 3:dfc8da7ac18c 299 header(_header), message_size(_message_size) {
akashvibhute 3:dfc8da7ac18c 300 }
akashvibhute 2:a5f8e04bd02b 301
akashvibhute 3:dfc8da7ac18c 302 /**
akashvibhute 3:dfc8da7ac18c 303 * Create debugging string
akashvibhute 3:dfc8da7ac18c 304 *
akashvibhute 3:dfc8da7ac18c 305 * Useful for debugging. Dumps all members into a single string, using
akashvibhute 3:dfc8da7ac18c 306 * internal static memory. This memory will get overridden next time
akashvibhute 3:dfc8da7ac18c 307 * you call the method.
akashvibhute 3:dfc8da7ac18c 308 *
akashvibhute 3:dfc8da7ac18c 309 * @return String representation of this object
akashvibhute 3:dfc8da7ac18c 310 */
akashvibhute 3:dfc8da7ac18c 311 const char* toString(void) const;
akashvibhute 2:a5f8e04bd02b 312
akashvibhute 2:a5f8e04bd02b 313 };
akashvibhute 2:a5f8e04bd02b 314
akashvibhute 3:dfc8da7ac18c 315
akashvibhute 2:a5f8e04bd02b 316
akashvibhute 2:a5f8e04bd02b 317 /**
akashvibhute 2:a5f8e04bd02b 318 * 2014-2015 - Optimized Network Layer for RF24 Radios
akashvibhute 0:c3db0798d9aa 319 *
akashvibhute 0:c3db0798d9aa 320 * This class implements an OSI Network Layer using nRF24L01(+) radios driven
akashvibhute 0:c3db0798d9aa 321 * by RF24 library.
akashvibhute 0:c3db0798d9aa 322 */
akashvibhute 0:c3db0798d9aa 323
akashvibhute 0:c3db0798d9aa 324 class RF24Network
akashvibhute 0:c3db0798d9aa 325 {
akashvibhute 2:a5f8e04bd02b 326 private:
akashvibhute 3:dfc8da7ac18c 327 Timer rf24netTimer;
akashvibhute 3:dfc8da7ac18c 328 /**@}*/
akashvibhute 3:dfc8da7ac18c 329 /**
akashvibhute 3:dfc8da7ac18c 330 * @name Primary Interface
akashvibhute 3:dfc8da7ac18c 331 *
akashvibhute 3:dfc8da7ac18c 332 * These are the main methods you need to operate the network
akashvibhute 3:dfc8da7ac18c 333 */
akashvibhute 3:dfc8da7ac18c 334 /**@{*/
akashvibhute 0:c3db0798d9aa 335 public:
akashvibhute 3:dfc8da7ac18c 336 /**
akashvibhute 3:dfc8da7ac18c 337 * Construct the network
akashvibhute 3:dfc8da7ac18c 338 *
akashvibhute 3:dfc8da7ac18c 339 * @param _radio The underlying radio driver instance
akashvibhute 3:dfc8da7ac18c 340 *
akashvibhute 3:dfc8da7ac18c 341 */
akashvibhute 2:a5f8e04bd02b 342
akashvibhute 3:dfc8da7ac18c 343 RF24Network( RF24& _radio );
akashvibhute 0:c3db0798d9aa 344
akashvibhute 3:dfc8da7ac18c 345 /**
akashvibhute 3:dfc8da7ac18c 346 * Bring up the network using the current radio frequency/channel.
akashvibhute 3:dfc8da7ac18c 347 * Calling begin brings up the network, and configures the address, which designates the location of the node within RF24Network topology.
akashvibhute 3:dfc8da7ac18c 348 * @note Node addresses are specified in Octal format, see <a href=Addressing.html>RF24Network Addressing</a> for more information.
akashvibhute 3:dfc8da7ac18c 349 * @warning Be sure to 'begin' the radio first.
akashvibhute 3:dfc8da7ac18c 350 *
akashvibhute 3:dfc8da7ac18c 351 * **Example 1:** Begin on current radio channel with address 0 (master node)
akashvibhute 3:dfc8da7ac18c 352 * @code
akashvibhute 3:dfc8da7ac18c 353 * network.begin(00);
akashvibhute 3:dfc8da7ac18c 354 * @endcode
akashvibhute 3:dfc8da7ac18c 355 * **Example 2:** Begin with address 01 (child of master)
akashvibhute 3:dfc8da7ac18c 356 * @code
akashvibhute 3:dfc8da7ac18c 357 * network.begin(01);
akashvibhute 3:dfc8da7ac18c 358 * @endcode
akashvibhute 3:dfc8da7ac18c 359 * **Example 3:** Begin with address 011 (child of 01, grandchild of master)
akashvibhute 3:dfc8da7ac18c 360 * @code
akashvibhute 3:dfc8da7ac18c 361 * network.begin(011);
akashvibhute 3:dfc8da7ac18c 362 * @endcode
akashvibhute 3:dfc8da7ac18c 363 *
akashvibhute 3:dfc8da7ac18c 364 * @see begin(uint8_t _channel, uint16_t _node_address )
akashvibhute 3:dfc8da7ac18c 365 * @param _node_address The logical address of this node
akashvibhute 3:dfc8da7ac18c 366 *
akashvibhute 3:dfc8da7ac18c 367 */
akashvibhute 2:a5f8e04bd02b 368
akashvibhute 3:dfc8da7ac18c 369 inline void begin(uint16_t _node_address) {
akashvibhute 3:dfc8da7ac18c 370 begin(USE_CURRENT_CHANNEL,_node_address);
akashvibhute 3:dfc8da7ac18c 371 }
akashvibhute 0:c3db0798d9aa 372
akashvibhute 3:dfc8da7ac18c 373 /**
akashvibhute 3:dfc8da7ac18c 374 * Main layer loop
akashvibhute 3:dfc8da7ac18c 375 *
akashvibhute 3:dfc8da7ac18c 376 * This function must be called regularly to keep the layer going. This is where payloads are
akashvibhute 3:dfc8da7ac18c 377 * re-routed, received, and all the action happens.
akashvibhute 3:dfc8da7ac18c 378 *
akashvibhute 3:dfc8da7ac18c 379 * @see
akashvibhute 3:dfc8da7ac18c 380 *
akashvibhute 3:dfc8da7ac18c 381 * @return Returns the type of the last received payload.
akashvibhute 3:dfc8da7ac18c 382 */
akashvibhute 3:dfc8da7ac18c 383 uint8_t update(void);
akashvibhute 3:dfc8da7ac18c 384
akashvibhute 3:dfc8da7ac18c 385 /**
akashvibhute 3:dfc8da7ac18c 386 * Test whether there is a message available for this node
akashvibhute 3:dfc8da7ac18c 387 *
akashvibhute 3:dfc8da7ac18c 388 * @return Whether there is a message available for this node
akashvibhute 3:dfc8da7ac18c 389 */
akashvibhute 3:dfc8da7ac18c 390 bool available(void);
akashvibhute 2:a5f8e04bd02b 391
akashvibhute 3:dfc8da7ac18c 392 /**
akashvibhute 3:dfc8da7ac18c 393 * Read the next available header
akashvibhute 3:dfc8da7ac18c 394 *
akashvibhute 3:dfc8da7ac18c 395 * Reads the next available header without advancing to the next
akashvibhute 3:dfc8da7ac18c 396 * incoming message. Useful for doing a switch on the message type
akashvibhute 3:dfc8da7ac18c 397 *
akashvibhute 3:dfc8da7ac18c 398 * If there is no message available, the header is not touched
akashvibhute 3:dfc8da7ac18c 399 *
akashvibhute 3:dfc8da7ac18c 400 * @param[out] header The header (envelope) of the next message
akashvibhute 3:dfc8da7ac18c 401 */
akashvibhute 3:dfc8da7ac18c 402 uint16_t peek(RF24NetworkHeader& header);
akashvibhute 0:c3db0798d9aa 403
akashvibhute 3:dfc8da7ac18c 404 /**
akashvibhute 3:dfc8da7ac18c 405 * Read a message
akashvibhute 3:dfc8da7ac18c 406 *
akashvibhute 3:dfc8da7ac18c 407 * @code
akashvibhute 3:dfc8da7ac18c 408 * while ( network.available() ) {
akashvibhute 3:dfc8da7ac18c 409 * RF24NetworkHeader header;
akashvibhute 3:dfc8da7ac18c 410 * uint32_t time;
akashvibhute 3:dfc8da7ac18c 411 * network.peek(header);
akashvibhute 3:dfc8da7ac18c 412 * if(header.type == 'T'){
akashvibhute 3:dfc8da7ac18c 413 * network.read(header,&time,sizeof(time));
akashvibhute 3:dfc8da7ac18c 414 * Serial.print("Got time: ");
akashvibhute 3:dfc8da7ac18c 415 * Serial.println(time);
akashvibhute 3:dfc8da7ac18c 416 * }
akashvibhute 3:dfc8da7ac18c 417 * }
akashvibhute 3:dfc8da7ac18c 418 * @endcode
akashvibhute 3:dfc8da7ac18c 419 * @param[out] header The header (envelope) of this message
akashvibhute 3:dfc8da7ac18c 420 * @param[out] message Pointer to memory where the message should be placed
akashvibhute 3:dfc8da7ac18c 421 * @param maxlen The largest message size which can be held in @p message
akashvibhute 3:dfc8da7ac18c 422 * @return The total number of bytes copied into @p message
akashvibhute 3:dfc8da7ac18c 423 */
akashvibhute 3:dfc8da7ac18c 424 uint16_t read(RF24NetworkHeader& header, void* message, uint16_t maxlen);
akashvibhute 2:a5f8e04bd02b 425
akashvibhute 3:dfc8da7ac18c 426 /**
akashvibhute 3:dfc8da7ac18c 427 * Send a message
akashvibhute 3:dfc8da7ac18c 428 *
akashvibhute 3:dfc8da7ac18c 429 * @note RF24Network now supports fragmentation for very long messages, send as normal. Fragmentation
akashvibhute 3:dfc8da7ac18c 430 * may need to be enabled or configured by editing the RF24Network_config.h file. Default max payload size is 120 bytes.
akashvibhute 3:dfc8da7ac18c 431 *
akashvibhute 3:dfc8da7ac18c 432 * @code
akashvibhute 3:dfc8da7ac18c 433 * uint32_t time = millis();
akashvibhute 3:dfc8da7ac18c 434 * uint16_t to = 00; // Send to master
akashvibhute 3:dfc8da7ac18c 435 * RF24NetworkHeader header(to, 'T'); // Send header type 'T'
akashvibhute 3:dfc8da7ac18c 436 * network.write(header,&time,sizeof(time));
akashvibhute 3:dfc8da7ac18c 437 * @endcode
akashvibhute 3:dfc8da7ac18c 438 * @param[in,out] header The header (envelope) of this message. The critical
akashvibhute 3:dfc8da7ac18c 439 * thing to fill in is the @p to_node field so we know where to send the
akashvibhute 3:dfc8da7ac18c 440 * message. It is then updated with the details of the actual header sent.
akashvibhute 3:dfc8da7ac18c 441 * @param message Pointer to memory where the message is located
akashvibhute 3:dfc8da7ac18c 442 * @param len The size of the message
akashvibhute 3:dfc8da7ac18c 443 * @return Whether the message was successfully received
akashvibhute 3:dfc8da7ac18c 444 */
akashvibhute 3:dfc8da7ac18c 445 bool write(RF24NetworkHeader& header,const void* message, uint16_t len);
akashvibhute 2:a5f8e04bd02b 446
akashvibhute 3:dfc8da7ac18c 447 /**@}*/
akashvibhute 3:dfc8da7ac18c 448 /**
akashvibhute 3:dfc8da7ac18c 449 * @name Advanced Configuration
akashvibhute 3:dfc8da7ac18c 450 *
akashvibhute 3:dfc8da7ac18c 451 * For advanced configuration of the network
akashvibhute 3:dfc8da7ac18c 452 */
akashvibhute 3:dfc8da7ac18c 453 /**@{*/
akashvibhute 3:dfc8da7ac18c 454
akashvibhute 2:a5f8e04bd02b 455
akashvibhute 2:a5f8e04bd02b 456 /**
akashvibhute 3:dfc8da7ac18c 457 * Construct the network in dual head mode using two radio modules.
akashvibhute 3:dfc8da7ac18c 458 * @note Not working on RPi. Radios will share MISO, MOSI and SCK pins, but require separate CE,CS pins.
akashvibhute 3:dfc8da7ac18c 459 * @code
akashvibhute 3:dfc8da7ac18c 460 * RF24 radio(7,8);
akashvibhute 3:dfc8da7ac18c 461 * RF24 radio1(4,5);
akashvibhute 3:dfc8da7ac18c 462 * RF24Network(radio.radio1);
akashvibhute 3:dfc8da7ac18c 463 * @endcode
akashvibhute 3:dfc8da7ac18c 464 * @param _radio The underlying radio driver instance
akashvibhute 3:dfc8da7ac18c 465 * @param _radio1 The second underlying radio driver instance
akashvibhute 3:dfc8da7ac18c 466 */
akashvibhute 3:dfc8da7ac18c 467
akashvibhute 3:dfc8da7ac18c 468 RF24Network( RF24& _radio, RF24& _radio1);
akashvibhute 3:dfc8da7ac18c 469
akashvibhute 3:dfc8da7ac18c 470 /**
akashvibhute 3:dfc8da7ac18c 471 * By default, multicast addresses are divided into levels.
akashvibhute 2:a5f8e04bd02b 472 *
akashvibhute 2:a5f8e04bd02b 473 * Nodes 1-5 share a multicast address, nodes n1-n5 share a multicast address, and nodes n11-n55 share a multicast address.<br>
akashvibhute 2:a5f8e04bd02b 474 *
akashvibhute 2:a5f8e04bd02b 475 * This option is used to override the defaults, and create custom multicast groups that all share a single
akashvibhute 3:dfc8da7ac18c 476 * address. <br>
akashvibhute 2:a5f8e04bd02b 477 * The level should be specified in decimal format 1-6 <br>
akashvibhute 2:a5f8e04bd02b 478 * @see multicastRelay
akashvibhute 2:a5f8e04bd02b 479 * @param level Levels 1 to 6 are available. All nodes at the same level will receive the same
akashvibhute 2:a5f8e04bd02b 480 * messages if in range. Messages will be routed in order of level, low to high by default, with the
akashvibhute 2:a5f8e04bd02b 481 * master node (00) at multicast Level 0
akashvibhute 2:a5f8e04bd02b 482 */
akashvibhute 3:dfc8da7ac18c 483
akashvibhute 2:a5f8e04bd02b 484 void multicastLevel(uint8_t level);
akashvibhute 2:a5f8e04bd02b 485
akashvibhute 2:a5f8e04bd02b 486 /**
akashvibhute 2:a5f8e04bd02b 487 * Enabling this will allow this node to automatically forward received multicast frames to the next highest
akashvibhute 2:a5f8e04bd02b 488 * multicast level. Duplicate frames are filtered out, so multiple forwarding nodes at the same level should
akashvibhute 2:a5f8e04bd02b 489 * not interfere. Forwarded payloads will also be received.
akashvibhute 2:a5f8e04bd02b 490 * @see multicastLevel
akashvibhute 2:a5f8e04bd02b 491 */
akashvibhute 3:dfc8da7ac18c 492
akashvibhute 2:a5f8e04bd02b 493 bool multicastRelay;
akashvibhute 2:a5f8e04bd02b 494
akashvibhute 3:dfc8da7ac18c 495 /**
akashvibhute 3:dfc8da7ac18c 496 * Set up the watchdog timer for sleep mode using the number 0 through 10 to represent the following time periods:<br>
akashvibhute 3:dfc8da7ac18c 497 * wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s
akashvibhute 3:dfc8da7ac18c 498 * @code
akashvibhute 3:dfc8da7ac18c 499 * setup_watchdog(7); // Sets the WDT to trigger every second
akashvibhute 3:dfc8da7ac18c 500 * @endcode
akashvibhute 3:dfc8da7ac18c 501 * @param prescalar The WDT prescaler to define how often the node will wake up. When defining sleep mode cycles, this time period is 1 cycle.
akashvibhute 3:dfc8da7ac18c 502 */
akashvibhute 3:dfc8da7ac18c 503 void setup_watchdog(uint8_t prescalar);
akashvibhute 3:dfc8da7ac18c 504
akashvibhute 3:dfc8da7ac18c 505 /**
akashvibhute 3:dfc8da7ac18c 506 * @note: This value is automatically assigned based on the node address
akashvibhute 3:dfc8da7ac18c 507 * to reduce errors and increase throughput of the network.
akashvibhute 3:dfc8da7ac18c 508 *
akashvibhute 3:dfc8da7ac18c 509 * Sets the timeout period for individual payloads in milliseconds at staggered intervals.
akashvibhute 3:dfc8da7ac18c 510 * Payloads will be retried automatically until success or timeout
akashvibhute 3:dfc8da7ac18c 511 * Set to 0 to use the normal auto retry period defined by radio.setRetries()
akashvibhute 3:dfc8da7ac18c 512 *
akashvibhute 3:dfc8da7ac18c 513 */
akashvibhute 3:dfc8da7ac18c 514
akashvibhute 3:dfc8da7ac18c 515 uint32_t txTimeout; /**< Network timeout value */
akashvibhute 3:dfc8da7ac18c 516
akashvibhute 3:dfc8da7ac18c 517 /**
akashvibhute 3:dfc8da7ac18c 518 * This only affects payloads that are routed by one or more nodes.
akashvibhute 3:dfc8da7ac18c 519 * This specifies how long to wait for an ack from across the network.
akashvibhute 3:dfc8da7ac18c 520 * Radios sending directly to their parent or children nodes do not
akashvibhute 3:dfc8da7ac18c 521 * utilize this value.
akashvibhute 3:dfc8da7ac18c 522 */
akashvibhute 3:dfc8da7ac18c 523
akashvibhute 3:dfc8da7ac18c 524 uint16_t routeTimeout; /**< Timeout for routed payloads */
akashvibhute 3:dfc8da7ac18c 525
akashvibhute 3:dfc8da7ac18c 526
akashvibhute 3:dfc8da7ac18c 527 /**@}*/
akashvibhute 3:dfc8da7ac18c 528 /**
akashvibhute 3:dfc8da7ac18c 529 * @name Advanced Operation
akashvibhute 3:dfc8da7ac18c 530 *
akashvibhute 3:dfc8da7ac18c 531 * For advanced operation of the network
akashvibhute 3:dfc8da7ac18c 532 */
akashvibhute 3:dfc8da7ac18c 533 /**@{*/
akashvibhute 2:a5f8e04bd02b 534
akashvibhute 2:a5f8e04bd02b 535 /**
akashvibhute 3:dfc8da7ac18c 536 * Return the number of failures and successes for all transmitted payloads, routed or sent directly
akashvibhute 3:dfc8da7ac18c 537 * @note This needs to be enabled via #define ENABLE_NETWORK_STATS in RF24Network_config.h
akashvibhute 3:dfc8da7ac18c 538 *
akashvibhute 3:dfc8da7ac18c 539 * @code
akashvibhute 3:dfc8da7ac18c 540 * bool fails, success;
akashvibhute 3:dfc8da7ac18c 541 * network.failures(&fails,&success);
akashvibhute 3:dfc8da7ac18c 542 * @endcode
akashvibhute 3:dfc8da7ac18c 543 *
akashvibhute 3:dfc8da7ac18c 544 */
akashvibhute 3:dfc8da7ac18c 545 void failures(uint32_t *_fails, uint32_t *_ok);
akashvibhute 3:dfc8da7ac18c 546
akashvibhute 3:dfc8da7ac18c 547 #if defined (RF24NetworkMulticast)
akashvibhute 2:a5f8e04bd02b 548
akashvibhute 3:dfc8da7ac18c 549 /**
akashvibhute 3:dfc8da7ac18c 550 * Send a multicast message to multiple nodes at once
akashvibhute 3:dfc8da7ac18c 551 * Allows messages to be rapidly broadcast through the network
akashvibhute 3:dfc8da7ac18c 552 *
akashvibhute 3:dfc8da7ac18c 553 * Multicasting is arranged in levels, with all nodes on the same level listening to the same address
akashvibhute 3:dfc8da7ac18c 554 * Levels are assigned by network level ie: nodes 01-05: Level 1, nodes 011-055: Level 2
akashvibhute 3:dfc8da7ac18c 555 * @see multicastLevel
akashvibhute 3:dfc8da7ac18c 556 * @see multicastRelay
akashvibhute 3:dfc8da7ac18c 557 * @param message Pointer to memory where the message is located
akashvibhute 3:dfc8da7ac18c 558 * @param len The size of the message
akashvibhute 3:dfc8da7ac18c 559 * @param level Multicast level to broadcast to
akashvibhute 3:dfc8da7ac18c 560 * @return Whether the message was successfully sent
akashvibhute 3:dfc8da7ac18c 561 */
akashvibhute 3:dfc8da7ac18c 562
akashvibhute 3:dfc8da7ac18c 563 bool multicast(RF24NetworkHeader& header,const void* message, uint16_t len, uint8_t level);
akashvibhute 3:dfc8da7ac18c 564
akashvibhute 3:dfc8da7ac18c 565
akashvibhute 3:dfc8da7ac18c 566 #endif
akashvibhute 2:a5f8e04bd02b 567
akashvibhute 3:dfc8da7ac18c 568 /**
akashvibhute 3:dfc8da7ac18c 569 * Writes a direct (unicast) payload. This allows routing or sending messages outside of the usual routing paths.
akashvibhute 3:dfc8da7ac18c 570 * The same as write, but a physical address is specified as the last option.
akashvibhute 3:dfc8da7ac18c 571 * The payload will be written to the physical address, and routed as necessary by the recipient
akashvibhute 3:dfc8da7ac18c 572 */
akashvibhute 3:dfc8da7ac18c 573 bool write(RF24NetworkHeader& header,const void* message, uint16_t len, uint16_t writeDirect);
akashvibhute 0:c3db0798d9aa 574
akashvibhute 3:dfc8da7ac18c 575 /**
akashvibhute 3:dfc8da7ac18c 576 * Sleep this node - For AVR devices only
akashvibhute 3:dfc8da7ac18c 577 * @note NEW - Nodes can now be slept while the radio is not actively transmitting. This must be manually enabled by uncommenting
akashvibhute 3:dfc8da7ac18c 578 * the #define ENABLE_SLEEP_MODE in RF24Network_config.h
akashvibhute 3:dfc8da7ac18c 579 * @note Setting the interruptPin to 255 will disable interrupt wake-ups
akashvibhute 3:dfc8da7ac18c 580 * @note The watchdog timer should be configured in setup() if using sleep mode.
akashvibhute 3:dfc8da7ac18c 581 * This function will sleep the node, with the radio still active in receive mode.
akashvibhute 3:dfc8da7ac18c 582 *
akashvibhute 3:dfc8da7ac18c 583 * The node can be awoken in two ways, both of which can be enabled simultaneously:
akashvibhute 3:dfc8da7ac18c 584 * 1. An interrupt - usually triggered by the radio receiving a payload. Must use pin 2 (interrupt 0) or 3 (interrupt 1) on Uno, Nano, etc.
akashvibhute 3:dfc8da7ac18c 585 * 2. The watchdog timer waking the MCU after a designated period of time, can also be used instead of delays to control transmission intervals.
akashvibhute 3:dfc8da7ac18c 586 * @code
akashvibhute 3:dfc8da7ac18c 587 * if(!network.available()){ network.sleepNode(1,0); } //Sleeps the node for 1 second or a payload is received
akashvibhute 3:dfc8da7ac18c 588 *
akashvibhute 3:dfc8da7ac18c 589 * Other options:
akashvibhute 3:dfc8da7ac18c 590 * network.sleepNode(0,0); // Sleep this node for the designated time period, or a payload is received.
akashvibhute 3:dfc8da7ac18c 591 * network.sleepNode(1,255); // Sleep this node for 1 cycle. Do not wake up until then, even if a payload is received ( no interrupt )
akashvibhute 3:dfc8da7ac18c 592 * @endcode
akashvibhute 3:dfc8da7ac18c 593 * @see setup_watchdog()
akashvibhute 3:dfc8da7ac18c 594 * @param cycles: The node will sleep in cycles of 1s. Using 2 will sleep 2 WDT cycles, 3 sleeps 3WDT cycles...
akashvibhute 3:dfc8da7ac18c 595 * @param interruptPin: The interrupt number to use (0,1) for pins two and three on Uno,Nano. More available on Mega etc.
akashvibhute 3:dfc8da7ac18c 596 * @return True if sleepNode completed normally, after the specified number of cycles. False if sleep was interrupted
akashvibhute 3:dfc8da7ac18c 597 */
akashvibhute 3:dfc8da7ac18c 598 bool sleepNode( unsigned int cycles, int interruptPin );
akashvibhute 2:a5f8e04bd02b 599
akashvibhute 2:a5f8e04bd02b 600
akashvibhute 3:dfc8da7ac18c 601 /**
akashvibhute 3:dfc8da7ac18c 602 * This node's parent address
akashvibhute 3:dfc8da7ac18c 603 *
akashvibhute 3:dfc8da7ac18c 604 * @return This node's parent address, or -1 if this is the base
akashvibhute 3:dfc8da7ac18c 605 */
akashvibhute 3:dfc8da7ac18c 606 uint16_t parent() const;
akashvibhute 3:dfc8da7ac18c 607
akashvibhute 3:dfc8da7ac18c 608 /**
akashvibhute 3:dfc8da7ac18c 609 * Provided a node address and a pipe number, will return the RF24Network address of that child pipe for that node
akashvibhute 2:a5f8e04bd02b 610 */
akashvibhute 3:dfc8da7ac18c 611 uint16_t addressOfPipe( uint16_t node,uint8_t pipeNo );
akashvibhute 2:a5f8e04bd02b 612
akashvibhute 3:dfc8da7ac18c 613 /**
akashvibhute 3:dfc8da7ac18c 614 * @note Addresses are specified in octal: 011, 034
akashvibhute 3:dfc8da7ac18c 615 * @return True if a supplied address is valid
akashvibhute 3:dfc8da7ac18c 616 */
akashvibhute 3:dfc8da7ac18c 617 bool is_valid_address( uint16_t node );
akashvibhute 2:a5f8e04bd02b 618
akashvibhute 3:dfc8da7ac18c 619 /**@}*/
akashvibhute 3:dfc8da7ac18c 620 /**
akashvibhute 3:dfc8da7ac18c 621 * @name Deprecated
akashvibhute 3:dfc8da7ac18c 622 *
akashvibhute 3:dfc8da7ac18c 623 * Maintained for backwards compatibility
akashvibhute 3:dfc8da7ac18c 624 */
akashvibhute 3:dfc8da7ac18c 625 /**@{*/
akashvibhute 2:a5f8e04bd02b 626
akashvibhute 3:dfc8da7ac18c 627 /**
akashvibhute 3:dfc8da7ac18c 628 * Bring up the network on a specific radio frequency/channel.
akashvibhute 3:dfc8da7ac18c 629 * @note Use radio.setChannel() to configure the radio channel
akashvibhute 3:dfc8da7ac18c 630 *
akashvibhute 3:dfc8da7ac18c 631 * **Example 1:** Begin on channel 90 with address 0 (master node)
akashvibhute 3:dfc8da7ac18c 632 * @code
akashvibhute 3:dfc8da7ac18c 633 * network.begin(90,0);
akashvibhute 3:dfc8da7ac18c 634 * @endcode
akashvibhute 3:dfc8da7ac18c 635 * **Example 2:** Begin on channel 90 with address 01 (child of master)
akashvibhute 3:dfc8da7ac18c 636 * @code
akashvibhute 3:dfc8da7ac18c 637 * network.begin(90,01);
akashvibhute 3:dfc8da7ac18c 638 * @endcode
akashvibhute 3:dfc8da7ac18c 639 * **Example 3:** Begin on channel 90 with address 011 (child of 01, grandchild of master)
akashvibhute 3:dfc8da7ac18c 640 * @code
akashvibhute 3:dfc8da7ac18c 641 * network.begin(90,011);
akashvibhute 3:dfc8da7ac18c 642 * @endcode
akashvibhute 3:dfc8da7ac18c 643 *
akashvibhute 3:dfc8da7ac18c 644 * @param _channel The RF channel to operate on
akashvibhute 3:dfc8da7ac18c 645 * @param _node_address The logical address of this node
akashvibhute 3:dfc8da7ac18c 646 *
akashvibhute 3:dfc8da7ac18c 647 */
akashvibhute 3:dfc8da7ac18c 648 void begin(uint8_t _channel, uint16_t _node_address );
akashvibhute 2:a5f8e04bd02b 649
akashvibhute 3:dfc8da7ac18c 650 /**@}*/
akashvibhute 3:dfc8da7ac18c 651 /**
akashvibhute 3:dfc8da7ac18c 652 * @name External Applications/Systems
akashvibhute 3:dfc8da7ac18c 653 *
akashvibhute 3:dfc8da7ac18c 654 * Interface for External Applications and Systems ( RF24Mesh, RF24Ethernet )
akashvibhute 3:dfc8da7ac18c 655 */
akashvibhute 3:dfc8da7ac18c 656 /**@{*/
akashvibhute 2:a5f8e04bd02b 657
akashvibhute 3:dfc8da7ac18c 658 /** The raw system frame buffer of received data. */
akashvibhute 2:a5f8e04bd02b 659
akashvibhute 3:dfc8da7ac18c 660 uint8_t frame_buffer[MAX_FRAME_SIZE];
akashvibhute 0:c3db0798d9aa 661
akashvibhute 3:dfc8da7ac18c 662 /**
akashvibhute 3:dfc8da7ac18c 663 * **Linux** <br>
akashvibhute 3:dfc8da7ac18c 664 * Data with a header type of EXTERNAL_DATA_TYPE will be loaded into a separate queue.
akashvibhute 3:dfc8da7ac18c 665 * The data can be accessed as follows:
akashvibhute 3:dfc8da7ac18c 666 * @code
akashvibhute 3:dfc8da7ac18c 667 * RF24NetworkFrame f;
akashvibhute 3:dfc8da7ac18c 668 * while(network.external_queue.size() > 0){
akashvibhute 3:dfc8da7ac18c 669 * f = network.external_queue.front();
akashvibhute 3:dfc8da7ac18c 670 * uint16_t dataSize = f.message_size;
akashvibhute 3:dfc8da7ac18c 671 * //read the frame message buffer
akashvibhute 3:dfc8da7ac18c 672 * memcpy(&myBuffer,&f.message_buffer,dataSize);
akashvibhute 3:dfc8da7ac18c 673 * network.external_queue.pop();
akashvibhute 3:dfc8da7ac18c 674 * }
akashvibhute 3:dfc8da7ac18c 675 * @endcode
akashvibhute 3:dfc8da7ac18c 676 */
akashvibhute 2:a5f8e04bd02b 677
akashvibhute 0:c3db0798d9aa 678
akashvibhute 3:dfc8da7ac18c 679 #if !defined ( DISABLE_FRAGMENTATION )
akashvibhute 3:dfc8da7ac18c 680 /**
akashvibhute 3:dfc8da7ac18c 681 * **ARDUINO** <br>
akashvibhute 3:dfc8da7ac18c 682 * The frag_ptr is only used with Arduino (not RPi/Linux) and is mainly used for external data systems like RF24Ethernet. When
akashvibhute 3:dfc8da7ac18c 683 * an EXTERNAL_DATA payload type is received, and returned from network.update(), the frag_ptr will always point to the starting
akashvibhute 3:dfc8da7ac18c 684 * memory location of the received frame. <br>This is used by external data systems (RF24Ethernet) to immediately copy the received
akashvibhute 3:dfc8da7ac18c 685 * data to a buffer, without using the user-cache.
akashvibhute 3:dfc8da7ac18c 686 *
akashvibhute 3:dfc8da7ac18c 687 * @see RF24NetworkFrame
akashvibhute 3:dfc8da7ac18c 688 *
akashvibhute 3:dfc8da7ac18c 689 * @code
akashvibhute 3:dfc8da7ac18c 690 * uint8_t return_type = network.update();
akashvibhute 3:dfc8da7ac18c 691 * if(return_type == EXTERNAL_DATA_TYPE){
akashvibhute 3:dfc8da7ac18c 692 * uint16_t size = network.frag_ptr->message_size;
akashvibhute 3:dfc8da7ac18c 693 * memcpy(&myDataBuffer,network.frag_ptr->message_buffer,network.frag_ptr->message_size);
akashvibhute 3:dfc8da7ac18c 694 * }
akashvibhute 3:dfc8da7ac18c 695 * @endcode
akashvibhute 3:dfc8da7ac18c 696 * Linux devices (defined as RF24_LINUX) currently cache all payload types, and do not utilize frag_ptr.
akashvibhute 3:dfc8da7ac18c 697 */
akashvibhute 3:dfc8da7ac18c 698 RF24NetworkFrame* frag_ptr;
akashvibhute 3:dfc8da7ac18c 699 #endif
akashvibhute 3:dfc8da7ac18c 700
akashvibhute 3:dfc8da7ac18c 701 /**
akashvibhute 3:dfc8da7ac18c 702 * Variable to determine whether update() will return after the radio buffers have been emptied (DEFAULT), or
akashvibhute 3:dfc8da7ac18c 703 * whether to return immediately when (most) system types are received.
akashvibhute 3:dfc8da7ac18c 704 *
akashvibhute 3:dfc8da7ac18c 705 * As an example, this is used with RF24Mesh to catch and handle system messages without loading them into the user cache.
akashvibhute 3:dfc8da7ac18c 706 *
akashvibhute 3:dfc8da7ac18c 707 * The following reserved/system message types are handled automatically, and not returned.
akashvibhute 3:dfc8da7ac18c 708 *
akashvibhute 3:dfc8da7ac18c 709 * | System Message Types <br> (Not Returned) |
akashvibhute 3:dfc8da7ac18c 710 * |-----------------------|
akashvibhute 3:dfc8da7ac18c 711 * | NETWORK_ADDR_RESPONSE |
akashvibhute 3:dfc8da7ac18c 712 * | NETWORK_ACK |
akashvibhute 3:dfc8da7ac18c 713 * | NETWORK_PING |
akashvibhute 3:dfc8da7ac18c 714 * | NETWORK_POLL <br>(With multicast enabled) |
akashvibhute 3:dfc8da7ac18c 715 * | NETWORK_REQ_ADDRESS |
akashvibhute 3:dfc8da7ac18c 716 *
akashvibhute 3:dfc8da7ac18c 717 */
akashvibhute 3:dfc8da7ac18c 718 bool returnSysMsgs;
akashvibhute 3:dfc8da7ac18c 719
akashvibhute 3:dfc8da7ac18c 720 /**
akashvibhute 3:dfc8da7ac18c 721 * Network Flags allow control of data flow
akashvibhute 3:dfc8da7ac18c 722 *
akashvibhute 3:dfc8da7ac18c 723 * Incoming Blocking: If the network user-cache is full, lets radio cache fill up. Radio ACKs are not sent when radio internal cache is full.<br>
akashvibhute 3:dfc8da7ac18c 724 * This behaviour may seem to result in more failed sends, but the payloads would have otherwise been dropped due to the cache being full.<br>
akashvibhute 3:dfc8da7ac18c 725 *
akashvibhute 3:dfc8da7ac18c 726 * | FLAGS | Value | Description |
akashvibhute 3:dfc8da7ac18c 727 * |-------|-------|-------------|
akashvibhute 3:dfc8da7ac18c 728 * |FLAG_HOLD_INCOMING| 1(bit_1) | INTERNAL: Set automatically when a fragmented payload will exceed the available cache |
akashvibhute 3:dfc8da7ac18c 729 * |FLAG_BYPASS_HOLDS| 2(bit_2) | EXTERNAL: Can be used to prevent holds from blocking. Note: Holds are disabled & re-enabled by RF24Mesh when renewing addresses. This will cause data loss if incoming data exceeds the available cache space|
akashvibhute 3:dfc8da7ac18c 730 * |FLAG_FAST_FRAG| 4(bit_3) | INTERNAL: Replaces the fastFragTransfer variable, and allows for faster transfers between directly connected nodes. |
akashvibhute 3:dfc8da7ac18c 731 *
akashvibhute 3:dfc8da7ac18c 732 */
akashvibhute 3:dfc8da7ac18c 733 uint8_t networkFlags;
akashvibhute 3:dfc8da7ac18c 734
akashvibhute 3:dfc8da7ac18c 735 private:
akashvibhute 3:dfc8da7ac18c 736
akashvibhute 3:dfc8da7ac18c 737 uint32_t txTime;
akashvibhute 3:dfc8da7ac18c 738
akashvibhute 3:dfc8da7ac18c 739 bool write(uint16_t, uint8_t directTo);
akashvibhute 3:dfc8da7ac18c 740 bool write_to_pipe( uint16_t node, uint8_t pipe, bool multicast );
akashvibhute 3:dfc8da7ac18c 741 uint8_t enqueue(RF24NetworkHeader *header);
akashvibhute 3:dfc8da7ac18c 742
akashvibhute 3:dfc8da7ac18c 743 bool is_direct_child( uint16_t node );
akashvibhute 3:dfc8da7ac18c 744 bool is_descendant( uint16_t node );
akashvibhute 3:dfc8da7ac18c 745
akashvibhute 3:dfc8da7ac18c 746 uint16_t direct_child_route_to( uint16_t node );
akashvibhute 3:dfc8da7ac18c 747 //uint8_t pipe_to_descendant( uint16_t node );
akashvibhute 3:dfc8da7ac18c 748 void setup_address(void);
akashvibhute 3:dfc8da7ac18c 749 bool _write(RF24NetworkHeader& header,const void* message, uint16_t len, uint16_t writeDirect);
akashvibhute 3:dfc8da7ac18c 750
akashvibhute 3:dfc8da7ac18c 751 struct logicalToPhysicalStruct {
akashvibhute 3:dfc8da7ac18c 752 uint16_t send_node;
akashvibhute 3:dfc8da7ac18c 753 uint8_t send_pipe;
akashvibhute 3:dfc8da7ac18c 754 bool multicast;
akashvibhute 3:dfc8da7ac18c 755 };
akashvibhute 3:dfc8da7ac18c 756
akashvibhute 3:dfc8da7ac18c 757 bool logicalToPhysicalAddress(logicalToPhysicalStruct *conversionInfo);
akashvibhute 3:dfc8da7ac18c 758
akashvibhute 3:dfc8da7ac18c 759
akashvibhute 3:dfc8da7ac18c 760 RF24& radio; /**< Underlying radio driver, provides link/physical layers */
akashvibhute 3:dfc8da7ac18c 761 #if defined (DUAL_HEAD_RADIO)
akashvibhute 3:dfc8da7ac18c 762 RF24& radio1;
akashvibhute 3:dfc8da7ac18c 763 #endif
akashvibhute 3:dfc8da7ac18c 764 #if defined (RF24NetworkMulticast)
akashvibhute 3:dfc8da7ac18c 765 uint8_t multicast_level;
akashvibhute 3:dfc8da7ac18c 766 #endif
akashvibhute 3:dfc8da7ac18c 767 uint16_t node_address; /**< Logical node address of this unit, 1 .. UINT_MAX */
akashvibhute 3:dfc8da7ac18c 768 //const static int frame_size = 32; /**< How large is each frame over the air */
akashvibhute 3:dfc8da7ac18c 769 uint8_t frame_size;
akashvibhute 3:dfc8da7ac18c 770 const static unsigned int max_frame_payload_size = MAX_FRAME_SIZE-sizeof(RF24NetworkHeader);
akashvibhute 3:dfc8da7ac18c 771
akashvibhute 3:dfc8da7ac18c 772
akashvibhute 3:dfc8da7ac18c 773 #if !defined (NUM_USER_PAYLOADS)
akashvibhute 3:dfc8da7ac18c 774 #define NUM_USER_PAYLOADS 5
akashvibhute 3:dfc8da7ac18c 775 #endif
akashvibhute 3:dfc8da7ac18c 776
akashvibhute 3:dfc8da7ac18c 777 #if defined (DISABLE_USER_PAYLOADS)
akashvibhute 2:a5f8e04bd02b 778 uint8_t frame_queue[1]; /**< Space for a small set of frames that need to be delivered to the app layer */
akashvibhute 3:dfc8da7ac18c 779 #else
akashvibhute 2:a5f8e04bd02b 780 uint8_t frame_queue[MAIN_BUFFER_SIZE]; /**< Space for a small set of frames that need to be delivered to the app layer */
akashvibhute 3:dfc8da7ac18c 781 #endif
akashvibhute 3:dfc8da7ac18c 782
akashvibhute 2:a5f8e04bd02b 783 uint8_t* next_frame; /**< Pointer into the @p frame_queue where we should place the next received frame */
akashvibhute 3:dfc8da7ac18c 784
akashvibhute 3:dfc8da7ac18c 785 #if !defined ( DISABLE_FRAGMENTATION )
akashvibhute 3:dfc8da7ac18c 786 RF24NetworkFrame frag_queue;
akashvibhute 3:dfc8da7ac18c 787 uint8_t frag_queue_message_buffer[MAX_PAYLOAD_SIZE]; //frame size + 1
akashvibhute 3:dfc8da7ac18c 788 #endif
akashvibhute 3:dfc8da7ac18c 789
akashvibhute 3:dfc8da7ac18c 790 //uint8_t frag_queue[MAX_PAYLOAD_SIZE + 11];
akashvibhute 3:dfc8da7ac18c 791 //RF24NetworkFrame frag_queue;
akashvibhute 0:c3db0798d9aa 792
akashvibhute 3:dfc8da7ac18c 793 uint16_t parent_node; /**< Our parent's node address */
akashvibhute 3:dfc8da7ac18c 794 uint8_t parent_pipe; /**< The pipe our parent uses to listen to us */
akashvibhute 3:dfc8da7ac18c 795 uint16_t node_mask; /**< The bits which contain signfificant node address information */
akashvibhute 3:dfc8da7ac18c 796
akashvibhute 3:dfc8da7ac18c 797 #if defined ENABLE_NETWORK_STATS
akashvibhute 3:dfc8da7ac18c 798 static uint32_t nFails;
akashvibhute 3:dfc8da7ac18c 799 static uint32_t nOK;
akashvibhute 3:dfc8da7ac18c 800 #endif
akashvibhute 3:dfc8da7ac18c 801
akashvibhute 2:a5f8e04bd02b 802 public:
akashvibhute 2:a5f8e04bd02b 803
akashvibhute 3:dfc8da7ac18c 804
akashvibhute 2:a5f8e04bd02b 805
akashvibhute 0:c3db0798d9aa 806 };
akashvibhute 0:c3db0798d9aa 807
akashvibhute 0:c3db0798d9aa 808 /**
akashvibhute 2:a5f8e04bd02b 809 * @example helloworld_tx.ino
akashvibhute 0:c3db0798d9aa 810 *
akashvibhute 0:c3db0798d9aa 811 * Simplest possible example of using RF24Network. Put this sketch
akashvibhute 0:c3db0798d9aa 812 * on one node, and helloworld_rx.pde on the other. Tx will send
akashvibhute 0:c3db0798d9aa 813 * Rx a nice message every 2 seconds which rx will print out for us.
akashvibhute 0:c3db0798d9aa 814 */
akashvibhute 0:c3db0798d9aa 815
akashvibhute 0:c3db0798d9aa 816 /**
akashvibhute 2:a5f8e04bd02b 817 * @example helloworld_rx.ino
akashvibhute 0:c3db0798d9aa 818 *
akashvibhute 0:c3db0798d9aa 819 * Simplest possible example of using RF24Network. Put this sketch
akashvibhute 0:c3db0798d9aa 820 * on one node, and helloworld_tx.pde on the other. Tx will send
akashvibhute 0:c3db0798d9aa 821 * Rx a nice message every 2 seconds which rx will print out for us.
akashvibhute 0:c3db0798d9aa 822 */
akashvibhute 0:c3db0798d9aa 823
akashvibhute 0:c3db0798d9aa 824 /**
akashvibhute 2:a5f8e04bd02b 825 * @example Network_Ping.ino
akashvibhute 0:c3db0798d9aa 826 *
akashvibhute 2:a5f8e04bd02b 827 * Example to give users an understanding of addressing and topology in the mesh network
akashvibhute 0:c3db0798d9aa 828 * Using this sketch, each node will send a ping to the base every
akashvibhute 0:c3db0798d9aa 829 * few seconds. The RF24Network library will route the message across
akashvibhute 0:c3db0798d9aa 830 * the mesh to the correct node.
akashvibhute 2:a5f8e04bd02b 831 *
akashvibhute 2:a5f8e04bd02b 832 */
akashvibhute 2:a5f8e04bd02b 833
akashvibhute 2:a5f8e04bd02b 834 /**
akashvibhute 2:a5f8e04bd02b 835 * @example Network_Ping_Sleep.ino
akashvibhute 2:a5f8e04bd02b 836 *
akashvibhute 2:a5f8e04bd02b 837 * Example: This is almost exactly the same as the Network_Ping example, but with use
akashvibhute 2:a5f8e04bd02b 838 * of the integrated sleep mode.
akashvibhute 2:a5f8e04bd02b 839 *
akashvibhute 2:a5f8e04bd02b 840 * This example demonstrates how nodes on the network utilize sleep mode to conserve power. For example,
akashvibhute 2:a5f8e04bd02b 841 * the radio itself will draw about 13.5mA in receive mode. In sleep mode, it will use as little as 22ua (.000022mA)
akashvibhute 2:a5f8e04bd02b 842 * of power when not actively transmitting or receiving data. In addition, the Arduino is powered down as well,
akashvibhute 2:a5f8e04bd02b 843 * dropping network power consumption dramatically compared to previous capabilities. <br>
akashvibhute 2:a5f8e04bd02b 844 * Note: Sleeping nodes generate traffic that will wake other nodes up. This may be mitigated with further modifications. Sleep
akashvibhute 2:a5f8e04bd02b 845 * payloads are currently always routed to the master node, which will wake up intermediary nodes. Routing nodes can be configured
akashvibhute 2:a5f8e04bd02b 846 * to go back to sleep immediately.
akashvibhute 2:a5f8e04bd02b 847 * The displayed millis() count will give an indication of how much a node has been sleeping compared to the others, as millis() will
akashvibhute 2:a5f8e04bd02b 848 * not increment while a node sleeps.
akashvibhute 2:a5f8e04bd02b 849 *<br>
akashvibhute 2:a5f8e04bd02b 850 * - Using this sketch, each node will send a ping to every other node in the network every few seconds.<br>
akashvibhute 2:a5f8e04bd02b 851 * - The RF24Network library will route the message across the mesh to the correct node.<br>
akashvibhute 2:a5f8e04bd02b 852 *
akashvibhute 0:c3db0798d9aa 853 */
akashvibhute 0:c3db0798d9aa 854
akashvibhute 0:c3db0798d9aa 855 /**
akashvibhute 0:c3db0798d9aa 856 * @example sensornet.pde
akashvibhute 0:c3db0798d9aa 857 *
akashvibhute 0:c3db0798d9aa 858 * Example of a sensor network.
akashvibhute 0:c3db0798d9aa 859 * This sketch demonstrates how to use the RF24Network library to
akashvibhute 0:c3db0798d9aa 860 * manage a set of low-power sensor nodes which mostly sleep but
akashvibhute 0:c3db0798d9aa 861 * awake regularly to send readings to the base.
akashvibhute 0:c3db0798d9aa 862 */
akashvibhute 0:c3db0798d9aa 863 /**
akashvibhute 0:c3db0798d9aa 864 * @mainpage Network Layer for RF24 Radios
akashvibhute 0:c3db0798d9aa 865 *
akashvibhute 0:c3db0798d9aa 866 * This class implements an <a href="http://en.wikipedia.org/wiki/Network_layer">OSI Network Layer</a> using nRF24L01(+) radios driven
akashvibhute 2:a5f8e04bd02b 867 * by the newly optimized <a href="http://tmrh20.github.com/RF24/">RF24</a> library fork.
akashvibhute 0:c3db0798d9aa 868 *
akashvibhute 0:c3db0798d9aa 869 * @section Purpose Purpose/Goal
akashvibhute 0:c3db0798d9aa 870 *
akashvibhute 2:a5f8e04bd02b 871 * Original: Create an alternative to ZigBee radios for Arduino communication.
akashvibhute 3:dfc8da7ac18c 872 *
akashvibhute 2:a5f8e04bd02b 873 * New: Enhance the current functionality for maximum efficiency, reliability, and speed
akashvibhute 0:c3db0798d9aa 874 *
akashvibhute 2:a5f8e04bd02b 875 * Xbees are excellent little radios, backed up by a mature and robust standard
akashvibhute 0:c3db0798d9aa 876 * protocol stack. They are also expensive.
akashvibhute 0:c3db0798d9aa 877 *
akashvibhute 2:a5f8e04bd02b 878 * For many Arduino uses, they seem like overkill. So I am working to improve the current
akashvibhute 2:a5f8e04bd02b 879 * standard for nRF24L01 radios. The best RF24 modules are available for less than
akashvibhute 0:c3db0798d9aa 880 * $6 from many sources. With the RF24Network layer, I hope to cover many
akashvibhute 0:c3db0798d9aa 881 * common communication scenarios.
akashvibhute 0:c3db0798d9aa 882 *
akashvibhute 0:c3db0798d9aa 883 * Please see the @ref Zigbee page for a comparison against the ZigBee protocols
akashvibhute 0:c3db0798d9aa 884 *
akashvibhute 0:c3db0798d9aa 885 * @section Features Features
akashvibhute 0:c3db0798d9aa 886 *
akashvibhute 3:dfc8da7ac18c 887 * <b>Whats new? </b><br>
akashvibhute 2:a5f8e04bd02b 888 * @li New: (Dec 8) Merge of RPi and Arduino code. Finally moving closer to a stable release. Report issues at https://github.com/TMRh20/RF24Network/issues
akashvibhute 2:a5f8e04bd02b 889 * @li New functionality: (Dec 8) Support for fragmented multicast payloads on both RPi and Arduino
akashvibhute 3:dfc8da7ac18c 890 * @li New functionality: (Nov 24) Fragmentation & reassembly supported on both RPi and Arduino
akashvibhute 2:a5f8e04bd02b 891 * @li Note: structure of network frames is changed, these are only used by external applications like RF24Ethernet and RF24toTUN, and for fragmentation
akashvibhute 2:a5f8e04bd02b 892 * @li New functionality: User message types 1 through 64 will not receive a network ack
akashvibhute 2:a5f8e04bd02b 893 *
akashvibhute 0:c3db0798d9aa 894 * The layer provides:
akashvibhute 2:a5f8e04bd02b 895 * @li <b>New</b> (2014): Network ACKs: Efficient acknowledgement of network-wide transmissions, via dynamic radio acks and network protocol acks.
akashvibhute 2:a5f8e04bd02b 896 * @li <b>New</b> (2014): Updated addressing standard for optimal radio transmission.
akashvibhute 2:a5f8e04bd02b 897 * @li <b>New</b> (2014): Extended timeouts and staggered timeout intervals. The new txTimeout variable allows fully automated extended timeout periods via auto-retry/auto-reUse of payloads.
akashvibhute 2:a5f8e04bd02b 898 * @li <b>New</b> (2014): Optimization to the core library provides improvements to reliability, speed and efficiency. See https://tmrh20.github.io/RF24 for more info.
akashvibhute 2:a5f8e04bd02b 899 * @li <b>New</b> (2014): Built in sleep mode using interrupts. (Still under development. (Enable via RF24Network_config.h))
akashvibhute 2:a5f8e04bd02b 900 * @li <b>New</b> (2014): Dual headed operation: The use of dual radios for busy routing nodes or the master node enhances throughput and decreases errors. See the <a href="Tuning.html">Tuning</a> section.
akashvibhute 0:c3db0798d9aa 901 * @li Host Addressing. Each node has a logical address on the local network.
akashvibhute 0:c3db0798d9aa 902 * @li Message Forwarding. Messages can be sent from one node to any other, and
akashvibhute 0:c3db0798d9aa 903 * this layer will get them there no matter how many hops it takes.
akashvibhute 0:c3db0798d9aa 904 * @li Ad-hoc Joining. A node can join a network without any changes to any
akashvibhute 0:c3db0798d9aa 905 * existing nodes.
akashvibhute 0:c3db0798d9aa 906 *
akashvibhute 2:a5f8e04bd02b 907 * The layer does not provide:
akashvibhute 2:a5f8e04bd02b 908 * @li Dynamic address assignment. (See RF24Mesh)
akashvibhute 2:a5f8e04bd02b 909 * @li Layer 4 protocols (TCP/IP - See RF24Ethernet and RF24toTUN)
akashvibhute 0:c3db0798d9aa 910 *
akashvibhute 0:c3db0798d9aa 911 * @section More How to learn more
akashvibhute 0:c3db0798d9aa 912 *
akashvibhute 0:c3db0798d9aa 913 * @li <a href="classRF24Network.html">RF24Network Class Documentation</a>
akashvibhute 2:a5f8e04bd02b 914 * @li <a href="AdvancedConfig.html"> Advanced Configuration Options</a>
akashvibhute 2:a5f8e04bd02b 915 * @li <a href="Addressing.html"> Addressing format</a>
akashvibhute 2:a5f8e04bd02b 916 * @li <a href="Tuning.html"> Topology and Overview</a>
akashvibhute 2:a5f8e04bd02b 917 * @li <a href="https://github.com/TMRh20/RF24Network/archive/Development.zip">Download Current Development Package</a>
akashvibhute 2:a5f8e04bd02b 918 * @li <a href="examples.html">Examples Page</a>. Start with <a href="helloworld_rx_8ino-example.html">helloworld_rx</a> and <a href="helloworld_tx_8ino-example.html">helloworld_tx</a>.
akashvibhute 0:c3db0798d9aa 919 *
akashvibhute 3:dfc8da7ac18c 920 * <b> Additional Information & Add-ons </b>
akashvibhute 2:a5f8e04bd02b 921 * @li <a href="https://github.com/TMRh20/RF24Mesh">RF24Mesh: Dynamic Mesh Layer for RF24Network Dev</a>
akashvibhute 2:a5f8e04bd02b 922 * @li <a href="https://github.com/TMRh20/RF24Ethernet">RF24Ethernet: TCP/IP over RF24Network</a>
akashvibhute 2:a5f8e04bd02b 923 * @li <a href="http://tmrh20.blogspot.com/2014/03/high-speed-data-transfers-and-wireless.html">My Blog: RF24 Optimization Overview</a>
akashvibhute 2:a5f8e04bd02b 924 * @li <a href="http://tmrh20.blogspot.com/2014/03/arduino-radiointercomwireless-audio.html">My Blog: RF24 Wireless Audio</a>
akashvibhute 2:a5f8e04bd02b 925 * @li <a href="http://maniacbug.github.com/RF24/">RF24: Original Author</a>
akashvibhute 0:c3db0798d9aa 926 * @section Topology Topology for Mesh Networks using nRF24L01(+)
akashvibhute 0:c3db0798d9aa 927 *
akashvibhute 0:c3db0798d9aa 928 * This network layer takes advantage of the fundamental capability of the nRF24L01(+) radio to
akashvibhute 2:a5f8e04bd02b 929 * listen actively to up to 6 other radios at once. The network is arranged in a
akashvibhute 0:c3db0798d9aa 930 * <a href="http://en.wikipedia.org/wiki/Network_Topology#Tree">Tree Topology</a>, where
akashvibhute 0:c3db0798d9aa 931 * one node is the base, and all other nodes are children either of that node, or of another.
akashvibhute 0:c3db0798d9aa 932 * Unlike a true mesh network, multiple nodes are not connected together, so there is only one
akashvibhute 0:c3db0798d9aa 933 * path to any given node.
akashvibhute 0:c3db0798d9aa 934 *
akashvibhute 2:a5f8e04bd02b 935 * @section Octal Octal Addressing and Topology
akashvibhute 0:c3db0798d9aa 936 *
akashvibhute 0:c3db0798d9aa 937 * Each node must be assigned an 15-bit address by the administrator. This address exactly
akashvibhute 0:c3db0798d9aa 938 * describes the position of the node within the tree. The address is an octal number. Each
akashvibhute 0:c3db0798d9aa 939 * digit in the address represents a position in the tree further from the base.
akashvibhute 0:c3db0798d9aa 940 *
akashvibhute 0:c3db0798d9aa 941 * @li Node 00 is the base node.
akashvibhute 0:c3db0798d9aa 942 * @li Nodes 01-05 are nodes whose parent is the base.
akashvibhute 0:c3db0798d9aa 943 * @li Node 021 is the second child of node 01.
akashvibhute 0:c3db0798d9aa 944 * @li Node 0321 is the third child of node 021, an so on.
akashvibhute 0:c3db0798d9aa 945 * @li The largest node address is 05555, so 3,125 nodes are allowed on a single channel.
akashvibhute 2:a5f8e04bd02b 946 * An example topology is shown below, with 5 nodes in direct communication with the master node,
akashvibhute 2:a5f8e04bd02b 947 * and multiple leaf nodes spread out at a distance, using intermediate nodes to reach other nodes.
akashvibhute 2:a5f8e04bd02b 948 *
akashvibhute 2:a5f8e04bd02b 949 *| | | 00 | | | 00 | | | | Master Node (00) |
akashvibhute 2:a5f8e04bd02b 950 *|---|----|----|----|----|----|----|----|----|-----------------------------------------------------|
akashvibhute 2:a5f8e04bd02b 951 *| | | 01 | | | 04 | | | | 1st level children of master (00) |
akashvibhute 2:a5f8e04bd02b 952 *| | 011| | 021| | |014 | | | 2nd level children of master. Children of 1st level.|
akashvibhute 2:a5f8e04bd02b 953 *|111| | | 121| 221| | | 114| | 3rd level children of master. Children of 2nd level.|
akashvibhute 2:a5f8e04bd02b 954 *| | | | |1221| |1114|2114|3114| 4th level children of master. Children of 3rd level.|
akashvibhute 0:c3db0798d9aa 955 *
akashvibhute 0:c3db0798d9aa 956 * @section Routing How routing is handled
akashvibhute 0:c3db0798d9aa 957 *
akashvibhute 0:c3db0798d9aa 958 * When sending a message using RF24Network::write(), you fill in the header with the logical
akashvibhute 0:c3db0798d9aa 959 * node address. The network layer figures out the right path to find that node, and sends
akashvibhute 0:c3db0798d9aa 960 * it through the system until it gets to the right place. This works even if the two nodes
akashvibhute 0:c3db0798d9aa 961 * are far separated, as it will send the message down to the base node, and then back out
akashvibhute 0:c3db0798d9aa 962 * to the final destination.
akashvibhute 0:c3db0798d9aa 963 *
akashvibhute 0:c3db0798d9aa 964 * All of this work is handled by the RF24Network::update() method, so be sure to call it
akashvibhute 0:c3db0798d9aa 965 * regularly or your network will miss packets.
akashvibhute 0:c3db0798d9aa 966 *
akashvibhute 0:c3db0798d9aa 967 * @section Startup Starting up a node
akashvibhute 0:c3db0798d9aa 968 *
akashvibhute 0:c3db0798d9aa 969 * When a node starts up, it only has to contact its parent to establish communication.
akashvibhute 0:c3db0798d9aa 970 * No direct connection to the Base node is needed. This is useful in situations where
akashvibhute 0:c3db0798d9aa 971 * relay nodes are being used to bridge the distance to the base, so leaf nodes are out
akashvibhute 0:c3db0798d9aa 972 * of range of the base.
akashvibhute 0:c3db0798d9aa 973 *
akashvibhute 2:a5f8e04bd02b 974 * @section Directionality Directionality
akashvibhute 0:c3db0798d9aa 975 *
akashvibhute 0:c3db0798d9aa 976 * By default all nodes are always listening, so messages will quickly reach
akashvibhute 2:a5f8e04bd02b 977 * their destination.
akashvibhute 2:a5f8e04bd02b 978 *
akashvibhute 2:a5f8e04bd02b 979 * You may choose to sleep any nodes on the network if using interrupts. This is useful in a
akashvibhute 2:a5f8e04bd02b 980 * case where the nodes are operating on batteries and need to sleep. This greatly decreases
akashvibhute 2:a5f8e04bd02b 981 * the power requirements for a sensor network. The leaf nodes can sleep most of the time,
akashvibhute 2:a5f8e04bd02b 982 * and wake every few minutes to send in a reading. Routing nodes can be triggered to wake up
akashvibhute 2:a5f8e04bd02b 983 * whenever a payload is received See sleepNode() in the class documentation, and RFNetwork_config.h
akashvibhute 2:a5f8e04bd02b 984 * to enable sleep mode.
akashvibhute 2:a5f8e04bd02b 985 *
akashvibhute 2:a5f8e04bd02b 986 *
akashvibhute 2:a5f8e04bd02b 987 * @page Addressing Addressing Format: Understanding Addressing and Topology
akashvibhute 2:a5f8e04bd02b 988 * An overview of addressing in RF24Network
akashvibhute 2:a5f8e04bd02b 989 *
akashvibhute 2:a5f8e04bd02b 990 * @section Overview Overview
akashvibhute 2:a5f8e04bd02b 991 * The nrf24 radio modules typically use a 40-bit address format, requiring 5-bytes of storage space per address, and allowing a wide
akashvibhute 3:dfc8da7ac18c 992 * array of addresses to be utilized. In addition, the radios are limited to direct communication with 6 other nodes while using the
akashvibhute 3:dfc8da7ac18c 993 * Enhanced-Shock-Burst (ESB) functionality of the radios.
akashvibhute 2:a5f8e04bd02b 994 *
akashvibhute 2:a5f8e04bd02b 995 * RF24Network uses a simple method of data compression to store the addresses using only 2 bytes, in a format designed to represent the
akashvibhute 2:a5f8e04bd02b 996 * network topology in an intuitive way.
akashvibhute 2:a5f8e04bd02b 997 * See the <a href="Tuning.html"> Topology and Overview</a> page for more info regarding topology.
akashvibhute 2:a5f8e04bd02b 998 *
akashvibhute 2:a5f8e04bd02b 999 * @section Octal_Binary Decimal, Octal and Binary formats
akashvibhute 3:dfc8da7ac18c 1000 *
akashvibhute 2:a5f8e04bd02b 1001 * Say we want to designate a logical address to a node, using a tree topology as defined by the manufacturer.
akashvibhute 3:dfc8da7ac18c 1002 * In the simplest format, we could assign the first node the address of 1, the second 2 and so on.
akashvibhute 2:a5f8e04bd02b 1003 * Since a single node can only connect to 6 other nodes (1 parent and 5 children) subnets need to be created if using more than 6 nodes.<br>
akashvibhute 2:a5f8e04bd02b 1004 * In this case the children of node 1 could simply be designated as 11,21,31,41, and 51<br>
akashvibhute 3:dfc8da7ac18c 1005 * Children of node 2 could be designated as 12,22,32,42, and 52
akashvibhute 3:dfc8da7ac18c 1006 *
akashvibhute 2:a5f8e04bd02b 1007 * The above example is exactly how RF24Network manages the addresses, but they are represented in Octal format.
akashvibhute 3:dfc8da7ac18c 1008 *
akashvibhute 3:dfc8da7ac18c 1009 * <b>Decimal, Octal and Binary</b>
akashvibhute 3:dfc8da7ac18c 1010 * <table>
akashvibhute 2:a5f8e04bd02b 1011 * <tr bgcolor="#a3b4d7" >
akashvibhute 2:a5f8e04bd02b 1012 * <td> Decimal </td> <td> Binary </td><td> Decimal </td> <td> Binary </td><td> Decimal </td> <td> Binary </td>
akashvibhute 2:a5f8e04bd02b 1013 * </tr><tr>
akashvibhute 2:a5f8e04bd02b 1014 * <td> 1 </td> <td> 00000001 </td><td> 11 </td> <td> 00001011 </td><td> 111 </td> <td> 01101111 </td>
akashvibhute 2:a5f8e04bd02b 1015 * </tr><tr bgcolor="#a3b4d7" >
akashvibhute 2:a5f8e04bd02b 1016 * <td> Octal </td> <td> Binary </td><td> Octal </td> <td> Binary </td><td> Octal </td> <td> Binary </td>
akashvibhute 2:a5f8e04bd02b 1017 * </tr><tr>
akashvibhute 2:a5f8e04bd02b 1018 * <td> 1 </td> <td> 00000001 </td><td> 011 </td> <td> 00001001 </td><td> 0111 </td> <td> 1001001 </td>
akashvibhute 2:a5f8e04bd02b 1019 * </tr>
akashvibhute 2:a5f8e04bd02b 1020 * </table>
akashvibhute 2:a5f8e04bd02b 1021 *
akashvibhute 3:dfc8da7ac18c 1022 *
akashvibhute 3:dfc8da7ac18c 1023 * Since the numbers 0-7 can be represented in exactly three bits, each digit is represented by exactly 3 bits when viewed in octal format.
akashvibhute 3:dfc8da7ac18c 1024 * This allows a very simple method of managing addresses via masking and bit shifting.
akashvibhute 3:dfc8da7ac18c 1025 *
akashvibhute 2:a5f8e04bd02b 1026 * @section DisplayAddresses Displaying Addresses
akashvibhute 2:a5f8e04bd02b 1027 *
akashvibhute 2:a5f8e04bd02b 1028 * When using Arduino devices, octal addresses can be printed in the following manner:
akashvibhute 2:a5f8e04bd02b 1029 * @code
akashvibhute 3:dfc8da7ac18c 1030 * uint16_t address = 0111;
akashvibhute 2:a5f8e04bd02b 1031 * Serial.println(address,OCT);
akashvibhute 2:a5f8e04bd02b 1032 * @endcode
akashvibhute 2:a5f8e04bd02b 1033 *
akashvibhute 2:a5f8e04bd02b 1034 * Printf can also be used, if enabled, or if using linux/RPi
akashvibhute 2:a5f8e04bd02b 1035 * @code
akashvibhute 2:a5f8e04bd02b 1036 * uint16_t address = 0111;
akashvibhute 2:a5f8e04bd02b 1037 * printf("0%o\n",address);
akashvibhute 2:a5f8e04bd02b 1038 * @endcode
akashvibhute 2:a5f8e04bd02b 1039 *
akashvibhute 2:a5f8e04bd02b 1040 * See http://www.cplusplus.com/doc/hex/ for more information<br>
akashvibhute 3:dfc8da7ac18c 1041 * See the <a href="Tuning.html"> Topology and Overview</a> page for more info regarding topology.
akashvibhute 2:a5f8e04bd02b 1042 *
akashvibhute 2:a5f8e04bd02b 1043 * @page AdvancedConfig Advanced Configuration
akashvibhute 2:a5f8e04bd02b 1044 *
akashvibhute 2:a5f8e04bd02b 1045 * RF24Network offers many features, some of which can be configured by editing the RF24Network_config.h file
akashvibhute 2:a5f8e04bd02b 1046 *
akashvibhute 2:a5f8e04bd02b 1047 * | Configuration Option | Description |
akashvibhute 2:a5f8e04bd02b 1048 * |----------------------|-------------|
akashvibhute 2:a5f8e04bd02b 1049 * |<b> #define RF24NetworkMulticast </b> | This option allows nodes to send and receive multicast payloads. Nodes with multicast enabled can also be configured to relay multicast payloads on to further multicast levels. See multicastRelay |
akashvibhute 2:a5f8e04bd02b 1050 * | <b> #define DISABLE_FRAGMENTATION </b> | Fragmentation is enabled by default, and uses an additional 144 bytes of memory. |
akashvibhute 2:a5f8e04bd02b 1051 * | <b> #define MAX_PAYLOAD_SIZE 144 </b> | The maximum size of payloads defaults to 144 bytes. If used with RF24toTUN and two Raspberry Pi, set this to 1514 (TAP) or 1500 (TUN) |
akashvibhute 2:a5f8e04bd02b 1052 * | <b> #define NUM_USER_PAYLOADS 5 </b> | This is the number of 24-byte payloads the network layer will cache for the user. If using fragmentation, this number * 24 must be larger than MAX_PAYLOAD_SIZE |
akashvibhute 2:a5f8e04bd02b 1053 * | <b> #define DISABLE_USER_PAYLOADS </b> | This option will disable user-caching of payloads entirely. Use with RF24Ethernet to reduce memory usage. (TCP/IP is an external data type, and not cached) |
akashvibhute 2:a5f8e04bd02b 1054 * | <b> #define ENABLE_SLEEP_MODE </b> | Uncomment this option to enable sleep mode for AVR devices. (ATTiny,Uno, etc) |
akashvibhute 2:a5f8e04bd02b 1055 * | <b> #define DUAL_HEAD_RADIO </b> | Uncomment this option to enable use of dual radios |
akashvibhute 2:a5f8e04bd02b 1056 * | **#define ENABLE_NETWORK_STATS** | Enable counting of all successful or failed transmissions, routed or sent directly |
akashvibhute 2:a5f8e04bd02b 1057 *
akashvibhute 2:a5f8e04bd02b 1058 ** @page Tuning Performance and Data Loss: Tuning the Network
akashvibhute 2:a5f8e04bd02b 1059 * Tips and examples for tuning the network and general operation.
akashvibhute 2:a5f8e04bd02b 1060 *
akashvibhute 2:a5f8e04bd02b 1061 * <img src="tmrh20/topologyImage.jpg" alt="Topology" height="75%" width="75%">
akashvibhute 2:a5f8e04bd02b 1062 *
akashvibhute 2:a5f8e04bd02b 1063 * @section General Understanding Radio Communication and Topology
akashvibhute 2:a5f8e04bd02b 1064 * When a transmission takes place from one radio module to another, the receiving radio will communicate
akashvibhute 2:a5f8e04bd02b 1065 * back to the sender with an acknowledgement (ACK) packet, to indicate success. If the sender does not
akashvibhute 3:dfc8da7ac18c 1066 * receive an ACK, the radio automatically engages in a series of timed retries, at set intervals. The
akashvibhute 3:dfc8da7ac18c 1067 * radios use techniques like addressing and numbering of payloads to manage this, but it is all done
akashvibhute 2:a5f8e04bd02b 1068 * automatically by the nrf chip, out of sight from the user.
akashvibhute 2:a5f8e04bd02b 1069 *
akashvibhute 2:a5f8e04bd02b 1070 * When working over a radio network, some of these automated techniques can actually hinder data transmission to a degree.
akashvibhute 3:dfc8da7ac18c 1071 * Retrying failed payloads over and over on a radio network can hinder communication for nearby nodes, or
akashvibhute 2:a5f8e04bd02b 1072 * reduce throughput and errors on routing nodes.
akashvibhute 2:a5f8e04bd02b 1073 *
akashvibhute 2:a5f8e04bd02b 1074 * Radios in this network are linked by <b>addresses</b> assigned to <b>pipes</b>. Each radio can listen
akashvibhute 2:a5f8e04bd02b 1075 * to 6 addresses on 6 pipes, therefore each radio has a parent pipe and 5 child pipes, which are used
akashvibhute 2:a5f8e04bd02b 1076 * to form a tree structure. Nodes communicate directly with their parent and children nodes. Any other
akashvibhute 2:a5f8e04bd02b 1077 * traffic to or from a node must be routed through the network.
akashvibhute 2:a5f8e04bd02b 1078 *
akashvibhute 2:a5f8e04bd02b 1079 * @section Topology Topology of RF24Network
akashvibhute 2:a5f8e04bd02b 1080 *
akashvibhute 2:a5f8e04bd02b 1081 * Anybody who is familiar at all with IP networking should be able to easily understand RF24Network topology. The
akashvibhute 2:a5f8e04bd02b 1082 * master node can be seen as the gateway, with up to 4 directly connected nodes. Each of those nodes creates a
akashvibhute 2:a5f8e04bd02b 1083 * subnet below it, with up to 4 additional child nodes. The numbering scheme can also be related to IP addresses,
akashvibhute 2:a5f8e04bd02b 1084 * for purposes of understanding the topology via subnetting. Nodes can have 5 children if multicast is disabled.
akashvibhute 2:a5f8e04bd02b 1085 *
akashvibhute 3:dfc8da7ac18c 1086 * Expressing RF24Network addresses in IP format:
akashvibhute 2:a5f8e04bd02b 1087 *
akashvibhute 3:dfc8da7ac18c 1088 * As an example, we could designate the master node in theory, as Address 10.10.10.10 <br>
akashvibhute 3:dfc8da7ac18c 1089 * The children nodes of the master would be 10.10.10.1, 10.10.10.2, 10.10.10.3, 10.10.10.4 and 10.10.10.5 <br>
akashvibhute 3:dfc8da7ac18c 1090 * The children nodes of 10.10.10.1 would be 10.10.1.1, 10.10.2.1, 10.10.3.1, 10.10.4.1 and 10.10.5.1 <br>
akashvibhute 3:dfc8da7ac18c 1091 *
akashvibhute 2:a5f8e04bd02b 1092 * In RF24Network, the master is just 00 <br>
akashvibhute 2:a5f8e04bd02b 1093 * Children of master are 01,02,03,04,05 <br>
akashvibhute 2:a5f8e04bd02b 1094 * Children of 01 are 011,021,031,041,051 <br>
akashvibhute 3:dfc8da7ac18c 1095 *
akashvibhute 2:a5f8e04bd02b 1096 * @section Network Routing
akashvibhute 2:a5f8e04bd02b 1097 *
akashvibhute 2:a5f8e04bd02b 1098 * Routing of traffic is handled invisibly to the user, by the network layer. If the network addresses are
akashvibhute 2:a5f8e04bd02b 1099 * assigned in accordance with the physical layout of the network, nodes will route traffic automatically
akashvibhute 2:a5f8e04bd02b 1100 * as required. Users simply constuct a header containing the appropriate destination address, and the network
akashvibhute 2:a5f8e04bd02b 1101 * will forward it through to the correct node. Individual nodes only route individual fragments, so if using
akashvibhute 2:a5f8e04bd02b 1102 * fragmentation, routing nodes do not need it enabled, unless sending or receiving fragmented payloads themselves.
akashvibhute 2:a5f8e04bd02b 1103 *
akashvibhute 2:a5f8e04bd02b 1104 * If routing data between parent and child nodes (marked by direct links on the topology image above) the network
akashvibhute 2:a5f8e04bd02b 1105 * uses built-in acknowledgement and retry functions of the chip to prevent data loss. When payloads are sent to
akashvibhute 2:a5f8e04bd02b 1106 * other nodes, they need to be routed. Routing is managed using a combination of built in ACK requests, and
akashvibhute 2:a5f8e04bd02b 1107 * software driven network ACKs. This allows all routing nodes to forward data very quickly, with only the final
akashvibhute 2:a5f8e04bd02b 1108 * routing node confirming delivery and sending back an
akashvibhute 2:a5f8e04bd02b 1109 * acknowledgement.
akashvibhute 2:a5f8e04bd02b 1110 *
akashvibhute 2:a5f8e04bd02b 1111 * Example: Node 00 sends to node 01. The nodes will use the built in auto-retry and auto-ack functions.<br>
akashvibhute 2:a5f8e04bd02b 1112 * Example: Node 00 sends to node 011. Node 00 will send to node 01 as before. Node 01 will forward the message to
akashvibhute 2:a5f8e04bd02b 1113 * 011. If delivery was successful, node 01 will also forward a message back to node 00, indicating success.
akashvibhute 2:a5f8e04bd02b 1114 *
akashvibhute 2:a5f8e04bd02b 1115 * Old Functionality: Node 00 sends to node 011 using auto-ack. Node 00 first sends to 01, 01 acknowledges.
akashvibhute 2:a5f8e04bd02b 1116 * Node 01 forwards the payload to 011 using auto-ack. If the payload fails between 01 and 011, node 00 has
akashvibhute 3:dfc8da7ac18c 1117 * no way of knowing.
akashvibhute 3:dfc8da7ac18c 1118 *
akashvibhute 2:a5f8e04bd02b 1119 * @note When retrying failed payloads that have been routed, there is a chance of duplicate payloads if the network-ack
akashvibhute 2:a5f8e04bd02b 1120 * is not successful. In this case, it is left up to the user to manage retries and filtering of duplicate payloads.
akashvibhute 2:a5f8e04bd02b 1121 *
akashvibhute 2:a5f8e04bd02b 1122 * Acknowledgements can and should be managed by the application or user. If requesting a response from another node,
akashvibhute 2:a5f8e04bd02b 1123 * an acknowledgement is not required, so a user defined type of 0-64 should be used, to prevent the network from
akashvibhute 2:a5f8e04bd02b 1124 * responding with an acknowledgement. If not requesting a response, and wanting to know if the payload was successful
akashvibhute 2:a5f8e04bd02b 1125 * or not, users can utilize header types 65-127.
akashvibhute 3:dfc8da7ac18c 1126 *
akashvibhute 2:a5f8e04bd02b 1127 * @section TuningOverview Tuning Overview
akashvibhute 2:a5f8e04bd02b 1128 * The RF24 radio modules are generally only capable of either sending or receiving data at any given
akashvibhute 2:a5f8e04bd02b 1129 * time, but have built-in auto-retry mechanisms to prevent the loss of data. These values are adjusted
akashvibhute 2:a5f8e04bd02b 1130 * automatically by the library on startup, but can be further adjusted to reduce data loss, and
akashvibhute 2:a5f8e04bd02b 1131 * thus increase throughput of the network. This page is intended to provide a general overview of its
akashvibhute 2:a5f8e04bd02b 1132 * operation within the context of the network library, and provide guidance for adjusting these values.
akashvibhute 2:a5f8e04bd02b 1133 *
akashvibhute 2:a5f8e04bd02b 1134 * @section RetryTiming Auto-Retry Timing
akashvibhute 2:a5f8e04bd02b 1135 *
akashvibhute 2:a5f8e04bd02b 1136 * The core radio library provides the functionality of adjusting the internal auto-retry interval of the
akashvibhute 2:a5f8e04bd02b 1137 * radio modules. In the network configuration, the radios can be set to automatically retry failed
akashvibhute 2:a5f8e04bd02b 1138 * transmissions at intervals ranging anywhere from 500us (.5ms) up to 4000us (4ms). When operating any
akashvibhute 2:a5f8e04bd02b 1139 * number of radios larger than two, it is important to stagger the assigned intervals, to prevent the
akashvibhute 2:a5f8e04bd02b 1140 * radios from interfering with each other at the radio frequency (RF) layer.
akashvibhute 2:a5f8e04bd02b 1141 *
akashvibhute 2:a5f8e04bd02b 1142 * The library should provide fairly good working values, as it simply staggers the assigned values within
akashvibhute 2:a5f8e04bd02b 1143 * groups of radios in direct communication. This value can be set manually by calling radio.setRetries(X,15);
akashvibhute 2:a5f8e04bd02b 1144 * and adjusting the value of X from 1 to 15 (steps of 250us).
akashvibhute 2:a5f8e04bd02b 1145 *
akashvibhute 2:a5f8e04bd02b 1146 * @section AutoRetry Auto-Retry Count and Extended Timeouts
akashvibhute 2:a5f8e04bd02b 1147 *
akashvibhute 2:a5f8e04bd02b 1148 * The core radio library also provides the ability to adjust the internal auto-retry count of the radio
akashvibhute 2:a5f8e04bd02b 1149 * modules. The default setting is 15 automatic retries per payload, and can be extended by configuring
akashvibhute 2:a5f8e04bd02b 1150 * the network.txTimeout variable. This default retry count should generally be left at 15, as per the
akashvibhute 2:a5f8e04bd02b 1151 * example in the above section. An interval/retry setting of (15,15) will provide 15 retrys at intervals of
akashvibhute 2:a5f8e04bd02b 1152 * 4ms, taking up to 60ms per payload. The library now provides staggered timeout periods by default, but
akashvibhute 2:a5f8e04bd02b 1153 * they can also be adjusted on a per-node basis.
akashvibhute 0:c3db0798d9aa 1154 *
akashvibhute 2:a5f8e04bd02b 1155 * The txTimeout variable is used to extend the retry count to a defined duration in milliseconds. See the
akashvibhute 2:a5f8e04bd02b 1156 * network.txTimeout variable. Timeout periods of extended duration (500+) will generally not help when payloads
akashvibhute 2:a5f8e04bd02b 1157 * are failing due to data collisions, it will only extend the duration of the errors. Extended duration timeouts
akashvibhute 2:a5f8e04bd02b 1158 * should generally only be configured on leaf nodes that do not receive data, or on a dual-headed node.
akashvibhute 2:a5f8e04bd02b 1159 *
akashvibhute 2:a5f8e04bd02b 1160 * @section Examples
akashvibhute 2:a5f8e04bd02b 1161 *
akashvibhute 2:a5f8e04bd02b 1162 * <b>Example 1:</b> Network with master node and three leaf nodes that send data to the master node. None of the leaf
akashvibhute 2:a5f8e04bd02b 1163 * nodes need to receive data.
akashvibhute 2:a5f8e04bd02b 1164 *
akashvibhute 2:a5f8e04bd02b 1165 * a: Master node uses default configuration<br>
akashvibhute 2:a5f8e04bd02b 1166 * b: Leaf nodes can be configured with extended timeout periods to ensure reception by the master.<br>
akashvibhute 2:a5f8e04bd02b 1167 * c:
akashvibhute 2:a5f8e04bd02b 1168 * @code
akashvibhute 2:a5f8e04bd02b 1169 * Leaf 01: network.txTimeout = 500; Leaf 02: network.txTimeout = 573; Leaf 03: network.txTimeout = 653;
akashvibhute 2:a5f8e04bd02b 1170 * @endcode
akashvibhute 2:a5f8e04bd02b 1171 * This configuration will provide a reduction in errors, as the timeouts have been extended, and are staggered
akashvibhute 2:a5f8e04bd02b 1172 * between devices.
akashvibhute 2:a5f8e04bd02b 1173 *
akashvibhute 2:a5f8e04bd02b 1174 *
akashvibhute 2:a5f8e04bd02b 1175 * <b>Example 2:</b> Network with master node and three leaf nodes that send data to the master node. The second leaf
akashvibhute 2:a5f8e04bd02b 1176 * node needs to receive configuration data from the master at set intervals of 1 second, and send data back to the
akashvibhute 2:a5f8e04bd02b 1177 * master node. The other leaf nodes will send basic sensor information every few seconds, and a few dropped payloads
akashvibhute 2:a5f8e04bd02b 1178 * will not affect the operation greatly.
akashvibhute 2:a5f8e04bd02b 1179 *
akashvibhute 2:a5f8e04bd02b 1180 * a: Master node configured with extended timeouts of .5 seconds, and increased retry delay:
akashvibhute 2:a5f8e04bd02b 1181 * @code
akashvibhute 2:a5f8e04bd02b 1182 * radio.setRetries(11,15);
akashvibhute 2:a5f8e04bd02b 1183 * network.txTimeout = 500;
akashvibhute 2:a5f8e04bd02b 1184 * @endcode
akashvibhute 2:a5f8e04bd02b 1185 * b: Second leaf node configured with a similar timeout period and retry delay:
akashvibhute 2:a5f8e04bd02b 1186 * @code
akashvibhute 2:a5f8e04bd02b 1187 * radio.setRetries(8,15);
akashvibhute 2:a5f8e04bd02b 1188 * network.txTimeout = 553;
akashvibhute 2:a5f8e04bd02b 1189 * @endcode
akashvibhute 2:a5f8e04bd02b 1190 * c: First and third leaf nodes configured with default timeout periods or slightly increased timout periods.
akashvibhute 2:a5f8e04bd02b 1191 *
akashvibhute 2:a5f8e04bd02b 1192 * @section DualHead Dual Headed Operation
akashvibhute 2:a5f8e04bd02b 1193 *
akashvibhute 2:a5f8e04bd02b 1194 * The library now supports a dual radio configuration to further enhance network performance, while reducing errors on
akashvibhute 2:a5f8e04bd02b 1195 * busy networks. Master nodes or relay nodes with a large number of child nodes can benefit somewhat from a dual headed
akashvibhute 2:a5f8e04bd02b 1196 * configuration, since one radio is used for receiving, and the other entirely for transmission.
akashvibhute 2:a5f8e04bd02b 1197 *
akashvibhute 2:a5f8e04bd02b 1198 * To configure a dual headed node:
akashvibhute 2:a5f8e04bd02b 1199 * 1. Edit the RF24Network_config.h file, and uncomment #define DUAL_HEAD_RADIO
akashvibhute 2:a5f8e04bd02b 1200 * 2. Connect another radio, using the same MOSI, MISO, and SCK lines.
akashvibhute 2:a5f8e04bd02b 1201 * 3. Choose another two pins to use for CE and CS on the second radio. Connect them.
akashvibhute 2:a5f8e04bd02b 1202 * 4. Setup the radio and network like so:
akashvibhute 2:a5f8e04bd02b 1203 *
akashvibhute 2:a5f8e04bd02b 1204 * @code
akashvibhute 2:a5f8e04bd02b 1205 * RF24 radio(7,8); // Using CE (7) and CS (8) for first radio
akashvibhute 2:a5f8e04bd02b 1206 * RF24 radio1(4,5); // Using CE (4) and CS (5) for second radio
akashvibhute 2:a5f8e04bd02b 1207 * RF24Network network(radio,radio1); // Set up the network using both radios
akashvibhute 2:a5f8e04bd02b 1208 *
akashvibhute 2:a5f8e04bd02b 1209 * Then in setup(), call radio.begin(); and radio1.begin(); before network.begin();
akashvibhute 2:a5f8e04bd02b 1210 * @endcode
akashvibhute 2:a5f8e04bd02b 1211 *
akashvibhute 2:a5f8e04bd02b 1212 * 5. Upload to MCU. The node will now use the first radio to receive data, and radio1 to transmit, preventing data loss on a busy network.
akashvibhute 2:a5f8e04bd02b 1213 * 6. Re-comment the #define in the config file as required if configuring other single-headed radios.
akashvibhute 2:a5f8e04bd02b 1214 *
akashvibhute 2:a5f8e04bd02b 1215 *
akashvibhute 2:a5f8e04bd02b 1216 * Any node can be configured in dual-head mode.
akashvibhute 2:a5f8e04bd02b 1217 *
akashvibhute 2:a5f8e04bd02b 1218 *
akashvibhute 2:a5f8e04bd02b 1219 *
akashvibhute 0:c3db0798d9aa 1220 *
akashvibhute 0:c3db0798d9aa 1221 * @page Zigbee Comparison to ZigBee
akashvibhute 0:c3db0798d9aa 1222 *
akashvibhute 0:c3db0798d9aa 1223 * This network layer is influenced by the design of ZigBee, but does not implement it
akashvibhute 2:a5f8e04bd02b 1224 * directly.
akashvibhute 0:c3db0798d9aa 1225 *
akashvibhute 0:c3db0798d9aa 1226 * @section Advantage Which is better?
akashvibhute 0:c3db0798d9aa 1227 *
akashvibhute 0:c3db0798d9aa 1228 * ZigBee is a much more robust, feature-rich set of protocols, with many different vendors
akashvibhute 0:c3db0798d9aa 1229 * providing compatible chips.
akashvibhute 0:c3db0798d9aa 1230 *
akashvibhute 0:c3db0798d9aa 1231 * RF24Network is cheap. While ZigBee radios are well over $20, nRF24L01 modules can be found
akashvibhute 2:a5f8e04bd02b 1232 * for under $2. My personal favorite is
akashvibhute 0:c3db0798d9aa 1233 * <a href="http://www.mdfly.com/index.php?main_page=product_info&products_id=82">MDFly RF-IS2401</a>.
akashvibhute 0:c3db0798d9aa 1234 *
akashvibhute 0:c3db0798d9aa 1235 * @section Contrast Similiarities & Differences
akashvibhute 0:c3db0798d9aa 1236 *
akashvibhute 0:c3db0798d9aa 1237 * Here are some comparisons between RF24Network and ZigBee.
akashvibhute 0:c3db0798d9aa 1238 *
akashvibhute 0:c3db0798d9aa 1239 * @li Both networks support Star and Tree topologies. Only Zigbee supports a true mesh.
akashvibhute 2:a5f8e04bd02b 1240 * @li In ZigBee networks, only leaf nodes can sleep
akashvibhute 2:a5f8e04bd02b 1241 * @li ZigBee nodes are configured using AT commands, or a separate Windows application.
akashvibhute 0:c3db0798d9aa 1242 * RF24 nodes are configured by recompiliing the firmware or writing to EEPROM.
akashvibhute 0:c3db0798d9aa 1243 *
akashvibhute 0:c3db0798d9aa 1244 * @section NodeNames Node Naming
akashvibhute 0:c3db0798d9aa 1245 *
akashvibhute 0:c3db0798d9aa 1246 * @li Leaf node: A node at the outer edge of the network with no children. ZigBee calls it
akashvibhute 0:c3db0798d9aa 1247 * an End Device node.
akashvibhute 0:c3db0798d9aa 1248 * @li Relay node: A node which has both parents and children, and relays messages from one
akashvibhute 0:c3db0798d9aa 1249 * to the other. ZigBee calls it a Router.
akashvibhute 0:c3db0798d9aa 1250 * @li Base node. The top of the tree node with no parents, only children. Typically this node
akashvibhute 0:c3db0798d9aa 1251 * will bridge to another kind of network like Ethernet. ZigBee calls it a Co-ordinator node.
akashvibhute 2:a5f8e04bd02b 1252 *
akashvibhute 3:dfc8da7ac18c 1253 *
akashvibhute 2:a5f8e04bd02b 1254 *
akashvibhute 2:a5f8e04bd02b 1255 *
akashvibhute 0:c3db0798d9aa 1256 */
akashvibhute 0:c3db0798d9aa 1257
akashvibhute 0:c3db0798d9aa 1258 #endif // __RF24NETWORK_H__
akashvibhute 2:a5f8e04bd02b 1259