@@ -81,7 +81,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
81
81
requestNodeId ();
82
82
}
83
83
84
- debug (PSTR (" %s started, id %d \n " ), repeaterMode?" repeater" :" sensor" , nc.nodeId );
84
+ debug (PSTR (" %s started, id=%d, parent=%d, distance=%d \n " ), repeaterMode?" repeater" :" sensor" , nc.nodeId , nc. parentNodeId , nc. distance );
85
85
86
86
// Open reading pipe for messages directed to this node (set write pipe to same)
87
87
RF24::openReadingPipe (WRITE_PIPE, TO_ADDR (nc.nodeId ));
@@ -148,7 +148,8 @@ void MySensor::findParentNode() {
148
148
debug (PSTR (" find parent\n " ));
149
149
150
150
build (msg, nc.nodeId , BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT, false ).set (" " );
151
- sendWrite (BROADCAST_ADDRESS, msg);
151
+ // Write msg, but suppress recursive parent search
152
+ sendWrite (BROADCAST_ADDRESS, msg, false );
152
153
153
154
// Wait for ping response.
154
155
waitForReply ();
@@ -195,12 +196,16 @@ boolean MySensor::sendRoute(MyMessage &message) {
195
196
return false ;
196
197
}
197
198
198
- boolean MySensor::sendWrite (uint8_t next, MyMessage &message) {
199
+ boolean MySensor::sendWrite (uint8_t next, MyMessage &message, const bool allowFindParent ) {
199
200
bool ok = true ;
200
201
const bool broadcast = next == BROADCAST_ADDRESS;
201
- const bool toParent = !broadcast && (next == nc.parentNodeId );
202
+ const bool toParent = next == nc.parentNodeId ;
203
+ // With current implementation parent node Id can equal the broadcast address when
204
+ // starting with empty eeprom and AUTO node Id is active.
205
+ // This behavior is undesired, as possible parents will report back to broadcast address.
206
+ // debug(PSTR("sendWrite next=%d, parent=%d, distance=%d\n"), next, nc.parentNodeId, nc.distance);
202
207
// If sending directly to parent node and distance is not set, then try to find parent now.
203
- if ( toParent && !isValidDistance (nc.distance ) ) {
208
+ if ( allowFindParent && toParent && !isValidDistance (nc.distance ) ) {
204
209
findParentNode ();
205
210
// Known distance indicates parent has been found
206
211
ok = isValidDistance (nc.distance );
@@ -219,7 +224,8 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message) {
219
224
RF24::startListening ();
220
225
221
226
debug (PSTR (" send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,st=%s:%s\n " ),
222
- message.sender ,message.last , next, message.destination , message.sensor , mGetCommand (message), message.type , mGetPayloadType (message), mGetLength (message), ok?" ok" :" fail" , message.getString (convBuf));
227
+ message.sender ,message.last , next, message.destination , message.sensor , mGetCommand (message), message.type ,
228
+ mGetPayloadType (message), mGetLength (message), broadcast ? " bc" : (ok ? " ok" :" fail" ), message.getString (convBuf));
223
229
224
230
// If many successive transmissions to parent failed, the parent node might be down and we
225
231
// need to find another route to gateway.
0 commit comments