 /// Read out the OpenTherm gateway and relay readings using RFM12B.
 /// @see http://jeelabs.org/2012/11/20/opentherm-relay/
 /// @see http://jeelabs.org/2012/11/21/reducing-the-payload-size/
+/// @see http://jeelabs.org/2012/11/22/reducing-the-packet-rate/
 // 2012-11-11 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
 #include <JeeLib.h>
 
+#define RESEND_COUNT 10   // send each new value out this often
+
 // buffer to collect last data received
 byte lastChars[9], lastFill;
 
+MilliTimer resendTimer;   // fires once a second
+byte resendCursor;        // cycles over all the history entries
+
 // the last values received, one entry for each ID 0..255
-struct { byte values[2]; } history [256];
-
-static bool shouldSend (const byte* payload) {
-  byte id = payload[0];
-  if (memcmp(payload + 1, history[id].values, 2) == 0)
-    return false;
-  memcpy(history[id].values, payload + 1, 2);
-  return true;
-}
+struct { word value; byte resends; } history [256];
 
 static byte hex2bin (const byte* hex) {
   byte result = (hex[0] - (hex[0] <= '9' ? 0 : 7)) << 4;

    // done, or invalid: clear the lastChars buffer
    lastFill = 0;
  }
}

      switch (lastChars[1] & 7) {
        case 1: // Write-Data
        case 4: // Read-Ack
          sendIfChanged();
      }
  }
}
