diff --git a/MyConfig.h b/MyConfig.h
index 2a9c5da..b362561 100644
--- a/MyConfig.h
+++ b/MyConfig.h
@@ -483,14 +483,6 @@
#define MY_RF24_ADDR_WIDTH 5
#endif
-/**
- * @def MY_RF24_SANITY_CHECK
- * @brief RF24 sanity check to verify functional RF module
- *
- * This reads back and compares configuration registers. Disable if using non-P modules
- */
-#define MY_RF24_SANITY_CHECK
-
// Enable SOFTSPI for NRF24L01, useful for the W5100 Ethernet module
//#define MY_SOFTSPI
diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp
index eb80ad7..6b14b23 100644
--- a/core/MyTransport.cpp
+++ b/core/MyTransport.cpp
@@ -19,14 +19,6 @@
#include "MyTransport.h"
-// debug
-#if defined(MY_DEBUG)
- #define TRANSPORT_DEBUG(x,...) debug(x, ##__VA_ARGS__)
-#else
- #define TRANSPORT_DEBUG(x,...)
-#endif
-
-
// SM: transitions and update states
static transportState stInit = { stInitTransition, NULL };
static transportState stParent = { stParentTransition, stParentUpdate };
diff --git a/core/MyTransport.h b/core/MyTransport.h
index ad038a5..0b5a5c7 100644
--- a/core/MyTransport.h
+++ b/core/MyTransport.h
@@ -26,115 +26,105 @@
*
* Transport-related log messages, format: [!]SYSTEM:[SUB SYSTEM:]MESSAGE
* - [!] Exclamation mark is prepended in case of error
- * - SYSTEM:
- * - TSM: messages emitted by the transport state machine
- * - TSF: messages emitted by transport support functions
+ * - SYSTEM:
+ * - TSM: messages emitted by the transport state machine
+ * - TSF: messages emitted by transport support functions
* - SUB SYSTEMS:
- * - Transport state machine (TSM)
+ * - Transport state machine (TSM)
* - TSM:INIT from stInit Initialize transport and radio
* - TSM:FPAR from stParent Find parent
* - TSM:ID from stID Check/request node ID, if dynamic node ID set
* - TSM:UPL from stUplink Verify uplink connection by pinging GW
* - TSM:READY from stReady Transport is ready and fully operational
* - TSM:FAILURE from stFailure Failure in transport link or transport HW
- * - Transport support function (TSF)
- * - TSF:CHKUPL from @ref transportCheckUplink(..), checks connection to GW
- * - TSF:ASID from @ref transportAssignNodeID(..), assigns node ID
- * - TSF:PING from @ref transportPingNode(..), pings a node
- * - TSF:CRT from @ref transportClearRoutingTable(..), clears routing table stored in EEPROM
- * - TSF:MSG from @ref transportProcessMessage(..), processes incoming message
- * - TSF:SANCHK from @ref transportInvokeSanityCheck(..), calls transport-specific sanity check
- * - TSF:ROUTE from @ref transportRouteMessage(..), sends message
- * - TSF:SEND from @ref transportSendRoute(..), sends message if transport is ready (exposed)
+ * - Transport support function (TSF)
+ * - TSF:CHKUPL from @ref transportCheckUplink(), checks connection to GW
+ * - TSF:ASID from @ref transportAssignNodeID(), assigns node ID
+ * - TSF:PING from @ref transportPingNode(), pings a node
+ * - TSF:CRT from @ref transportClearRoutingTable(), clears routing table stored in EEPROM
+ * - TSF:MSG from @ref transportProcessMessage(), processes incoming message
+ * - TSF:SANCHK from @ref transportInvokeSanityCheck(), calls transport-specific sanity check
+ * - TSF:ROUTE from @ref transportRouteMessage(), sends message
+ * - TSF:SEND from @ref transportSendRoute(), sends message if transport is ready (exposed)
*
- * TSM state stInit log status / errors
- * - TSM:INIT Transition to stInit state
- * - TSM:INIT:STATID,ID=x Node ID x is static
- * - TSM:INIT:TSP OK Transport device configured and fully operational
- * - TSM:INIT:GW MODE Node is set up as GW, thus omitting ID and findParent states
- * - !TSM:INIT:TSP FAIL Transport device initialization failed
+ * Transport debug log messages:
*
- * TSM state stParent log status / errors
- * - TSM:FPAR Transition to stParent state
- * - TSM:FPAR:STATP=x Static parent x set, skip finding parent
- * - TSM:FPAR:OK Parent node identified
- * - !TSM:FPAR:NO REPLY No potential parents replied to find parent request, retry
- * - !TSM:FPAR:FAIL Finding parent failed, go to failure state
+ * |E| SYS | SUB | Message | Comment
+ * |-|------|-----------|-----------------------|---------------------------------------------------------------------
+ * | | TSM | INIT | | Transition to stInit state
+ * | | TSM | INIT | STATID,ID=%%d | Node ID is static
+ * | | TSM | INIT | TSP OK | Transport device configured and fully operational
+ * | | TSM | INIT | GW MODE | Node is set up as GW, thus omitting ID and findParent states
+ * |!| TSM | INIT | TSP FAIL | Transport device initialization failed
+ * | | TSM | FPAR | | Transition to stParent state
+ * | | TSM | FPAR | STATP=%%d | Static parent set, skip finding parent
+ * | | TSM | FPAR | OK | Parent node identified
+ * |!| TSM | FPAR | NO REPLY | No potential parents replied to find parent request
+ * |!| TSM | FPAR | FAIL | Finding parent failed
+ * | | TSM | ID | | Transition to stID state
+ * | | TSM | ID | OK,ID=%%d | Node ID is valid
+ * | | TSM | ID | REQ | Request node ID from controller
+ * |!| TSM | ID | FAIL,ID=%%d | ID verification failed, ID invalid
+ * | | TSM | UPL | | Transition to stUplink state
+ * | | TSM | UPL | OK | Uplink OK, GW returned ping
+ * |!| TSM | UPL | FAIL | Uplink check failed, i.e. GW could not be pinged
+ * | | TSM | READY | | Transition to stReady, i.e. transport is ready and fully operational
+ * |!| TSM | READY | UPL FAIL,SNP | Too many failed uplink transmissions, search new parent
+ * |!| TSM | READY | FAIL,STATP | Too many failed uplink transmissions, static parent enforced
+ * | | TSM | FAILURE | | Transition to stFailure state
+ * | | TSM | FAILURE | PDT | Power-down transport
+ * | | TSM | FAILURE | RE-INIT | Attempt to re-initialize transport
+ * | | TSF | CHKUPL | OK | Uplink OK
+ * | | TSF | CHKUPL | OK,FCTRL | Uplink OK, flood control prevents pinging GW in too short intervals
+ * | | TSF | CHKUPL | DGWC,O=%%d,N=%%d | Uplink check revealed changed network topology, old distance (O), new distance (N)
+ * | | TSF | CHKUPL | FAIL | No reply received when checking uplink
+ * | | TSF | ASID | OK,ID=%%d | Node ID assigned
+ * |!| TSF | ASID | FAIL,ID=%%d | Assigned ID is invalid
+ * | | TSF | PING | SEND,TO=%%d | Send ping to destination (TO)
+ * | | TSF | MSG | ACK REQ | ACK message requested
+ * | | TSF | MSG | ACK | ACK message, do not proceed but forward to callback
+ * | | TSF | MSG | FPAR RES,ID=%%d,D=%%d | Response to find parent received from node (ID) with distance (D) to GW
+ * | | TSF | MSG | FPAR PREF FOUND | Preferred parent found, i.e. parent defined via MY_PARENT_NODE_ID
+ * | | TSF | MSG | FPAR OK,ID=%%d,D=%%d | Find parent response from node (ID) is valid, distance (D) to GW
+ * | | TSF | MSG | FPAR INACTIVE | Find parent response received, but no find parent request active, skip response
+ * | | TSF | MSG | FPAR REQ,ID=%%d | Find parent request from node (ID)
+ * | | TSF | MSG | PINGED,ID=%%d,HP=%%d | Node pinged by node (ID) with (HP) hops
+ * | | TSF | MSG | PONG RECV,HP=%%d | Pinged node replied with (HP) hops
+ * | | TSF | MSG | BC | Broadcast message received
+ * | | TSF | MSG | GWL OK | Link to GW ok
+ * | | TSF | MSG | FWD BC MSG | Controlled broadcast message forwarding
+ * | | TSF | MSG | REL MSG | Relay message
+ * | | TSF | MSG | REL PxNG,HP=%%d | Relay PING/PONG message, increment hop counter (HP)
+ * |!| TSF | MSG | PVER,%%d!=%%d | Message protocol version mismatch
+ * |!| TSF | MSG | SIGN VERIFY FAIL | Signing verification failed
+ * |!| TSF | MSG | REL MSG,NORP | Node received a message for relaying, but node is not a repeater, message skipped
+ * |!| TSF | MSG | SIGN FAIL | Signing message failed
+ * |!| TSF | MSG | GWL FAIL | GW uplink failed
+ * | | TSF | SANCHK | OK | Sanity check passed
+ * |!| TSF | SANCHK | FAIL | Sanity check failed, attempt to re-initialize radio
+ * | | TSF | CRT | OK | Clearing routing table successful
+ * |!| TSF | ROUTE | FPAR ACTIVE | Finding parent active, message not sent
+ * |!| TSF | ROUTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent
+ * |!| TSF | SEND | TNR | Transport not ready, message cannot be sent
*
- * TSM state stID log status / errors
- * - TSM:ID Transition to stID state
- * - TSM:ID:OK,ID=x Node ID x is valid
- * - TSM:ID:REQ Request node ID from controller
- * - !TSM:ID:FAIL,ID=x ID verification failed, ID x invalid
- *
- * TSM state stUplink log status / errors
- * - TSM:UPL Transition to stUplink state
- * - TSM:UPL:OK Uplink OK, GW returned ping
- * - !TSM:UPL:FAIL Uplink check failed, i.e. GW could not be pinged
- *
- * TSM state stReady log status / errors
- * - TSM:READY Transition to stReady, i.e. transport is ready and fully operational
- * - !TSM:READY:UPL FAIL,SNP Too many failed uplink transmissions, search new parent
- * - !TSM:READY:UPL FAIL,STATP Too many failed uplink transmissions, no SNP, static parent enforced
- *
- * TSM state stFailure information / status
- * - TSM:FAILURE Transition to stFailure state
- * - TSM:FAILURE:PDT Power-down transport
- * - TSM:FAILURE:RE-INIT Attempt to re-initialize transport
- *
- * TSF information / status
- * - TSF:CHKUPL:OK Uplink OK
- * - TSF:CHKUPL:OK,FCTRL Uplink OK, flood control prevents pinging GW in too short intervals
- * - TSF:CHKUPL:DGWC,O=x,N=y Checking uplink revealed a changed network topology, old distance x, new distance y
- * - TSF:CHKUPL:FAIL No reply received when checking uplink
- * - TSF:ASID:OK,ID=x Node ID x assigned
- * - TSF:PING:SEND,TO=x Send ping to destination x
- * - TSF:MSG:ACK REQ ACK message requested
- * - TSF:MSG:ACK ACK message, do not proceed but forward to callback
- * - TSF:MSG:FPAR RES,ID=x,D=y Response to find parent received from node x with distance y to GW
- * - TSF:MSG:FPAR PREF FOUND Preferred parent found
- * - TSF:MSG:FPAR OK,ID=x,D=y Find parent reponse from node x is valid, distance y to GW
- * - TSF:MSG:FPAR INACTIVE Find parent response received, but no find parent request active, skip response
- * - TSF:MSG:FPAR REQ,ID=x Find parent request from node x
- * - TSF:MSG:PINGED,ID=x,HP=y Node pinged by node x with y hops
- * - TSF:MSG:PONG RECV,HP=x Pinged node replied with x hops
- * - TSF:MSG:BC Broadcast message received
- * - TSF:MSG:GWL OK Link to GW ok
- * - TSF:MSG:FWD BC MSG Controlled broadcast message forwarding
- * - TSF:MSG:REL MSG Relay message
- * - TSF:MSG:REL PxNG,HP=x Relay PING/PONG message, increment hop counter x
- * - TSF:SANCHK:OK Sanity check passed. This ensures radio functionality and automatically attempts to re-initialize in case of failure
- * - TSF:CRT:OK Clearing routing table successful
- *
- * Incoming / outgoing messages
+ * Incoming / outgoing messages:
*
* See here for more detail on the format and definitons.
*
* Receiving a message
- * - TSF:MSG:READ,sender-last-destination,s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s
- * Sending a message
- * - [!]TSF:MSG:SEND,sender-last-next-destination,s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,ft=%d,st=%s:%s
+ * - TSF:MSG:READ,sender-last-destination,s=%%d,c=%%d,t=%%d,pt=%%d,l=%%d,sg=%%d:%%s
*
- * - Message fields:
- * - s=sensor ID
- * - c=command
- * - t=msg type
- * - pt=payload type
- * - l=length
- * - ft=failed uplink transmission counter
- * - sg=signing flag
- *
- * TSF errors
- * - !TSF:ASID:FAIL,ID=x Assigned ID x is invalid, e.g. 0 (GATEWAY)
- * - !TSF:ROUTE:FPAR ACTIVE Finding parent active, message not sent
- * - !TSF:ROUTE:DST x UNKNOWN Routing for destination x unkown, send message to parent
- * - !TSF:SEND:TNR Transport not ready, message cannot be sent
- * - !TSF:MSG:PVER,x!=y Message protocol version mismatch
- * - !TSF:MSG:SIGN VERIFY FAIL Signing verficiation failed
- * - !TSF:MSG:REL MSG,NORP Node received a message for relaying, but node is not a repeater, message skipped
- * - !TSF:MSG:SIGN FAIL Signing message failed
- * - !TSF:MSG:GWL FAIL GW uplink failed
- * - !TSF:SANCHK:FAIL Sanity check failed, attempt to re-intialize radio
+ * Sending a message
+ * - [!]TSF:MSG:SEND,sender-last-next-destination,s=%%d,c=%%d,t=%%d,pt=%%d,l=%%d,sg=%%d,ft=%%d,st=%%s:%%s
+ *
+ * Message fields:
+ * - s=sensor ID
+ * - c=command
+ * - t=msg type
+ * - pt=payload type
+ * - l=length
+ * - ft=failed uplink transmission counter
+ * - sg=signing flag
*
* @brief API declaration for MyTransport
*
@@ -145,6 +135,13 @@
#include "MySensorsCore.h"
+ // debug
+#if defined(MY_DEBUG)
+ #define TRANSPORT_DEBUG(x,...) debug(x, ##__VA_ARGS__) //!< debug
+#else
+ #define TRANSPORT_DEBUG(x,...) //!< debug NULL
+#endif
+
#if defined(MY_REPEATER_FEATURE)
#define TRANSMISSION_FAILURES 10 //!< search for a new parent node after this many transmission failures, higher threshold for repeating nodes
#else
@@ -350,7 +347,7 @@ uint32_t transportGetHeartbeat();
/**
* @brief Initialize transport HW
-* @return true if initalization successful
+* @return true if initialization successful
*/
bool transportInit();
/**
diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp
index 9af162f..5113790 100644
--- a/drivers/RF24/RF24.cpp
+++ b/drivers/RF24/RF24.cpp
@@ -134,7 +134,7 @@ LOCAL void RF24_setStatus(uint8_t status) {
RF24_writeByteRegister(RF24_STATUS, status);
}
LOCAL void RF24_enableFeatures(void) {
- RF24_writeByteRegister(ACTIVATE, 0x73);
+ RF24_RAW_writeByteRegister(ACTIVATE, 0x73);
}
LOCAL void RF24_openWritingPipe(uint8_t recipient) {
@@ -247,7 +247,7 @@ LOCAL uint8_t RF24_getNodeID(void) {
}
LOCAL bool RF24_sanityCheck(void) {
- // detect HW defect ot interrupted SPI line, CE disconnect cannot be detected
+ // detect HW defect, configuration errors or interrupted SPI line, CE disconnect cannot be detected
bool status = RF24_readByteRegister(RF_SETUP) == MY_RF24_RF_SETUP;
status &= RF24_readByteRegister(RF_CH) == MY_RF24_CHANNEL;
return status;
@@ -273,18 +273,16 @@ LOCAL bool RF24_initialize(void) {
RF24_setChannel(MY_RF24_CHANNEL);
// set data rate and pa level
RF24_setRFSetup(MY_RF24_RF_SETUP);
- // sanity check
- #if defined(MY_RF24_SANITY_CHECK)
- if (!RF24_sanityCheck()) {
- RF24_DEBUG(PSTR("RF24:Sanity check failed: configuration mismatch! Check wiring, replace module or non-P version\n"));
- return false;
- }
- #endif
- // toggle features (necessary on some clones)
+ // toggle features (necessary on some clones and non-P versions)
RF24_enableFeatures();
// enable ACK payload and dynamic payload
RF24_setFeature(MY_RF24_FEATURE);
- // enable broadcasting pipe
+ // sanity check (this function is P/non-P independent)
+ if (!RF24_sanityCheck()) {
+ RF24_DEBUG(PSTR("!RF24:Sanity check failed: configuration mismatch! Check wiring or replace module\n"));
+ return false;
+ }
+ // enable broadcasting pipe
RF24_setPipe(_BV(ERX_P0 + BROADCAST_PIPE));
// disable AA on all pipes, activate when node pipe set
RF24_setAutoACK(0x00);