(SOLVED) Problem with esp8266 and HTTPS

Hi, I'm trying to make a ddns updater using an esp8266 ("WEMOS D1 mini" clone), the way to update it is by making an https request to a specific url of each ddns record.

I'm basing myself on this forum thread:
https://forum.arduino.cc/t/esp8266-httpclient-library-for-https/495245/4

My problem is that when compiling this code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

HTTPClient http;
WiFiClient client;

// Sustituir por los datos de vuestro WiFi
const char* ssid = "*****";
const char* password = "*****";
String Url[2] = {
  "*****", //*****
  "*****"  //*****
};
String Print[2] = {
  "*****", //*****
  "*****"  //*****
};
int    NumUrl = 2;
void setup()
{
   Serial.begin(115200);
   delay(1000);
   // Conectar WiFi
   WiFi.begin(ssid, password);
   Serial.println("Conectando ");
   while (WiFi.status() != WL_CONNECTED){ 
      delay(500);
      Serial.print(".");
   }
   Serial.println("");
}
void loop(){
  for(int i = 0; i <= NumUrl; i++){
    PeticionHTTP(Url[i], Print[i]);
    delay(5000);
  }
  delay(900000);
}

void PeticionHTTP(String url_, String print_){
  if (http.begin(url_, print_)){
    Serial.print("[HTTP] GET...\n");
    int httpCode = http.GET();  // Realizar peticiĆ³n
    if (httpCode > 0) {
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);
      if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
        String payload = http.getString();   // Obtener respuesta
        Serial.println(payload);   // Mostrar respuesta por serial
      }
    }else {
      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
  }else {
    Serial.printf("[HTTP} Unable to connect\n");
  }
}

i get this error

C:\Users\Arixt\Documents\Arduino\*****\*****.ino: In function 'void PeticionHTTP(String, String)':
*****:41:30: error: no matching function for call to 'HTTPClient::begin(String&, String&)'
   41 |   if (http.begin(url_, print_)){
      |                              ^
In file included from C:\Users\Arixt\Documents\Arduino\*****\*****.ino:2:
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:161:10: note: candidate: 'bool HTTPClient::begin(WiFiClient&, const String&)'
  161 |     bool begin(WiFiClient &client, const String& url);
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:161:28: note:   no known conversion for argument 1 from 'String' to 'WiFiClient&'
  161 |     bool begin(WiFiClient &client, const String& url);
      |                ~~~~~~~~~~~~^~~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:162:10: note: candidate: 'bool HTTPClient::begin(WiFiClient&, const String&, uint16_t, const String&, bool)'
  162 |     bool begin(WiFiClient &client, const String& host, uint16_t port, const String& uri = "/", bool https = false);
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:162:10: note:   candidate expects 5 arguments, 2 provided
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:165:10: note: candidate: 'bool HTTPClient::begin(String)'
  165 |     bool begin(String url)  __attribute__ ((error("obsolete API, use ::begin(WiFiClient, url)")));
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:165:10: note:   candidate expects 1 argument, 2 provided
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: candidate: 'bool HTTPClient::begin(String, uint16_t, String)'
  166 |     bool begin(String host, uint16_t port, String uri = "/")  __attribute__ ((error("obsolete API, use ::begin(WiFiClient, host, port, uri)")));
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:38: note:   no known conversion for argument 2 from 'String' to 'uint16_t' {aka 'short unsigned int'}
  166 |     bool begin(String host, uint16_t port, String uri = "/")  __attribute__ ((error("obsolete API, use ::begin(WiFiClient, host, port, uri)")));
      |                             ~~~~~~~~~^~~~
In file included from C:\Users\Arixt\Documents\Arduino\ydns.eu-v2\ydns.eu-v2.ino:2:
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: candidate: 'bool HTTPClient::begin(String, const uint8_t*)'
  167 |     bool begin(String url, const uint8_t httpsFingerprint[20])  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:42: note:   no known conversion for argument 2 from 'String' to 'const uint8_t*' {aka 'const unsigned char*'}
  167 |     bool begin(String url, const uint8_t httpsFingerprint[20])  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:168:10: note: candidate: 'bool HTTPClient::begin(String, uint16_t, String, const uint8_t*)'
  168 |     bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:168:10: note:   candidate expects 4 arguments, 2 provided
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:169:10: note: candidate: 'bool HTTPClient::begin(String, uint16_t, String, bool, String)'
  169 |     bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint)  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |          ^~~~~
