 #include <JeeLib.h>
 #include <avr/sleep.h>
 
-#define BLIP_ID 1  // set this to a unique ID to disambiguate multiple nodes
+#define BLIP_ID   2 // set this to a unique ID to disambiguate multiple nodes
+#define SEND_MODE 3 // set to 3 if fuses are e=06/h=DE/l=CE, else set to 2
 
 struct {
   long ping;  // 32-bit counter

  rf12_initialize(17, RF12_868MHZ, 5);
  // see http://tools.jeelabs.org/rfm12b
  rf12_control(0xC040); // set low-battery level to 2.2V i.s.o. 3.1V
  payload.id = BLIP_ID;
}

void loop() {
  payload.vcc1 = vccRead();

  ++payload.ping;

  while (!rf12_canSend())
    rf12_recvDone();
  
  rf12_sendStart(0, &payload, sizeof payload);
  // set the sync mode to 2 if the fuses are still the Arduino default
  // mode 3 (full powerdown) can only be used with 258 CK startup fuses
  rf12_sendWait(2);

  payload.vcc2 = vccRead();
  
  rf12_sleep(RF12_SLEEP);
  Sleepy::loseSomeTime(60000);
  rf12_sleep(RF12_WAKEUP);
}


volatile bool adcDone;

// for low-noise/-power ADC readouts, we'll use ADC completion interrupts
ISR(ADC_vect) { adcDone = true; }

// this must be defined since we're using the watchdog for low-power waiting
ISR(WDT_vect) { Sleepy::watchdogEvent(); }

static byte vccRead (byte count =4) {
  set_sleep_mode(SLEEP_MODE_ADC);
  ADMUX = bit(REFS0) | 14; // use VCC as AREF and internal bandgap as input
  bitSet(ADCSRA, ADIE);
  while (count-- > 0) {
    adcDone = false;
