Skip to content

WiFiClientSecure::lastError() returns invalid value for successful connection #7365

@klew

Description

@klew

Board

ESP32 dev module

Device Description

plain board with nothing connected to

Hardware Configuration

nothing

Version

v2.0.5

IDE Name

Arduino IDE

Operating System

Ubuntu 22.04

Flash frequency

40 MHz

PSRAM enabled

yes

Upload speed

115200

Description

WiFiClientSecure::lastError() method returns invalid values when called after successful WiFiClientSecure::connect().

connect() methods are setting _lastError variable to return code of start_ssl_client() which on success returns > 0 value and internally considers < 0 return value as an error.
However in lastError() method implementation, only value == 0 is considered as "no error situation". For > 0 values, implementation attemp to get error string via mbedtls_strerror, which for > 0 values gives "UNKNOWN ERROR CODE".

I expect to get 0 (no error) in lastError() method, when there was no error :)

Sketch

auto clientSec = new WiFiClientSecure;
if (clientSec) {
  int result = clientSec->connect(host, port);
  char buf[200];
  int lastErr = 0;
  lastErr = clientSec->lastError(buf, sizeof(buf));
  // print lastErr
}

Debug Message

-

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions