   } while (!isDesiredPacket());
 
   int offset = window - (diff - lowEstimate);
-  estimate = diff & ~0x0F; // truncate down to a 16 ms multiple
+  // the new estimate shouldn't be too close to the exact time
+  estimate = (diff + 2) & ~0x0F; // truncate down to 16 ms multiple
 
   Serial.print(" ok at "); Serial.print(diff);
   Serial.print(", window = "); Serial.print(window);

}

void loop () {
  // gradually improve the estimate each time reception succeeds
  if (estimateWithWatchdog() && window >= 32)
    window /= 2;
}

/// @dir syncRecv
/// Try to receive periodic transmissions with minimal power consumption.
/// @see http://jeelabs.org/2012/11/02/synchronised-reception/
// 2012-10-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <JeeLib.h>

#define SEND_ID 9       // wait for packets from node 9

word estimate = 3000;   // packet expected every 3s
word window = 512;      // start with +/- 17 % window, power of 2
byte missed;            // count how often in a row receive failed

ISR(WDT_vect) { Sleepy::watchdogEvent(); }

