Error when making HTTPS requests

Issue

When making request to www.google.com, the request(GET) is OK, but, when make request to google.com, this returns an error!

I have an API in Heroku, that has the X URL, and when I access using the HttpClient, it's return error(-1)!

The same error occur when access google.com!

I think that is because some type of redirect or something else, but I can't confirm this!

Somebody know how to resolve this problem?

Example code

#define TINY_GSM_MODEM_SIM800

#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>

// Defina os pinos RX e TX conectados ao SIM800L
#define MODEM_RX 19
#define MODEM_TX 18

// Substitua pelos detalhes da sua rede
const char apn[] = "claro.com.br";

// Objeto Serial para comunicação com o modem
SoftwareSerial SerialSIM(MODEM_RX, MODEM_TX);

// Inicializa o modem SIM800L
TinyGsm modem(SerialSIM);
TinyGsmClientSecure client(modem);
HttpClient http(client, "www.google.com", 443);

void setup() {
  // Inicializa o Serial Monitor
  Serial.begin(9600);

  // Configura e inicia o Serial para comunicação com o modem
  SerialSIM.begin(9600);

  delay(3000);  // Dê um tempo para o modem iniciar

  http.setHttpResponseTimeout(30000);

  // Reinicia e inicializa o modem
  modem.restart();
  Serial.println("Configurando APN...");
  modem.gprsConnect(apn, "claro", "claro");

  // Verifica se a conexão foi estabelecida
  if (modem.isGprsConnected()) {
    Serial.println("Conexão GPRS estabelecida");
  } else {
    Serial.println("Erro ao conectar GPRS. Verifique APN, usuário e senha.");
    return;
  }

  modem.sendAT("+HTTPSSL=1");
}

void loop() {
  // Faz uma requisição HTTP GET
  Serial.println("Realizando requisição HTTP GET...");
  int err = http.get("/");

  // Verifica se a requisição foi bem-sucedida
  if (err == 0) {
    Serial.println("Iniciando recebimento da resposta...");

    int status = http.responseStatusCode();
    Serial.print("Código de status: ");
    Serial.println(status);

    String response = http.responseBody();
    Serial.println("Corpo da resposta:");
    Serial.println(response);
  } else {
    Serial.print("Falha na requisição: ");
    Serial.println(err);
  }

  delay(10000);
}

Config

ESP32
SIM800L

I don't know if this applies to your issue, but I see they're different addresses, thus different servers, doing different things, maybe even different services/protocols/ports. Try executing "nslookup www.google.com" and "nslookup google.com", to see that they are not the same.

In this case I can't go any further because I used ESP WiFi connections, never used a GSM SIM800 connection to a remote server, so I'm sorry I can't say much if something could/must be changed or wrong but I'm waiting with you for someone with such kind of experience.

PS: it seems to me the "WiFiClientSecure.h" library is missing, but I don't know...

1 Like

The error was that the SIM800L only supports TLS 1.0!

And the sites(APIs) that I used, only support minimum version TLS 1.2

(Sorry English)

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