   if ((int)(millis()/TRANSMITPERIOD) > lastPeriod) {
     lastPeriod++;
     
+    if (!sensorData.status) {
+      send_reading(CMD_ALERT);
+      blink_led(DPIN_RF_LED, DEFAULT_LED_DELAY);
+      log();
+    }
+
+  }
+  
+}
+
+//------------------------------------------------------------------------------
+void blink_led(byte pin, int delay_ms) {
+  digitalWrite(pin, HIGH);
+  delay(delay_ms);
+  digitalWrite(pin, LOW);
+}
+
+//------------------------------------------------------------------------------
+// Compares each sensor's value against its expectation, returning true if the
+// values are acceptable or false if they fall outside the expectations.
+int check_status() {
+  int status = HIGH;
+  if (sensorData.ldr > sensorThresholds.light) {
+    status = LOW;
+  }
+  if (sensorData.hall == sensorThresholds.door) {
+    status = LOW;
+  }
+  if (sensorData.tempInsideC < sensorThresholds.minTempInsideC) {
+    status = LOW;
+  }
+  if (sensorData.tempInsideC > sensorThresholds.maxTempInsideC) {
+    status = LOW;
+  }
+  return status;
+}
+
+//------------------------------------------------------------------------------
+// Logs the current sensor values.
+void log() {
+  Serial.print("Status: "); 
+  Serial.print(sensorData.status);
+  Serial.print(", Light: "); 
+  Serial.print(sensorData.ldr);
+  Serial.print(", Hall: "); 
+  Serial.print(sensorData.hall);
+  Serial.print(", Temp: "); 
+  Serial.print(sensorData.tempInsideC);
+  Serial.print("C, "); 
+  Serial.print(sensorData.tempOutsideC);
+  Serial.print("C");
+  Serial.print(", Battery: "); 
+  Serial.println(sensorData.batteryVoltage);
+}
+
+//------------------------------------------------------------------------------
+// Retrieves the new sensor values.
+void interogate_sensors() {
+
+  // block access to sensor data  
+  sensorData.available = false;
+  
+  // read light level
+  sensorData.ldr = map(analogRead(APIN_LDR), 0, 1023, 0, 255);
+
+  // read door status
+  sensorData.hall = digitalRead(DPIN_HALL);
+  
+  // read one-wire sensors
+  oneWireSensors.requestTemperatures();
+  sensorData.tempInsideC = oneWireSensors.getTempC(thermometerInside);
+  sensorData.tempOutsideC = oneWireSensors.getTempC(thermometerOutside);
+  
+  // read battery voltage
+  int val = analogRead(APIN_BATTERY);
+  float pinVoltage = val * 0.00488;
+  sensorData.batteryVoltage = pinVoltage * VDD_RATIO;
+
+  // enable access to sensor data  
+  sensorData.available = true;
+ 
+  // update status led
+  sensorData.status = check_status();
+  digitalWrite(DPIN_SENSOR_LED, !sensorData.status); 
+  
+}
+
+//------------------------------------------------------------------------------
+void send_reading(unsigned int command) {
+  
     // assemble sensor reading message
     int decBatteryVoltage = int(sensorData.batteryVoltage);
     unsigned int fracBatteryVoltage;

#define CMD_BOOT     0x10
#define CMD_CONFIG   0x11
#define CMD_READING  0x21
#define PRECISION    100

#define APIN_BATTERY    0  // data connection for photocell
#define APIN_LDR        1  // data connection for photocell
#define DPIN_ONEWIRE    3  // data connection for the Dallas OneWire bus
#define DPIN_HALL       7  // data connection for hall effect
#define DPIN_SENSOR_LED 8
#define DPIN_RF_LED     9

#define VDD_RATIO 1.622

struct SensorData {
  boolean available;
  unsigned int ldr;
  unsigned int hall;
  float tempInsideC;

    Serial.print("reading [");
    Serial.print(buffer);
    Serial.print("]");
    
    // transmit reading to gateway
    radio.Send(GATEWAYID, buffer, strlen(buffer), true);
    Serial.print(" : waiting for ACK - ");
    if (waitForAck(GATEWAYID)) Serial.println("<OK>");
    else Serial.println("<NONE>");
}

//------------------------------------------------------------------------------
