 
 String mac_address;
 const int led = 12;
-const int led2 = 13;
 
 
 // Configuration
 void SetHostname(const char* new_hostname) {
-  strncpy(config.hostname, new_hostname, NAME_LEN);
-}
-
-void SetDevice(const unsigned int index, struct Connected_device device) {
+  strncpy(config.hostname, new_hostname, NAME_LEN -1);
+  config.hostname[NAME_LEN] = '\0';
+}
+
+void SetDevice(const unsigned int index, struct Connected_device& device) {
   if (index < MAX_DEVICES) {
     memcpy(&(config.devices[index]), &device, sizeof(device));
   }
 }
 
+String DeviceAddress(Connected_device& device) {
+  String return_value = "";
+  for(int i = 0; i < ADDRESS_SEGMENTS; i++){
+    if(strlen(device.address_segment[i].segment) > 0){
+      if(i > 0){
+        return_value += "/";
+      }
+      return_value += device.address_segment[i].segment;
+    } else {
+      break;
+    }
+  }
+  return return_value;
+}
+
 
 // mDNS
 Brokers brokers(QUESTION_SERVICE);

}

void handleConfig() {
  const unsigned int now = millis() / 1000;

  String message = "";

  if (http_server.hasArg("test_arg")) {
    message += "test_arg: " + http_server.arg("test_arg") + "\n";
  }
  if (http_server.hasArg("hostname")) {
    char tmp_buffer[NAME_LEN];
    http_server.arg("hostname").toCharArray(tmp_buffer, NAME_LEN);
    SetHostname(tmp_buffer);
    message += "hostname: " + http_server.arg("hostname") + "\n";
  }
  Serial.println("device");
  if (http_server.hasArg("device") and http_server.hasArg("name") and http_server.hasArg("room") and http_server.hasArg("io_type") and http_server.hasArg("io_pins")) {
    unsigned int index = http_server.arg("device").toInt();
    Connected_device device;
    http_server.arg("name").toCharArray(device.name, NAME_LEN);
    http_server.arg("room").toCharArray(device.room, NAME_LEN);
    if (http_server.arg("io_type") == "test") {
      device.io_type = Io_Type::test;
    } else if (http_server.arg("io_type") == "rgb") {

      io_pins_buffer[strlen(io_pins_buffer)] = ',';
    }

    unsigned int pin_num = 0, pin_buffer_pointer = 0;
    memset(pin_buffer, '\0', 4);
    for (unsigned int i = 0; i < strlen(io_pins_buffer); ++i) {
      if (io_pins_buffer[i] == ',') {
        device.io_pins[pin_num++] = atoi(pin_buffer);
        memset(pin_buffer, '\0', 4);
        pin_buffer_pointer = 0;
