 
 void setup() {
   // Set serial port
-  Serial.begin(115200);   
+  Serial.begin(115200); 
   // Default on
   pinMode(RELAY_PIN,OUTPUT);
   digitalWrite(RELAY_PIN, LOW);

  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
    // Try to configure the ethernet using DHCP
    delay(2000);
    DBG Serial.println("dhcp");
    if (Ethernet.begin(settings.mac) == 0) {
      DBG Serial.println("dhcp fail");
      // Use static IP
      Ethernet.begin(settings.mac, IP, MASK, GW);
    }
    // Print IP
    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
}

void loop() {
  
  // Make sure that update period is not too high
  #ifndef NOETH
    if ((settings.feed != 0) && (settings.period < MIN_ETHERNET_PERIOD)) {
      DBG Serial.println("period too high");
      resetSleep(MIN_ETHERNET_PERIOD);
    }
  #endif
  
  // Start profiling
  long started = millis();


            if (strcmp(toks, "switch") == 0) {
              toks = strtok (NULL, "/");
              if (atoi(toks) > 0) {
                digitalWrite(RELAY_PIN, HIGH);
              } 
              else { 
                digitalWrite(RELAY_PIN, LOW);
              }
              writeHeader(request, JSON_RESPONSE);
              request.print("[");
              request.print(digitalRead(RELAY_PIN));
              request.print("]\n");
              break;
            } 
          }
          else {
            File dataFile = SD.open(toks, FILE_READ);
            if (dataFile) {
              writeHeader(request, HTML_RESPONSE);
              while (dataFile.available()) {
                request.write(dataFile.read());
              }
              dataFile.close();
              request.write("\n");
              break;
            } 
          }
        }
        writeHeader(request, HTML_RESPONSE_404);
        request.write("\n");
        break;
      }
    }
