What is the best way to switch from WebClient to Access Point with ATWINC1500

Hello,

I am currently in the process of switching from WebClient to Access Point with my ATWINC1500. I have the following problem that, if I take the module from the Access point mode, I can not restart Access point again.

The WiFi module always runs in Web Client mode. So that I can configure my module (SSID, user, password), I have to put it in the access point mod.

void setupAccessPoint() {
  stopAP();
  if (startAP()) {
    wait(10000);
    server.begin();

    if (getLocalNetworkCredentials()) {
      stopAP();
      connect();
    } else {
      stopAP();
    }
  }
}

void stopAP() {
  WiFi.end();
}

boolean startAP() {
// WiFi.config (ip, dns, gateway, subnet);
  int status = WiFi.beginAP(accessPoint.apSSID, accessPoint.apPassword, accessPoint.channel);
  if (status != WL_AP_LISTENING) {
    return false;
  }
  return true;
}

boolean getLocalNetworkCredentials() {
  int status = WL_IDLE_STATUS;

  while (1) {

    // Exit menu with ESC
    if (getKeys() == 2) {
      waitForKeyRelease();
      break;
    }

    if (status != WiFi.status()) {
      status = WiFi.status();

      if (status == WL_AP_CONNECTED) {
        Serial.println("Device connected to AP");
      } else {
        Serial.println("Device disconnected from AP");
      }
    }

    WiFiClient client = server.available();

    if (client) {
      Serial.println("new client");
      String currentLine = "";

      while (client.connected()) {
        if (client.available()) {
          char c = client.read();
          Serial.print(c);

          if (c == '\n') {
            if (currentLine.length() == 0) {
              client.println("HTTP/1.1 200 OK");
              client.println("Content-type:text/html");
              client.println();

            } else {      // if you got a newline, then clear currentLine:
              currentLine = "";
            }

          } else if (c != '\r') {    // if you got anything else but a carriage return character,
            currentLine += c;      // add it to the end of the currentLine
          }
        }
      }

      client.stop();
      Serial.println("client disconnected");
    }
  }
}

In the while loop (in the method getLocalNetworkCredentials), there is the possibility to leave this while loop. The user can cancel this process. In this case, the access point must be switched off.

After that I can not start an access point anymore. I do not see the mistake.

Is stopping the AP with WiFi.end (); not correct?

some idea?