   delay(100);
 }
 
+void handle_wifistatus() {
+  Serial.println("serving page at /wifistatus");
+  String toSend = wstatus;
+  toSend += "<li>SSID: ";
+  toSend += WiFi.SSID();
+  toSend += "</li>";
+  toSend += "<li>Status: ";
+  switch(WiFi.status()) {
+    case WL_IDLE_STATUS:
+      toSend += "WL_IDLE_STATUS</li>"; break;
+    case WL_NO_SSID_AVAIL:
+      toSend += "WL_NO_SSID_AVAIL</li>"; break;
+    case WL_SCAN_COMPLETED:
+      toSend += "WL_SCAN_COMPLETED</li>"; break;
+    case WL_CONNECTED:
+      toSend += "WL_CONNECTED</li>"; break;
+    case WL_CONNECT_FAILED:
+      toSend += "WL_CONNECT_FAILED</li>"; break;
+    case WL_CONNECTION_LOST:
+      toSend += "WL_CONNECTION_LOST</li>"; break;
+    case WL_DISCONNECTED:
+      toSend += "WL_DISCONNECTED</li>"; break;
+    default:
+       toSend += "unknown</li>";
+  }
+  toSend += "</ul></p>";
+  toSend += footer;
+  server.send(200, "text/html", toSend);
+  delay(100);
+}
+
+void handle_chz() {
+  Serial.println("serving page at /chz");
+  String toSend = "<html><body><h2>Done! Joining...</h2></body></html>";
+  String ssid = "";
+  String key = "";
+
+  for ( uint8_t i = 0; i < server.args(); i++ ) {
+    Serial.println(" " + server.argName(i) + ": " + server.arg(i) + "\n");
+    if(server.argName(i) == "ssid")
+      ssid = server.arg(i);
+    else if(server.argName(i) == "key")
+      key = server.arg(i);
+  }
+
+  if(ssid == "") {
+    toSend = "<html><body><h2>Ooops, no SSID...?</h2></body></html>";
+  } else {
+    char ssidchars[sizeof(ssid)];
+    char keychars[sizeof(key)];
+    ssid.toCharArray(ssidchars, sizeof(ssid));
+    key.toCharArray(keychars, sizeof(key));
+    WiFi.begin(ssidchars, keychars);
+  }
+
+  server.send(200, "text/html", toSend);
+  delay(100);
+}
+
 void handle_L0() { handle_root(); } 
 void handle_L2() { handle_root(); }
 void handle_ALL() { handle_root(); }

      "<style>body{background:#FFF;color: #000;font-family: sans-serif;}</style>"
      "</head><body><p>No AP data :-(<br/>"
      "<a href='/'>Back</a><br/><a href='/wifi'>Try again</a></p>"
      "</body></html>";
  } else {
    Serial.print(n);

  server.on("/L0", handle_L0);
  server.on("/L2", handle_L2);
  server.on("/ALL", handle_ALL);
  server.onNotFound(handleNotFound);

  server.on("/wifi", handle_wifi);
  server.on("/wifistatus", handle_wifistatus);
  server.on("/chz", handle_chz);
  server.begin();

  Serial.println("HTTP server started");