C:\Users\Arixt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:169:10: note:   candidate expects 5 arguments, 2 provided
exit status 1
no matching function for call to 'HTTPClient::begin(String&, String&)'

String Url[2] = {
  "*****", //*****
  "*****"  //*****
};
String Print[2] = {
  "*****", //*****
  "*****"  //*****
};

aren't these supposed to be const char * , just as in the thread you linked ?
I never use https, so i'm no specialist, but it seems that begin() actually takes a pointer to the wficlient object as one of it's arguments, so i don't know if this works at all.

This loop is going to try entries 0, 1, and 2 of a two entry array. You mean:
for(int i = 0; i < NumUrl; i++) {

Hello, I have solved the problem, the point is that doing it with an esp8266 is crazy, or there is not enough documentation or it is not possible, but to make an https connection, the s keys are required (of course), but the esp8266 is not able to get them by itself, you have to give them by code, solution:

Don't break your head and buy an esp32 that does it automatically and without having to change the code every 3 months, I bought it, I sent it "almost the same code" and voila, I bought an esp32-s2 and without problem, this is the final code:

//Include libraries
#include <HTTPClient.h>
#include <WiFi.h>
#include <Preferences.h>
HTTPClient http;                                  //Create new client      
Preferences preferences;

//Add WIFI data
const char* ssid = "*****";              //Add your WIFI network name 
const char* password =  "*****";           //Add WIFI password


//Variables used in the code
int ContUpd = 0;
int response_code1 = 0;
int response_code2 = 0;

void setup() {
  delay(30000);
  preferences.begin("Vars", false);
  ContUpd = preferences.getInt("ContUpd", 0);
  delay(10);
  Serial.begin(115200);                   //Start monitor
  WiFi.begin(ssid, password);             //Start wifi connection
  Serial.print("Connecting...");
  while (WiFi.status() != WL_CONNECTED) { //Check for the connection
    delay(500);
    Serial.print(".");
  }

  Serial.print("Connected, my IP: ");
  Serial.println(WiFi.localIP());
}


void loop() {
  Serial.print("Num Updates: ");
  Serial.println(ContUpd);
   
  if(WiFi.status()== WL_CONNECTED){                   //Check WiFi connection status  
    http.begin("*****");   //Indicate the destination webpage 
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");         //Prepare the header
    int response_code = http.GET();
    response_code1 = response_code; 
    if(response_code > 0){
      Serial.println("HTTP code " + String(response_code));                     //Print return code
      if(response_code == 200){                                                 //If code is 200, we received a good response and we can read the echo data
        String response_body = http.getString();                                //Save the data comming from the website
        Serial.print("Server reply: ");                                         //Print data to the monitor for debug
        Serial.println(response_body);
      }//End of response_code = 200
    }//END of response_code > 0
  }
  if(WiFi.status()== WL_CONNECTED){                   //Check WiFi connection status  
    http.begin("*****");   //Indicate the destination webpage 
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");         //Prepare the header
    int response_code = http.GET(); 
    response_code2 = response_code; 
    if(response_code > 0){
      Serial.println("HTTP code " + String(response_code));                     //Print return code
      if(response_code == 200){                                                 //If code is 200, we received a good response and we can read the echo data
        String response_body = http.getString();                                //Save the data comming from the website
        Serial.print("Server reply: ");                                         //Print data to the monitor for debug
        Serial.println(response_body);
      }//End of response_code = 200
    }//END of response_code > 0
  }
  http.end();//End the connection
  ContUpd++;
  preferences.putInt("ContUpd", ContUpd);
  Serial.println("Next Update: 15 Min");
  delay(60000);
  Serial.println("Next Update: 14 Min");
  delay(60000);
  Serial.println("Next Update: 13 Min");
  delay(60000);
  Serial.println("Next Update: 12 Min");
  delay(60000);
  Serial.println("Next Update: 11 Min");
  delay(60000);
  Serial.println("Next Update: 10 Min");
  delay(60000);
  Serial.println("Next Update:  9 Min");
  delay(60000);
  Serial.println("Next Update:  8 Min");
  delay(60000);
  Serial.println("Next Update:  7 Min");
  delay(60000);
  Serial.println("Next Update:  6 Min");
  delay(60000);
  Serial.println("Next Update:  5 Min");
  delay(60000);
  Serial.println("Next Update:  4 Min");
  delay(60000);
  Serial.println("Next Update:  3 Min");
  delay(60000);
  Serial.println("Next Update:  2 Min");
  delay(60000);
  Serial.println("Next Update:  1 Min");
  delay(60000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.