1

I am trying to use a cert with an ESP8266. The identical code works fine on ab ESP32, but in the ESP8266 I am getting errors.

I set the cert as follows:

const char *ROOT_CERT PROGMEM = R"EOF(= "-----BEGIN CERTIFICATE-----
MIIFYDCCBEigAwIBAgIQQAF3ITfU6UK47naqPGQKtzANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
...
-----END CERTIFICATE--------)EOF"; 

For the ESP32 I use:

wifiClient.setCACert(ROOT_CERT)

This works fine, but on the 8266 I get:

no matching function for call to 'BearSSL::WiFiClientSecure::setCACert(const char*&)'

I have done some research and there are some suggestions the length is required, so I tried that also:

 wifiClient.setCACert(ROOT_CERT, sizeof(ROOT_CERT)-1);

But that produces the following error:

invalid conversion from 'const char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

I am using the 2.7.4 8266 board library as I have heard the 3.X has similar issues.

I have tried V 3.X but I get the following:

class BearSSL::WiFiClientSecure' has no member named 'setCACert'

1 Answer 1

1

i could not use setCACert with 8266. you need to do it differently and i had to do some web hunting.
But finally i did get my telegram test working from esp32 to 8266, here is what i did and hope that you can adapt it

you need :

#include <ESP8266WiFi.h>

after your defines add:

X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtokenValue,client);

in setup i had to add BOTH of these lines (i initially didnt think i needed the 1st line, but apparently you do) :

configTime(0, 0, "pool.ntp.org");   // get UTC time via NTP
client.setTrustAnchors(&cert);      // Add root certificate for api.telegram.org

this got my ESP32 code converted from ESP32 to 8266

1
  • PS- replace WiFi.h with the ESP8266WiFi.h Commented Apr 23, 2023 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.