You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The functions WiFiClientSecure.remoteIP(), remotePort(), localIP(), localPort() return 0. This is caused by the fact, that WiFiClientSecure is derived from WiFiClient but doesn't use its ClientContext* _client variable. It uses WiFiClient class that is the base of WiFiClientSecureCtx* _ctx instead, as is written in the documentation of the WiFiClientSecure class.
The problem is, that WiFiClientSecure.remoteIP() calls WiFiClient.remoteIP() with _client=nullptr instead of calling something like WiFiClientSecure._ctx->remoteIP(). The same holds with the other 3 function mentioned in the title.
The solution is to make these functions virtual and override them in WiFiClientSecure class.
I am creating a PR in no time.
/* This sketch establishes a TCP connection to a "quote of the day" service. It sends a "hello" message, and then prints received data.*/
#include<ESP8266WiFi.h>
#ifndef STASSID
#defineSTASSID"xxx"
#defineSTAPSK"xxx"
#endifconstchar* ssid = STASSID;
constchar* password = STAPSK;
constchar* host = "github.com";
constuint16_t port = 443;
voidsetup() {
Serial.begin(115200);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default, would try to act as both a client and an access-point and could cause network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
voidloop() {
staticboolwait = false;
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
// Use WiFiClient class to create TCP connections
WiFiClientSecure client;
client.setInsecure();
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
Serial.print(client.remoteIP().toString().c_str());
Serial.print(':');
Serial.println(client.remotePort());
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
if (wait) {
delay(300000); // execute once every 5 minutes, don't flood remote service
}
wait = true;
}
Debug Messages
expected:
WiFi connected
IP address:
192.168.1.137
connecting to github.com:443
140.82.121.4:443
got:
WiFi connected
IP address:
192.168.1.137
connecting to github.com:443
(IP unset):0
The text was updated successfully, but these errors were encountered:
Thanks for your fix, you're great, man! I've dug through the whole Internet trying to figure out why server.client().remoteIP().toString() returns "(IP unset)"!
Basic Infos
Platform
Settings in IDE
Problem Description
The functions
WiFiClientSecure.remoteIP(), remotePort(), localIP(), localPort()
return 0. This is caused by the fact, thatWiFiClientSecure
is derived fromWiFiClient
but doesn't use itsClientContext* _client
variable. It usesWiFiClient
class that is the base ofWiFiClientSecureCtx* _ctx
instead, as is written in the documentation of theWiFiClientSecure
class.The problem is, that
WiFiClientSecure.remoteIP()
callsWiFiClient.remoteIP()
with_client=nullptr
instead of calling something likeWiFiClientSecure._ctx->remoteIP()
. The same holds with the other 3 function mentioned in the title.The solution is to make these functions virtual and override them in
WiFiClientSecure
class.I am creating a PR in no time.
MCVE Sketch
The sketch is a modified WiFiClient example
Debug Messages
expected:
got:
The text was updated successfully, but these errors were encountered: