 }
 
 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";
+  }
+  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") {
+      device.io_type = Io_Type::rgb;
+    } else if (http_server.arg("io_type") == "pwm") {
+      device.io_type = Io_Type::pwm;
+    } else if (http_server.arg("io_type") == "onoff") {
+      device.io_type = Io_Type::onoff;
+    }
+    char tmp_buffer[NAME_LEN];
+    http_server.arg("io_pins").toCharArray(tmp_buffer, NAME_LEN);
+    char* pch = strtok (tmp_buffer, ",");
+    int i = 0;
+    while (pch != NULL and i < 4)
+    {
+      device.io_pins[i] = atoi(pch);
+      pch = strtok(NULL, ",");
+    }
+
+    SetDevice(index, device);
+
+    message += "device: " + http_server.arg("device") + "\n";
   }
 
   http_server.send(200, "text/plain", message);

  if (!mqtt_client.connected()) {
    Serial.println("MQTT disconnected.");
    mqtt_connect();
  }  
}

// Maximum number of devices connected to IO pins.
#define MAX_DEVICES 8

// Length of name strings. (hostname, room names, lamp names, etc.)
#define NAME_LEN 32


enum Io_Type {
  test,
