Purbright_Esp32_PlatformIO/lib/PurBrightLib/network.cpp
void Network::connectToApWithFailToStation()
{
  WiFi.persistent(true);
  SERIAL_DEBUG_LN("Configuring access point...");
  SERIAL_DEBUG_ADD("cfg.WIFISSID:");
  SERIAL_DEBUG_LN(cfg.WIFISSID);
  SERIAL_DEBUG_ADD("cfg.WIFIPASS:");
  SERIAL_DEBUG_LN(cfg.WIFIPASS);

  WiFi.mode(WIFI_STA);
  if (cfg.WIFISSID == " ")
  {
    WiFi.reconnect();
  }
  else
  {
    WiFi.begin(cfg.WIFISSID, cfg.WIFIPASS);
  }

  int numberOfAttempts = 0;

  while (WiFi.status() != WL_CONNECTED)
  {
    numberOfAttempts++;
    delay(200);
    SERIAL_DEBUG_ADD(".");
    if (numberOfAttempts > 100)
    {
      WiFi.mode(WIFI_AP);
      // You can remove the password parameter if you want the AP to be open.
      WiFi.softAP(cfg.WIFISSID, cfg.WIFIPASS);
      SERIAL_DEBUG_ADD("Wifi Connect Failed. \r\nStarting AP. \r\nAP IP address: ");
      SERIAL_DEBUG_LN(WiFi.softAPIP());
      return;
      break;
    }
  }
  SERIAL_DEBUG_LN("");
  SERIAL_DEBUG_LN("Connected! IP address: ");
  SERIAL_DEBUG_LN(WiFi.localIP());
}
// BACKUP LEGACY FUNCTION
/******************************************************************************
 * Function: Connect to Wifi with fail to AP mode if no connection
 * Description: This connection will attempt to create a WiFi connection with the given SSID and password. If the connection fails, it will attempt to connect to a default Wifi AP.
 * Parameters: None
 * Return: None
 ******************************************************************************/
BACKUP LEGACY FUNCTION
Function: Connect to Wifi with fail to AP mode if no connection
Description: This connection will attempt to create a WiFi connection with the given SSID and password. If the connection fails, it will attempt to connect to a default Wifi AP.
Parameters: None
Return: None
BACKUP LEGACY FUNCTION Function : Connect to Wifi with fail to AP mode if no connection Description : This connection will attempt to create a WiFi connection with the given SSID and password . If the connection fails it will attempt to connect to a default Wifi AP . Parameters : None Return : None
void Network::connectToApWithFailToStation()
{
  WiFi.persistent(true);
  SERIAL_DEBUG_LN("Configuring access point...");
  SERIAL_DEBUG_ADD("cfg.WIFISSID:");
  SERIAL_DEBUG_LN(cfg.WIFISSID);
  SERIAL_DEBUG_ADD("cfg.WIFIPASS:");
  SERIAL_DEBUG_LN(cfg.WIFIPASS);
  WiFi.mode(WIFI_STA);
  if (cfg.WIFISSID == " ")
  {
    WiFi.reconnect();
  }
  else
  {
    WiFi.begin(cfg.WIFISSID, cfg.WIFIPASS);
  }
  int numberOfAttempts = 0;
  while (WiFi.status() != WL_CONNECTED)
  {
    numberOfAttempts++;
    delay(200);
    SERIAL_DEBUG_ADD(".");
    if (numberOfAttempts > 100)
    {
      WiFi.mode(WIFI_AP);
      WiFi.softAP(cfg.WIFISSID, cfg.WIFIPASS);
      SERIAL_DEBUG_ADD("Wifi Connect Failed. \r\nStarting AP. \r\nAP IP address: ");
      SERIAL_DEBUG_LN(WiFi.softAPIP());
      return;
      break;
    }
  }
  SERIAL_DEBUG_LN("");
  SERIAL_DEBUG_LN("Connected! IP address: ");
  SERIAL_DEBUG_LN(WiFi.localIP());
}
void Network :: connectToApWithFailToStation ( ) { WiFi . persistent ( true ) ; SERIAL_DEBUG_LN ( " " ) ; SERIAL_DEBUG_ADD ( " " ) ; SERIAL_DEBUG_LN ( cfg . WIFISSID ) ; SERIAL_DEBUG_ADD ( " " ) ; SERIAL_DEBUG_LN ( cfg . WIFIPASS ) ; WiFi . mode ( WIFI_STA ) ; if ( cfg . WIFISSID == " " ) { WiFi . reconnect ( ) ; } else { WiFi . begin ( cfg . WIFISSID , cfg . WIFIPASS ) ; } int numberOfAttempts = 0 ; while ( WiFi . status ( ) != WL_CONNECTED ) { numberOfAttempts ++ ; delay ( 200 ) ; SERIAL_DEBUG_ADD ( " " ) ; if ( numberOfAttempts > 100 ) { WiFi . mode ( WIFI_AP ) ; WiFi . softAP ( cfg . WIFISSID , cfg . WIFIPASS ) ; SERIAL_DEBUG_ADD ( " \r \n \r \n " ) ; SERIAL_DEBUG_LN ( WiFi . softAPIP ( ) ) ; return ; break ; } } SERIAL_DEBUG_LN ( " " ) ; SERIAL_DEBUG_LN ( " " ) ; SERIAL_DEBUG_LN ( WiFi . localIP ( ) ) ; }
BACKUP LEGACY FUNCTION
 Function: Connect to Wifi with fail to AP mode if no connection
 Description: This connection will attempt to create a WiFi connection with the given SSID and password.
BACKUP LEGACY FUNCTION Function : Connect to Wifi with fail to AP mode if no connection Description : This connection will attempt to create a WiFi connection with the given SSID and password .
// You can remove the password parameter if you want the AP to be open.