Hieromon / AutoConnect

An Arduino library for ESP8266/ESP32 WLAN configuration at runtime with the Web interface
https://hieromon.github.io/AutoConnect/
MIT License
911 stars 190 forks source link

how to use esp8266 with WiFiClientSecure #612

Open pasagame opened 1 year ago

pasagame commented 1 year ago

I use this code with esp32, it works normally, but when used with esp8266, it cannot retrieve data. how to fix issue? thank you.

`#include

ifdef ARDUINO_ARCH_ESP8266

include

include

include

include

ESP8266WebServer Server; AutoConnect Portal(Server);

else

include

include

include

WebServer Server; AutoConnect Portal(Server);

endif

void rootPage() { char content[] = "Hello, world"; Server.send(200, "text/plain", content); }

void setup() { Serial.begin(115200); Serial.println(""); Server.on("/", rootPage); if (Portal.begin()) Serial.println("WiFi connected: " + WiFi.localIP().toString()); updateData(); }

void loop() { Portal.handleClient(); }

void updateData() {

String url = "https://www.myweb.com/api/xml/mydata=259874";

ifdef ARDUINO_ARCH_ESP8266

std::unique_ptrclient(new BearSSL::WiFiClientSecure); client -> setInsecure(); HTTPClient http; http.begin(*client, url);

else

HTTPClient http; http.begin(url);

endif

int httpCode = http.GET(); Serial.println(httpCode);

if (httpCode > 0) { String payload = http.getString(); Serial.println(payload); } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end();

} `