   eeprom_read_block((void*)&settings, (void*)0, sizeof(settings));
   if (strcmp(settings.magic, MAGIC) != 0) {
     reset();
+    DBG Serial.println("write defaults");  
     eeprom_write_block((const void*)&settings, (void*)0, sizeof(settings));
   }
   // set sleep counter
   resetSleep(settings.period);
   #ifndef NOETH
-    // Print hw address
-    char macstr[18];
-    snprintf(macstr, 18, "%02x:%02x:%02x:%02x:%02x:%02x", settings.mac[0], settings.mac[1], settings.mac[2], settings.mac[3], settings.mac[4], settings.mac[5]);
-    DBG Serial.print("HWAddr: ");
-    DBG Serial.println(macstr);
     // Try to configure the ethernet using DHCP
     delay(2000);
-    DBG Serial.println("Running DHCP...");
+    DBG Serial.println("dhcp");
     if (Ethernet.begin(settings.mac) == 0) {
-      DBG Serial.println("DHCP failed, using static IP.");
+      DBG Serial.println("dhcp fail");
       // Use static IP
       Ethernet.begin(settings.mac, IP, MASK, GW);
     }
     // Print IP
-    DBG Serial.print("IPAddr: ");
+    DBG Serial.print("ip: ");
     DBG Serial.println(Ethernet.localIP());
     // Give the Ethernet shield a second to initialize:
     delay(1000);
     // Start server
     server.begin();
+    // Init SD
+    pinMode(10, OUTPUT);
+    // see if the card is present and can be initialized:
+    if (!SD.begin(4)) {
+      Serial.println("sd fail");
+      return;
+    }
   #endif
 }
 

  // null-terminate input buffer
  inputBytes[i] = '\0';
  // execute command
  if (cmd == 'P') {
    int value = atoi(inputBytesPtr);
    if (value > 0) {
      resetSleep(value);
    }
  } 
  else if (cmd == 'A') {
    int value = atoi(inputBytesPtr);
    if (value >= 0) {
      settings.r1 = value;
    }
  } 
  else if (cmd == 'B') {
    int value = atoi(inputBytesPtr);
    if (value >= 0) {
      settings.r2 = value;
    }
  } 
  else if (cmd == 'C') {
    int value = atoi(inputBytesPtr);
    if (value >= 0) {
      settings.offset = value;
    }
  } 
  else if (cmd == 'D') {
    int value = atoi(inputBytesPtr);
    if (value >= 0) {
      settings.sensitivity = value;
    }
  } 
  else if (cmd == 'S') {
    int value = atoi(inputBytesPtr);
    if (value >= 0) {
      digitalWrite(RELAY_PIN, HIGH);
    } 
    else {
      digitalWrite(RELAY_PIN, LOW);
    }
  } 
  #ifndef NOETH
  else if (cmd == 'F') {
    long value = atol(inputBytesPtr);
    if (value >= 0) {


// Permanent configuration
struct settings_t {
  char magic[9];
  long period;
  int r1;
  int r2;
  int offset;
  int sensitivity;
#ifndef NOETH
  byte mac[6];
  char apikey[49];
  long feed;
  IPAddress host;
  long port;
#endif
} settings;

void reset() {
  strcpy (settings.magic,MAGIC);
  settings.period = PERIOD;
  settings.r1 = R1;
  settings.r2 = R2;
  settings.offset = OFFSET;
  settings.sensitivity = SENSITIVITY;
#ifndef NOETH
  settings.feed = FEED;
  settings.host = HOST;
  settings.port = PORT;
