Hey,
I really reviewied all examples available in internet and on this forum, but cannot really find proper answer or something that will work (looks like some examples work with some websites, but not with mine, or with www.google.com etc), and I think that code was working long time ago, and now it stopped:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
void setup() {
Serial.begin(115200);
Serial.println(F("\n\r* * * ESP BOOT * * *"));
Serial.println(F("WiFi begin!"));
WiFi.mode(WIFI_STA);
WiFi.begin("xxxx", "xxxx");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(F("\n\rWiFi connected!"));
}
void getpr24h() {
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
client->setTimeout(4000);
if (https.begin(*client, "https://www.knappe.pl/aaa.html")) { // HTTPS
Serial.println("[HTTPS] GET...");
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server?
if (httpCode == HTTP_CODE_OK) {
const String& payload = https.getString();
Serial.println(String("[HTTPS] Received payload: ") + payload);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n\r", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n\r");
}
}
void loop() {
getpr24h();
Serial.println("Wait 20s before next round to not get banned on API server...");
delay(20000);
}
and response I'm getting is:
WiFi begin!
....................
WiFi connected!
[HTTPS] GET...
[HTTPS] GET... code: 200
[HTTPS] Received payload:
Wait 20s before next round to not get banned on API server...
[HTTPS] GET...
[HTTPS] GET... code: 200
[HTTPS] Received payload:
Wait 20s before next round to not get banned on API server...
[HTTPS] GET...
[HTTPS] GET... code: 200
[HTTPS] Received payload:
I tried HTTP, HTTPS, json file, HTML file, and it doesn't work.