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

/// 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/
// 2012-11-11 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <JeeLib.h>

// buffer to collect last data received
byte lastChars[9], lastFill;

// 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;
}

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;
  }

  // periodically check whether the next id needs to be resent
  if (resendTimer.poll(1000))
    sendId(++resendCursor);
}
