Wifi stopped working after months (solved I hope)

I got a Mega2560 and a ESP-01 module. The sketch has been running for months but suddenly stopped working. There sketch has not changed.

Need some help/feedback on how to debug this problem.

When restarting the controller it issue the following AT commands (log from serial monitor):

10:47:54.062 -> Init Wifi.
10:47:54.062 -> ---> AT
10:47:54.062 -> Trying...
10:47:54.102 -> <--- DONE
10:47:54.102 -> ---> AT+CWMODE=1
10:47:54.102 -> Trying...
10:47:54.102 -> <--- DONE
10:47:54.142 -> Connecting Wifi...
10:47:54.142 -> ---> AT+CWJAP="mySSID","mysecretpassword"
10:47:54.222 -> Trying...
10:47:54.222 -> <--- DONE
10:47:54.262 -> ---> AT+CIPMUX=1
10:47:54.262 -> Trying...
10:47:54.302 -> <--- DONE
10:47:54.302 -> WiFi OK

10:47:54.382 -> *****************************************************
10:47:54.422 -> ********** Open TCP connection 
10:47:54.462 -> ---> AT+CIPSTART=0,"TCP","192.168.2.22",80
10:47:54.502 -> Trying...
10:47:55.542 -> Trying...
10:47:56.382 -> <--- DONE
10:47:56.382 -> ---> AT+CIPSEND=0,38
10:47:56.422 -> Trying...
10:47:57.422 -> Trying...
10:48:00.222 -> Trying...
10:48:01.302 -> Trying...
10:48:02.382 -> Trying...
10:48:03.422 -> Trying...
10:48:04.502 -> Trying...
10:48:05.582 -> Trying...
10:48:06.662 -> Trying...
10:48:07.742 -> Trying...
10:48:08.822 -> <--- FAILED, error count=1
10:48:08.822 -> ********** Close TCP Connection 
10:48:08.862 -> *****************************************************

I have tried different wifi modules but without success. Also tried to access two different WiFi routers.
I can see in the routers DHCP table that the module has got an IP address.

I also have a nano using the same module and it works fine. I see the requests from the nano in the webserver's log. The nano is using the same router.

Suggestions?

BTW, part of code in use:

HardwareSerial &wifi = Serial3;
uint32_t wifiErrorCount = 0;

bool sendATcmd(const char *AT_cmd, int AT_cmd_maxTime, const char *readReplay) 
{
  int   trycnt = 0;
  bool  status = false;
  
  Serial.print(F("---> "));
  Serial.println(AT_cmd);

  while (trycnt < AT_cmd_maxTime) {
    Serial.println(F("Trying..."));
    wifi.println(AT_cmd);
    if (wifi.find(*readReplay)) {
      AT_cmd_result = true;
      break;
    }
  
    ++trycnt;
  }
  
  Serial.print(F("<--- "));
  if (true == AT_cmd_result) {
    Serial.println(F("DONE"));
    status = true;
  } else {
    ++wifiErrorCount;
    Serial.print(F("FAILED, error count="));
    Serial.println(wifiErrorCount);
  }

  AT_cmd_result = false;

  return status;
}


void setup()
{
  Serial.begin(9600);
  Serial.println(F("\n\nInitializing"));

  bool  status = false;
  char  atcmd[100];
  
  Serial.println(F("Init Wifi."));
  wifi.begin(9600);
  for (int i = 0; !status && 10 > i; i++) {
    status = sendATcmd("AT", 5, "OK");
    if (status) {
      status = sendATcmd("AT+CWMODE=1", 5, "OK");
    } else {
      delay(1000);
      Serial.println(F("- Failed"));
    }
  }

  if (status) {
    debugprintF(2, F("Connecting Wifi..."));
    Serial.println(ssid);
    sprintf_P(atcmd, PSTR("AT+CWJAP=\"%s\",\"%s\""), ssid, password);
    status = sendATcmd(atcmd, 20, "OK");
  }
  
  if (status) {
    status = sendATcmd("AT+CIPMUX=1", 10, "OK");
  }
  wifiOk = status;

  if (wifiOk) {
    Serial.println(F("WiFi OK"));
  }

  // TEST CODE.
  if (wifiOk) {
    Serial.println(F("Testing Wifi..."));
    for (int i = 0; 3 > i; i++) {
      Serial.println(F("\n\n*****************************************************"));
      Serial.println(F("********** Open TCP connection "));

      sprintf_P(atcmd, PSTR("AT+CIPSTART=0,\"TCP\",\"%s\",%s"), host, port);
      status = sendATcmd(atcmd, 20, "OK");
      
      // Create the URL for the request.
      if (status) {
        char  atcmd2[20];
        
        sprintf_P(atcmd, PSTR("GET /foo/bar/mega.php?&v1=%d&v2=%d"),  random(10, 100),  random(10, 100));
        sprintf_P(atcmd2, PSTR("AT+CIPSEND=0,%d"), strlen(atcmd) + 4);
        status = sendATcmd(atcmd2, 10, ">");
          
        if (status) {
          sendATcmd(atcmd, 10, "OK");
          status = sendATcmd("AT+CIPCLOSE=0", 10, "OK");
        }
        
        Serial.println(F("********** Close TCP Connection "));
        Serial.println(F("*****************************************************"));
      }
    }
  }
}

It sounds like the port pin on your Arduino has failed as everything works with a different arduino so the shield appears OK. Try a different pin and adjust your code accordingly. I am not saying but what you are describing is also the symptoms of ESD; it works then dies sometime later. You may have to change Arduinos.

I thought that the pins may be bad so I made a sketch testing the two pins to the WiFi module and they seem to work OK.

The funny thing is that after adding a lot of debug code to write out the response from the WiFi module, it start working again. It also worked when the debug code was removed.

So now I'm happy that it work again. But I still try to find out what happened - what caused this behavior.

thehardwareman:
I thought that the pins may be bad ......... I still try to find out what happened - what caused this behavior.

You might have been right. You obviously know what you are doing with code so, unless there is something you are not telling us, the problem may well have been mechanical.

Nick_Pyner:
You might have been right. You obviously know what you are doing with code so, unless there is something you are not telling us, the problem may well have been mechanical.

ROLOF... I hope I know what I'm doing. And I hope have told you everything relevant on this issue, but I'm not sure :slight_smile:

This kind of problem is a bit irritating because now I have this feeling of "how long will this work before I see the same problem again?".

Currently this sketch and HW setup/configuration is just a test for something I'm going to make and I want the final product to work properly.

thehardwareman:
"how long will this work before I see the same problem again?".

The more likely the problem is mechanical, the more relevant that particular question is. If your test setup is on a breadboard, "several months" is plenty of time for things to move. It also should be adequate time to prove that your code is kosher.

One thing you might not have told us about is the power supply.

Nick_Pyner:
The more likely the problem is mechanical, the more relevant that particular question is. If your test setup is on a breadboard, "several months" is plenty of time for things to move. It also should be adequate time to prove that your code is kosher.

One thing you might not have told us about is the power supply.

It might be mechanical but I find it a bit odd that the WiFi adapter got an IP from the WiFi router upon startup.

I got a 3A 5V PWM. Should be plenty enough.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.