@@ -226,20 +226,19 @@ boolean Sensor::sendWrite(uint8_t dest, message_s message, int length) {
226
226
// int retry = WRITE_RETRY;
227
227
RF24::stopListening ();
228
228
RF24::openWritingPipe (TO_ADDR (dest));
229
- ok = RF24::write (&message, min (MAX_MESSAGE_LENGTH, sizeof (message.header ) + length), broadcast);
230
- debug (PSTR (" Sensor::sendWrite() - return value = %s\n " ), ok ? " true" : " false" );
229
+ RF24::startWrite (&message, min (MAX_MESSAGE_LENGTH, sizeof (message.header ) + length), broadcast);
231
230
RF24::startListening ();
232
231
RF24::closeReadingPipe (WRITE_PIPE); // Stop listening to write-pipe after transmit
233
232
234
- if (!broadcast && (radioId == GATEWAY_ADDRESS) ) {
233
+ if (!broadcast) {
235
234
// ---------------- WAIT FOR ACK ------------------
236
235
unsigned long startedWaiting = millis ();
237
236
bool timeout = false ;
238
- // Wait max 100 ms
237
+ // Wait for ack message maximum 50 ms
239
238
while ( !RF24::available () && !timeout ) {
240
- if (millis () - startedWaiting > 100 ) {
239
+ if (millis () - startedWaiting > ACK_MAX_WAIT ) {
241
240
timeout = true ;
242
- debug (PSTR (" Transmit: timeout\n " ));
241
+ debug (PSTR (" Ack: receive timeout\n " ));
243
242
ok = false ;
244
243
}
245
244
}
@@ -248,12 +247,12 @@ boolean Sensor::sendWrite(uint8_t dest, message_s message, int length) {
248
247
uint8_t idest;
249
248
RF24::read ( &idest, sizeof (uint8_t ));
250
249
if (dest != idest) {
251
- debug (PSTR (" Transmit: size problem \n " ));
250
+ debug (PSTR (" Ack: received ack from the wrong sensor \n " ));
252
251
ok = false ;
253
252
}
254
253
} else {
255
254
ok = false ;
256
- debug (PSTR (" Transmit: general fail \n " ));
255
+ debug (PSTR (" Ack: received non ack msg. \n " ));
257
256
}
258
257
// --------------------
259
258
}
@@ -456,11 +455,13 @@ boolean Sensor::readMessage() {
456
455
RF24::read (&msg, len);
457
456
458
457
if (!(msg.header .messageType ==M_INTERNAL && msg.header .type == I_PING_ACK)) {
458
+ delay (ACK_SEND_DELAY); // Small delay here to let other side switch to reading mode
459
459
RF24::stopListening ();
460
460
RF24::openWritingPipe (TO_ADDR (msg.header .last ));
461
461
RF24::write (&radioId, sizeof (uint8_t ));
462
462
RF24::startListening ();
463
463
RF24::closeReadingPipe (WRITE_PIPE); // Stop listening to write-pipe after transmit
464
+ debug (PSTR (" Sent ack msg to %d\n " ), msg.header .last );
464
465
}
465
466
uint8_t valid = validate (len-sizeof (header_s));
466
467
boolean ok = valid == VALIDATE_OK;
0 commit comments