WiFi connection stopped working

I have an ESP32-CAM and have set it up so that it captures images and sends them, via WiFi, to an application written (by me) in C# that's running on my laptop. It's been working for months just fine, bit it suddenly stopped working. The C# application sits in a loop waiting for a connection request but never receives one. The arduino app running on the ESP32-CAM is trying to do a connect to the laptop app but just keeps timing out without a connection being established.

Again, this all worked fine for a long time and, with no change to that part of the code, has simply stopped working. The Arduino code keeps trying to connect by the C# code never encounters a connection request.

I DID do a Windows Update, in response to its constant reminders, and it's right after that when the WiFi connection failures started. I noticed that the new version of Windows now includes an option to set up your computer as a Mobile WiFi Hotspot and figured that might be the problem. But even after I enabled that under Windows I continue to get the connection failures.

So I need some advice.

Here's the code that's running on the ESP32-CAM.

bool ConnectToComputerServerAppViaWifi()
{
  // We start by connecting to a WiFi Station
  char WiFiRouter_ssid[] = "TP-LINK_0E";
  char WiFiRouter_password[] = "610264";
  WiFiMulti.addAP(WiFiRouter_ssid, WiFiRouter_password);

  Serial.print("Waiting for WiFi Router , " + String(WiFiRouter_ssid) + " : " + String(WiFiRouter_password) + " ");

  // The following SUCCEEDS in connecting to my WiFi Router, which is connected (via WiFi) to my laptop. 
  while (WiFiMulti.run() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }

  Serial.print("\nSUCCESS: Connected to WiFi Router : " + String(WiFiRouter_ssid) 
    + " : password : " + String(WiFiRouter_password) 
    + " : IP address: " + WiFi.localIP() + "\n");

  delay(500);

  const uint16_t ComputerPort = 1000;
  const char * ComputerHost_IP = "192.168.0.99";

  Serial.print("Connecting to Computer : IP = " + String(ComputerHost_IP) + " at port " + String(ComputerPort) + "\n");

  // BUT the following consistently FAILS to make the connection through to the app running on the laptop.
  // It USED to always work, but now, ... never connects.
  while (!theWiFiClientConnectedToTheComputerServerApp.connect(ComputerHost_IP, ComputerPort))
  {
    Serial.println("Connection failed.");
    Serial.println("Waiting 1 second] before retrying...");
    delay(1000);
  }

  Serial.print("SUCCESS Connecting to Computer : IP = " + String(ComputerHost_IP) + " at port " + String(ComputerPort) + "\n");

  return true;
}

