From 84fac0add80a3d4b7f9ac564a27ff11bcb34b206 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Sun, 23 Apr 2023 17:38:24 +0200 Subject: [PATCH] Add overloads to support __FlashStringHelper like ESP8266 has them. --- cores/esp32/WString.h | 4 ++-- libraries/ESPmDNS/src/ESPmDNS.cpp | 4 ++-- libraries/ESPmDNS/src/ESPmDNS.h | 5 ++++- libraries/WiFi/src/WiFiSTA.h | 6 ++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cores/esp32/WString.h b/cores/esp32/WString.h index 261868bc9aa..9dd58fb6574 100644 --- a/cores/esp32/WString.h +++ b/cores/esp32/WString.h @@ -34,8 +34,8 @@ // A pure abstract class forward used as a means to proide a unique pointer type // but really is never defined. class __FlashStringHelper; -#define FPSTR(pstr_pointer) (pstr_pointer) -#define F(string_literal) (string_literal) +#define FPSTR(str_pointer) (reinterpret_cast(str_pointer)) +#define F(string_literal) (FPSTR(string_literal)) // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. diff --git a/libraries/ESPmDNS/src/ESPmDNS.cpp b/libraries/ESPmDNS/src/ESPmDNS.cpp index 77ab313a08f..cb2828716b1 100644 --- a/libraries/ESPmDNS/src/ESPmDNS.cpp +++ b/libraries/ESPmDNS/src/ESPmDNS.cpp @@ -60,7 +60,7 @@ MDNSResponder::~MDNSResponder() { end(); } -bool MDNSResponder::begin(const char* hostName){ +bool MDNSResponder::begin(const String& hostName){ if(mdns_init()){ log_e("Failed starting MDNS"); return false; @@ -68,7 +68,7 @@ bool MDNSResponder::begin(const char* hostName){ //WiFi.onEvent(_on_sys_event); _hostname = hostName; _hostname.toLowerCase(); - if(mdns_hostname_set(hostName)) { + if(mdns_hostname_set(hostName.c_str())) { log_e("Failed setting MDNS hostname"); return false; } diff --git a/libraries/ESPmDNS/src/ESPmDNS.h b/libraries/ESPmDNS/src/ESPmDNS.h index 16c590d4a87..9a5e5c14184 100644 --- a/libraries/ESPmDNS/src/ESPmDNS.h +++ b/libraries/ESPmDNS/src/ESPmDNS.h @@ -54,7 +54,10 @@ class MDNSResponder { public: MDNSResponder(); ~MDNSResponder(); - bool begin(const char* hostName); + bool begin(const String& hostName); + bool begin(const char* hostName){ + return begin(String(hostName)); + } void end(); void setInstanceName(String name); diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index b8bb855c198..76bddb3dc23 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -45,7 +45,13 @@ class WiFiSTAClass public: wl_status_t begin(const char* wpa2_ssid, wpa2_auth_method_t method, const char* wpa2_identity=NULL, const char* wpa2_username=NULL, const char *wpa2_password=NULL, const char* ca_pem=NULL, const char* client_crt=NULL, const char* client_key=NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true); + wl_status_t begin(const String& wpa2_ssid, wpa2_auth_method_t method, const String& wpa2_identity = (const char*)NULL, const String& wpa2_username = (const char*)NULL, const String& wpa2_password = (const char*)NULL, const String& ca_pem = (const char*)NULL, const String& client_crt = (const char*)NULL, const String& client_key = (const char*)NULL, int32_t channel=0, const uint8_t* bssid=0, bool connect=true) { + return begin(wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), channel, bssid, connect); + } wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); + wl_status_t begin(const String& ssid, const String& passphrase = (const char*)NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true) { + return begin(ssid.c_str(), passphrase.c_str(), channel, bssid, connect); + } wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true); wl_status_t begin();