Description
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.