Here's the pertinent code, in C#, that's running on my laptop, waiting for the connection request from the ESP32-CAM;

        private void Listening() // Listening for connection request.
        {
            while (IsListening) 
            {
                // It gets here.
                // NOTE: myserver is:
                //         public TcpListener myserver; and is properly set up before getting here.
                if (myserver.Pending() == true) // Determines if there are pending connection requests.
                {
                    // BUT it NEVER gets here.
                    client = myserver.AcceptTcpClient();
                    ByteStreamReaderComingInFromClient = client.GetStream();
                    TextStreamReaderComingInFromClient = new StreamReader(client.GetStream());
                    TextStreamWriterGoingToClient = new StreamWriter(client.GetStream());

                    IsConnected = true;
                }

None of this code has changed from back when it was working just fine.
But now the C# application on the laptop never recognizes that a connection request has been made
by the Arduino code running on theESP32-CAM. The Arduino code connects just fine to the TP-LINK Wifi router, but doesn't seem to get through to the app on the laptop.

Here's the code that's running on the ESP32-CAM.

Wrong, that's a small excerpt of the code. Post code that at least compiles!

That's the code that's pertinent to the problem that I'm encountering.

The entre program is over a thousand lines long. You seriously think that posting all of that would help? Who's going to look through thousands of lines of code to try to zero in on what the problem might be.

If you look at the code that I DID post and don't see anything wrong with it, then say so, but your comment that it's "not the code that's running" is not helpful at all.

Maybe check the firewall on the Windows Laptop. You can also check whether your laptop's Network Status changed. Windows is notorious for changing it after each reboot. Make sure it's "Private" instead of "Public". "Public" is by default a lot more restricted because it assumes you are connected to a public network (like in a Hooters or a strip club)

zzz.png

zzz.png

Ahhh, already the thread goes the way of ripping into each other.

Anways, I use an extended WiFiEvent callback to troubleshoot ESP32 WiFi issues.

The parts commented out were my temporary fixes till I figured out the issue.

void WiFiEvent(WiFiEvent_t event)
{
   log_i( "[WiFi-event] event: %d\n", event );
  switch (event) {
        case SYSTEM_EVENT_WIFI_READY:
          log_i("WiFi interface ready");
          break;
        case SYSTEM_EVENT_SCAN_DONE:
          log_i("Completed scan for access points");
          break;
        case SYSTEM_EVENT_STA_START:
          log_i("WiFi client started");
          break;
        case SYSTEM_EVENT_STA_STOP:
          log_i("WiFi clients stopped");
          break;
    case SYSTEM_EVENT_STA_CONNECTED:
      log_i("Connected to access point");
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      log_i("Disconnected from WiFi access point");
      break;
        case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
          log_i("Authentication mode of access point has changed");
          break;
        case SYSTEM_EVENT_STA_GOT_IP:
          log_i ("Obtained IP address: %s",  WiFi.localIP() );
          break;
        case SYSTEM_EVENT_STA_LOST_IP:
          log_i("Lost IP address and IP address is reset to 0");
          //      vTaskDelay( 5000 );
          //      ESP.restart();
          break;
        case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
          log_i("WiFi Protected Setup (WPS): succeeded in enrollee mode");
          break;
        case SYSTEM_EVENT_STA_WPS_ER_FAILED:
          log_i("WiFi Protected Setup (WPS): failed in enrollee mode");
          //      ESP.restart();
          break;
        case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
          log_i("WiFi Protected Setup (WPS): timeout in enrollee mode");
          break;
        case SYSTEM_EVENT_STA_WPS_ER_PIN:
          log_i("WiFi Protected Setup (WPS): pin code in enrollee mode");
          break;
        case SYSTEM_EVENT_AP_START:
          log_i("WiFi access point started");
          break;
        case SYSTEM_EVENT_AP_STOP:
          log_i("WiFi access point  stopped");
          //      WiFi.mode( WIFI_OFF);
          //      esp_sleep_enable_timer_wakeup( 1000000 * 2 ); // 1 second times how many seconds wanted
          //      esp_deep_sleep_start();
          break;
        case SYSTEM_EVENT_AP_STACONNECTED:
          log_i("Client connected");
          break;
    case SYSTEM_EVENT_AP_STADISCONNECTED:
      log_i("WiFi client disconnected");
          break;
        case SYSTEM_EVENT_AP_STAIPASSIGNED:
          log_i("Assigned IP address to client");
          break;
        case SYSTEM_EVENT_AP_PROBEREQRECVED:
          log_i("Received probe request");
          break;
        case SYSTEM_EVENT_GOT_IP6:
          log_i("IPv6 is preferred");
          break;
        case SYSTEM_EVENT_ETH_GOT_IP:
          log_i("Obtained IP address");
          break;
    default: break;
  }
}[code]

And I throw in My WiFi connection function because it may be useful:
[code]void connectToWiFi()
{
  log_i( "connect to wifi" );
  while ( WiFi.status() != WL_CONNECTED )
  {
    WiFi.disconnect();
    WiFi.begin( SSID, PASSWORD );
    log_i(" waiting on wifi connection" );
    vTaskDelay( 4000 );
  }
  log_i( "Connected to WiFi" );
  WiFi.onEvent( WiFiEvent );
}

Even if there has not been a connection ESPRESSIF recommends, you can read about in the AP API Reference - ESP32 - — ESP-IDF Programming Guide latest documentation or on their site, issuing a disconnect command before making a connection. A WiFi disconnect clears out certain properties of the WiFi stack.

Also.

If you really want to check for/if WiFi is connected, use as in the below if statement.

//check for a is-connected and if the WiFi 'thinks' its connected, found checking on both is more reliable than just a single check
    if ( (wifiClient.connected()) && (WiFi.status() == WL_CONNECTED) )
    {
      xSemaphoreTake( sema_MQTT_KeepAlive, portMAX_DELAY ); // whiles MQTTlient.loop() is running no other mqtt operations should be in process
      MQTTclient.loop();
      xSemaphoreGive( sema_MQTT_KeepAlive );
    }

hzrnbgy:
It is indeed set to Public, but when I click on the Private option it just ignores it. It doesn't change to Private.

Load one of the wifi example sketches and see if you can connect

Another option is to disable the firewall entirely. If that works, then you know what the problem is. Why its not accepting is entirely a different issue.