 DNSServer dnsServer;
 ESP8266WebServer server(80);
 
-String* genAPForm() {
-  return new String("");
-/*
-  if not aptbl then return "<html><body>No AP data :-(</body></html>" end
-  buf = ""; checked = " checked"
-  for ssid, _ in pairs(aptbl) do
-    buf = buf .. '<input type="radio" name="ssid" value="' .. ssid .. '"' ..
-      checked .. '>' .. ssid .. '<br/>\n'
-    checked = ""
-  end
-  return string.gsub(wifiform, "_ITEMS_", buf)
-*/
-}
-
 void setup() {
   Serial.begin(115200);
-  Serial.setDebugOutput(true);
+  // Serial.setDebugOutput(true);
 
-  WiFi.mode(WIFI_AP);
+  WiFi.mode(WIFI_AP_STA);
   WiFi.softAPConfig(apIP, apIP, netMsk);
   WiFi.softAP(ssid);
 

  "</body></html>";

const char* apChoice = 
  "<h2>Choose a wifi access point to join</h2><p><form method='POST' action='chz'>a "
  "_ITEMS_<br/>Pass key: <input type='textarea' name='key'><br/><br/>a "
  "<input type='submit' value='Submit'></form></p></body></html>]=]";

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);

  delay(100);
}

String genAPForm() {
  String f = apChoice;
  String buf = "";
  const char *checked = " checked";

  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
    f =
      "<html><head><title>WaterElf Aquaponics Helper: Wifi Config</title>"
      "<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);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
      delay(10);

      buf.concat("<input type='radio' name='ssid' value='");
      buf.concat(WiFi.SSID(i));
      buf.concat("'");
      buf.concat(checked);
      buf.concat(">");
      buf.concat(WiFi.SSID(i));
      buf.concat("<br/>\n");
      checked = "";
    }
    f.replace("_ITEMS_", buf);
  }
  Serial.println("");

  return f;
}

void handle_wifi() {
  Serial.println("serving page at /wifi");
  String toSend = genAPForm();
  server.send(200, "text/html", toSend);
  delay(100);
}

void handle_L0() { handle_root(); } 
void handle_L2() { handle_root(); }
void handle_ALL() { handle_root(); }
