Hello everyone and thank you for your help.
I have a problem. I have a ready working project: esp32 sends HTTP requests to the server and communicates via Bluetooth with the phone. I decided to switch from HTTP to HTTPS protocol and faced with a lack of memory even in an empty project (new), where I use only Bluetooth and HTTPS.
For example, here is the code with commented bluetooth initialization (The response from the server was received as expected):
#include <BluetoothSerial.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <WiFi.h>
char* sendPostRequest(const char* url, const char* prefix, const char* payload);
void initHTTPS(const char* url);
void initWebSocket(const char* url);
BluetoothSerial bs;
WiFiClientSecure clientHTTPS;
HTTPClient http;
String ssid = "TP-ssid";
String password = "password";
String msg = "{\"chipId\":\"34545642323523564\"}";
String url = "https://blink-off.space:8443/init-token";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid.c_str(), password.c_str());
for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
Serial.print(".");
delay(1000);
}
//bs.begin("blName");
initHTTPS(url.c_str());
//bs.begin("blName");
}
void loop() {
Serial.printf("Free heap: %u bytes\n", ESP.getFreeHeap());
String rq = sendPostRequest(url.c_str(), "init", msg.c_str());
Serial.println(rq);
delay(5000);
}
void initHTTPS(const char* url) {
clientHTTPS.setInsecure(); // Disabling certificate verification
//clientHTTPS.setCACert(echo_org_ssl_ca_cert);
if (!http.begin(clientHTTPS, url)) {
// If connection initialization failed
//return nullptr;
}
http.addHeader("Content-Type", "application/json");
}
char* sendPostRequest(const char* url, const char* prefix, const char* payload) {
//String payloadString = String(payload);
String encryptedPayload = String(payload);
// Forming a JSON message
char message[256];
snprintf(message, sizeof(message), "{\"%s\" : \"%s\"}", prefix, encryptedPayload.c_str());
int httpResponseCode = http.POST(message);
if (httpResponseCode > 0) {
String response = http.getString();
http.end();
// We allocate memory for the response and copy it there
char* responseCStr = (char*)malloc(response.length() + 1);
if (responseCStr) {
strcpy(responseCStr, response.c_str());
}
return responseCStr;
} else {
http.end();
return nullptr;
}
}
Now let's uncomment the line bs.begin("blName"); And we see a cyclic error, every 5 seconds when trying to request:
[ 1823][E][ssl_client.cpp:37] _handle_error(): [start_ssl_client():273]: (-17040) RSA - The public key operation failed : BIGNUM - Memory allocation failed
[ 1837][E][WiFiClientSecure.cpp:144] connect(): start_ssl_client: -17040
I repeat, when commenting on the bluetooth initialization line, everything works fine, but in my main project I need both bluetooth and HTTPS at the same time. HTTP (no hhtps) + Bluetooth is working correctly.