Open pasagame opened 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
ESP8266WebServer Server; AutoConnect Portal(Server);
WebServer Server; AutoConnect Portal(Server);
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";
std::unique_ptrclient(new BearSSL::WiFiClientSecure); client -> setInsecure(); HTTPClient http; http.begin(*client, url);
HTTPClient http; http.begin(url);
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();
} `
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();
} `