 #include "Cosa/OWI/Driver/DS18B20.hh"
 #include "Cosa/Socket/Driver/W5100.hh"
 
+// Disable SD on Ethernet Shield
+#define USE_ETHERNET_SHIELD
+#if defined(USE_ETHERNET_SHIELD)
+#include "Cosa/OutputPin.hh"
+OutputPin sd(Board::D4, 1);
+#endif
+
 // One-wire pin and connected DS18B20 device
-OWI owi(Board::D14);
-DS18B20 sensor(&owi);
+OWI owi(Board::D7);
+
+// The devices connected to the one-wire bus
+DS18B20 outdoors(&owi);
+DS18B20 indoors(&owi);
+DS18B20 basement(&owi);
+
+DS18B20* thermometer[] = {
+  &outdoors,
+  &indoors,
+  &basement
+};
 
 // Network configuration
 #define MOSQUITTO "test.mosquitto.org"

 * (D2)-----[ ]-------56-|IRQ         |
 *                       +------------+
 *
 *                       DS18B20/sensor
 *                       +------------+
 * (GND)---------------1-|GND         |
 * (D14)-----+---------2-|DQ          |
 *           |       +-3-|VDD         |
 *          4K7      |   +------------+
 *           |       | 
 * (VCC)-----+-------+
 *
 * This file is part of the Arduino Che Cosa project.
 */

  // Start MQTT client with socket and connect to server
  client.begin(ethernet.socket(Socket::TCP));
  client.connect(SERVER, CLIENT);
  client.publish_P(PSTR("public/cosa/client"), CLIENT, sizeof(CLIENT));
}

void loop()
{
  static uint8_t i = 0;

  // Select the topic path for the current thermometer
  str_P topic;
  switch (i) {
  case 0: topic = PSTR("public/cosa/temperature/outdoors"); break;
  case 1: topic = PSTR("public/cosa/temperature/indoors"); break;
  case 2: topic = PSTR("public/cosa/temperature/basement"); break;
  };
    
  // Request a conversion and read the temperature
  thermometer[i]->convert_request();
  thermometer[i]->read_scratchpad();

  // Use an iobuffer and iostream to convert temperature value to a string
  IOBuffer<32> buf;
  IOStream cout(&buf);
  cout << *thermometer[i] << PSTR(" C") << ends;

  // Publish the value to the MQTT server and take a nap
  client.publish(topic, buf, buf.available());
  i += 1;
  if (i == membersof(thermometer)) i = 0;

  // Take a nap
  sleep(5);
}
