   
   // Initialize the probe and wifi configuration
   initProbe("autogarten_probe", "-----", 5000, "changeme");
-  initWiFi("-----", "-----", true);
+  initWiFi("-----", "-----", false);
   
   // Add any sensors
+  addSensor("light_level_1", A0, SENSOR_TYPE_ANALOG_GENERIC);
+  addSensor("light_level_2", A1, SENSOR_TYPE_ANALOG_GENERIC);  
+  addSensor("switch_1", 2, SENSOR_TYPE_DIGITAL_GENERIC);
+  addSensor("soil_temp", oneWirePin, SENSOR_TYPE_ONEWIRE_TEMP);
+  addSensor("air_temp", oneWirePin, SENSOR_TYPE_ONEWIRE_TEMP);
   
   // Add any actuators
-  
-  
-}
-
-
-void loop() {
-
-   delay(10000);
-   syncWithControlServer();
-}
+  // TODO...  
+}
+
+
+void loop() {   
+  delay(5000);
+  
+  Serial.println();
+  Serial.print("Free Memory: ");
+  Serial.println(memoryFree());
+  
+  readAnalogGenericSensor("light_level_1");
+  readAnalogGenericSensor("light_level_2");
+  readDigitalGenericSensor("switch_1");
+  readOneWireTempSensor("soil_temp");
+  readOneWireTempSensor("air_temp");
+  
+  //syncWithControlServer();
+}
+
+
+
 
 /**
  * Initialize settings and behavior for the probe

  }
  
  // Once connected, print connection information
  Serial.print("... connection successful");
  printWiFiConnectionInfo();
}



  return syncRequest;
}


/*
 * Adds the given sensor to this probe
 */ 
boolean addSensor(char *sensorId, int pin, int sensorType) {
  
  // TODO: Verify a reserved PIN isn't being used... 

  switch (sensorType) {
    
    case SENSOR_TYPE_ANALOG_GENERIC:
      if (!isAnalogPin(pin)) {        
        Serial.print(sensorId);
        Serial.println(" ERROR 101");
        return false;
      }       
      break;
      
    case SENSOR_TYPE_DIGITAL_GENERIC:
      if (!isDigitalPin(pin)) {
        Serial.print(sensorId);
        Serial.println(" ERROR 102");
        return false;
      }
      pinMode(pin, INPUT);      
      break;      

    case SENSOR_TYPE_ONEWIRE_TEMP:
      if (pin != oneWirePin) {
        Serial.print(sensorId);
        Serial.println(" ERROR 103");
        return false;
      }
      
      if (oneWireDeviceCount >= maxOneWireDevices) {
        Serial.println(" ERROR 104");
        return false;
      }      
      
      // 1-wire devices share a pin, so set the sensorId in the 1-wire array      
      oneWireSensorIds[oneWireDeviceCount++] = sensorId;
      break;

    default:
        Serial.print(sensorId);
        Serial.println(" ERROR 105"); 
  }

  sensorIds[pin] = sensorId;  
  Serial.print(sensorIds[pin]);
  Serial.print(" added on pin ");
  Serial.println(pin);  
  return true;
}


/**
 * Returns the pin for the given sensorId
 */
int getPinForSensorId(char *sensorId) {
  int ctr;
  for (ctr=0; ctr < sizeof(sensorIds)/sizeof(char); ctr++) {
    if (sensorIds[ctr] == sensorId) {
      return ctr;
    }
  }
  return -1;  
}


/**
 * Returns true if pin is a digital pin
 */
boolean isDigitalPin(int pin) {
  return pin >= 0 && pin <= 13;
}


/**
 * Retrurns true if pin is an analog pin
 */
boolean isAnalogPin(int pin) {
  return pin >= A0 && pin <= A5;
}


/**
 * Read a value from an analog sensor.  Examples include...
 *  + Photoresistors for measuring light levels.
 *  + ...
 */ 
