How can I set an insecure connection with ESP32?

Pia012
Posts: 4
Joined: Mon Aug 29, 2022 12:22 pm

How can I set an insecure connection with ESP32?

Postby Pia012 » Sun Nov 13, 2022 5:56 pm

Hi everyone, I am porting my old code from ESP8266 to ESP32. I am optimizating it too, but I would like to know how can I translate this two rows:
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure(); // this is the magical line that makes everything work
I am finding a lot of guide with secure connection and certificates, but I would like to find a connection that it won't expire in the future. I need to send data to my server, so i know the destination.

the code is:

Code: Select all

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>

const int httpsPort = 443;

void postHttpsRequest(String parameter1, String parameter2) {   
  String postData; 
  String var1 = splitString(parameter1, '=', 0);
  float value1 = splitString(parameter1, '=', 1).toFloat();
  String var2 = splitString(parameter2, '=', 0);
  String value2 = splitString(parameter2, '=', 1);
  
  postData = var1 + String("=");
  postData += String(value1);
  postData += "&" + var2 + String("=");
  postData += value2;
  String pageSite = host + String("take") + var1 + String (".php");

  std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
  client->setInsecure(); // this is the magical line that makes everything work

  HTTPClient http;  
  if (http.begin(*client, pageSite)) { //works
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    //Send the request
    int httpCode = http.POST(postData); 
    //Get the response payload    
    String payload = http.getString();   
    if(httpCode == HTTP_CODE_OK){
    //Print HTTP return code
      Serial.println(payload + "["+String(httpCode)+"_ans]"); 
    }else{
      value2.trim();
      Serial.println(var1 + ":" + String(value1) + ";" + String(value2) + "["+String(httpCode)+"_ans]");
    } 
    //Print request response payload
    //Serial.println(payload);    
    http.end();
  }else{
    value2.trim();
    Serial.println(var1 + ":" + String(value1) + ";" + String(value2) + "["+String(408)+"_ans]");
  }


Who is online

Users browsing this forum: No registered users and 81 guests