 #define SEND_ID     9             // listen for this node ID
 
 #define CYCLE_TIME  3000          // expected cycle, milliseconds
+#define MIN_WIN     8             // minimum window size, power of 2
+#define MAX_WIN     1024          // maximum window size, power of 2
 
 #define EEADDR ((word*) 0)        // save estimate at this EEPROM address
 

  if (estimate < CYCLE_TIME - CYCLE_TIME/5 ||
      estimate > CYCLE_TIME + CYCLE_TIME/5)
    estimate = CYCLE_TIME;
  Serial.print("start estimate = "); Serial.println(estimate);
  // narrow down estimate from 20 % -> 2 %
  window = estimate / 5; 
  while (window >= 16)
    if (estimateWithWatchdog())
      window /= 2;
  // save best estimaet so far
  eeprom_write_word(EEADDR, estimate);
  Serial.print("save estimate "); Serial.println(estimate);
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[syncRecv]");
  rf12_initialize(1, SEND_FREQ, SEND_GROUP); // we never send
  chooseEstimate();
}

void loop () {
  uint32_t now = millis();
  byte lost = (now - lastRecv + estimate/2) / estimate;
  Serial.print(" #"); Serial.print(lost);
  if (lost > 20)
    chooseEstimate();
  else {
    uint32_t predict = lastRecv + (lost + 1) * estimate;
    word sleep = predict - now - window;

    Serial.print(" s "); Serial.print(sleep);
    Serial.flush(); delayMicroseconds(250);

    radioSleep(sleep);

    uint32_t recvTime;
    do {
      recvTime = millis();
      if (recvTime > predict + window)
        return;
    } while (!isDesiredPacket());

    estimate = (recvTime - lastRecv) / (lost + 1);
    int offset = (estimate - sleep) - window;
    lastRecv = recvTime;

    Serial.print(" e "); Serial.print(estimate);
    Serial.print(" w "); Serial.print(window);
    Serial.print(" o "); Serial.print(offset);
    Serial.print(" rf "); Serial.println(offset + window);
  }
}

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

static void radioSleep (word ms) {
  bitSet(DDRB, 1);
  bitSet(PORTB, 1); // LED off
  rf12_sleep(RF12_SLEEP);
  Sleepy::loseSomeTime(ms);
  rf12_sleep(RF12_WAKEUP);
  bitClear(PORTB, 1); // LED on
}

static bool isDesiredPacket () {