float readAnalogGenericSensor(char *sensorId) {
  int pin = getPinForSensorId(sensorId);
  float value = analogRead(pin);
  
  printSensorResult(sensorId, pin, value);
  return value;
}


/**
 * Read a value from an digital sensor.  Examples include...
 *  + Switches
 *  + ...
 */ 
int readDigitalGenericSensor(char *sensorId) {
  int pin = getPinForSensorId(sensorId);
  int value = digitalRead(pin);
  
  printSensorResult(sensorId, pin, value);
  return value;
}


/*
 * Using the OneWire library, reads temperature from a 1-wire device.
 * See: http://playground.arduino.cc/Learning/OneWire
 *
 * !! Important !!
 *     This function has been streamlined to ONLY support a DS18S20 digital thermometer
 *     running in non-parasitic power mode.  If using another 1-wire device then changes
 *     are required. See the Arduino OneWire page for details and code. 
 *
 *     Note that multiple DS18S20 devices can be wired together on the same bus.
 *     Be sure to place a 4.7K resistor between VCC and Data.
 *
 *     When using multiple DS18S20 devices, the order that the addSensor() is called
 *     matters.  Call addSensor() for the first item on the bus.
 */
float readOneWireTempSensor(char *sensorId) {
  
  int deviceCount = 0;
  byte addr[8];  
  
  // Iterate over all devices on the OneWire bus
  oneWire.reset_search();
  while (oneWire.search(addr) ){
    delay(250);
    
    // If this isn't the device we're looking for, continue.
    if (sensorId != oneWireSensorIds[deviceCount++]) {
      continue;
    }    
    
    // Print the device's unique 64-bit ROM code
    /*Serial.print(" * R=");
    for( i = 0; i < 8; i++) {
      Serial.print(addr[i], HEX);
      Serial.print(" ");
    }
    Serial.println("---");   
    */
    
    // Verify valid CRC, if not return error value
    if (OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("ERROR 201");
      return ERROR_VALUE;
    }
    
    // Verify is chip is a DS18B20, if not return error value.
    // The first ROM byte indicates which chip (0x28 = DS18B20).
    if(addr[0] != 0x28) {
      Serial.println("ERROR 202");
      return ERROR_VALUE;
    }
    
    // Reset the 1-Wire bus, select a device then start a conversion
    oneWire.reset();
    oneWire.select(addr);
    oneWire.write(0x44);  
    delay(800);
    
    // Reset the 1-Wire bus, select a device then read scratchpad
    oneWire.reset();
    oneWire.select(addr);    
    oneWire.write(0xBE);

    // Read the data on the bus (9 bytes)
    byte data[12];
    for (int i = 0; i < 9; i++) {
      data[i] = oneWire.read();
    }
    
    // Convert the data (hex) to a temperature value.
    // Since we're only supporting a DS18S20 device, we can assume
    // 12 bit resolution (750ms conversion time).
    int16_t raw = (data[1] << 8) | data[0];
    float value = convertCelsiusToFahrenheit((float)raw / 16.0);        
    printSensorResult(sensorId, oneWirePin, value);    
    return value;
  }

  Serial.println("ERROR 200");
  return ERROR_VALUE;
}


/**
 * For debugging purposes, prints out the results of reading a sensor
 */
void printSensorResult(char *sensorId, int pin, float value) {
  Serial.print(sensorId);
  Serial.print(" on ");
  Serial.print(pin);
  Serial.print(" = ");
  Serial.println(value);  
}


/**
 * Convert a celsius value to Fahrenheit, because Amurika
 */
float convertCelsiusToFahrenheit(float degreesCelsius) {
  return degreesCelsius * 1.8 + 32.0;
}


/**
 * Determine amount of free RAM
 * From Arduino Cookbook: Page 587
 */
extern int __bss_end;
extern void *__brkval;
int memoryFree() {
  int freeValue;
  if((int)__brkval == 0)
    freeValue = ((int)&freeValue) - ((int)&__bss_end);
  else
    freeValue = ((int)&freeValue) - ((int)__brkval);
  return freeValue; 
}

