Skip to content

WiFiClient error [WiFiClient.cpp:443] connected(): RES: -1 #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aietes opened this issue Dec 2, 2018 · 3 comments · Fixed by #2140
Closed

WiFiClient error [WiFiClient.cpp:443] connected(): RES: -1 #2139

Aietes opened this issue Dec 2, 2018 · 3 comments · Fixed by #2140

Comments

@Aietes
Copy link

Aietes commented Dec 2, 2018

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: latest
IDE name: Platform.io with Visual Studio Code
Flash Frequency: ?40Mhz?
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Mac OSX

Description:

I'm trying to connect and send a message via MQTT over WiFi. Code that used to run flawlessly now fails with error [WiFiClient.cpp:443] connected(): RES: -1. I'm not sure what is causing it. I'm using the PubSubClient library to send and receive MQTT message.

I'm connecting to WiFi in the standard way:

bool myWiFi::connect(String *ssid, String *pass)
{
  Serial.print("Connecting to WiFi");

  WiFi.mode(WIFI_STA);
  while (WiFi.status() == 255)
    ; //wait till WiFi is available

  if (!WiFi.reconnect() )
  {
    WiFi.begin(ssid->c_str(), pass->c_str());
  }

  unsigned long millis_rto = millis();
  unsigned long millis_cto = millis();
  while (WiFi.waitForConnectResult() != WL_CONNECTED)
  {
    Serial.print(".");
    if (millis() - millis_rto >= RETRY_TIMEOUT)
    {
      //reset timer
      millis_rto = millis();
      //start new try
      Serial.print("\nConnecting to WiFi");
      WiFi.begin(ssid->c_str(), pass->c_str());
    }
    if (millis() - millis_cto >= CONN_TIMEOUT)
    {
      Serial.println("\nWiFi connection timed out, open AP.");
      getConfig(ssid, pass);
      return false;
    }
    delay(500);
  }

  Serial.print("\nConnected to WiFi with IP ");
  Serial.println(WiFi.localIP());
  return true;
}

The connection works, the error message appears after a successful connection and receiving an IP.
I'm tracing the WiFi events to find out what's going on with WiFi.onEvent(WiFiEvent). I'm getting the expected sequence of events:

Connecting to WiFi
WiFi Event: 0
WiFi Event: 2
WiFi Event: 5
Connecting to WiFi.
WiFi Event: 4
WiFi Event: 7
Connected to WiFi with IP 192.168.178.57

But then the following error occurs:

[E][WiFiClient.cpp:443] connected(): RES: -1

Despite this error message, the first MQTT package is being sent. When I call the mqtt.loop() function though, this error appears in every tick.

Again, this code worked for months now, this error message is new after updating the libraries to the latest version. I'm looking for help on how to find the cause for this error, I'm not sure where to start.

@Aietes Aietes changed the title WiFi connection drops [WiFiClient.cpp:443] connected(): RES: -1 WiFi connection error [WiFiClient.cpp:443] connected(): RES: -1 Dec 2, 2018
@Aietes
Copy link
Author

Aietes commented Dec 2, 2018

I'm realizing that this must be connected to the PubSubClient making a connection to an MQTT server via WiFiClient, so probably this error has little to do with the actual connection to the AP. I'll reference this issue in PubSubClient.

@Aietes Aietes changed the title WiFi connection error [WiFiClient.cpp:443] connected(): RES: -1 WiFiClient error [WiFiClient.cpp:443] connected(): RES: -1 Dec 2, 2018
@luc-github
Copy link
Contributor

check this : #2140

@Aietes
Copy link
Author

Aietes commented Dec 2, 2018

Yes, that's where the message originates. I'm not sure though if there is an underlying issue to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants