   ws.setAuthentication("admin", adminpass);
 
   if (wmode == 1) {
-    inAPMode = true;
     Serial.println(F("[ INFO ] ESP-RFID is running in AP Mode "));
-    WiFi.mode(WIFI_AP);
-    Serial.print(F("[ INFO ] Configuring access point... "));
-    Serial.println(WiFi.softAP(ssid, password) ? "Ready" : "Failed!");
-    // Access Point IP
-    IPAddress myIP = WiFi.softAPIP();
-    Serial.print(F("[ INFO ] AP IP address: "));
-    Serial.println(myIP);
-    Serial.print(F("[ INFO ] AP SSID: "));
-    Serial.println(ssid);
-    isWifiConnected = true;
-    return true;
+    return startAP(ssid, password);
   }
   else if (!connectSTA(ssid, password, bssid)) {
     return false;

  WiFi.scanDelete();
}

// Fallback to AP Mode, so we can connect to ESP if there is no Internet connection
void fallbacktoAPMode() {
  inAPMode = true;
  WiFi.mode(WIFI_AP);
  Serial.print(F("[ INFO ] Configuring access point... "));
  Serial.println(WiFi.softAP(deviceHostname) ? "Ready" : "Failed!");
  // Access Point IP
  IPAddress myIP = WiFi.softAPIP();
  Serial.print(F("[ INFO ] AP IP address: "));
  Serial.println(myIP);
  server.serveStatic("/auth/", SPIFFS, "/auth/").setDefaultFile("users.htm").setAuthentication("admin", "admin");
  isWifiConnected = true;
}

void parseBytes(const char* str, char sep, byte* bytes, int maxBytes, int base) {

bool doEnableWifi = false;
int wifiTimeout = -1;
unsigned long wiFiUptimeMillis = 0;
char * deviceHostname = NULL;

int relayPin;
int relayType;
