Using the Mega to send data over HTTPS?

Hello! I have this working Arduino sending data to my website, but after forcing HTTPS and SSL on the site, the Arduino Mega is not able to send data!

I added Certificate fingerprint and changed port to 443:

#include <Wire.h>
#include <ESP8266_Lib.h>
#include "WiFiEsp.h"
#include "SHTSensor.h"
SHTSensor sht;
WiFiEspClient client;


char ssid[] = "Bluelight's WiFi";            // SSID
char pass[] = "******";        // wifipassord


// your network password
int status = WL_IDLE_STATUS;
char server[] = "infernusweb.net";
char fingerprint[] = "28:A4:FD:E0:DE:25:7B:C7:DB:A5:4F:70:FD:03:1D:6E:B5:9B:E7:D2";   // added this line to enable HTTPS
#define EspSerial Serial1
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);
long sendetid;
long rssi;
double rssidouble;
double temp;
double fuktighet;

void setup()
{

  Wire.begin();
  Serial.begin(9600);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);
  delay(1600);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");



  if (sht.init()) {
    Serial.print("init(): success\n");
  } else {
    Serial.print("init(): failed\n");
  }



  sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM);
  printWifiStatus();
  sendetid = millis();
  sjekker();
  sender();
}

void loop()
{



  if ((millis() - sendetid) > 60000L) {
    sjekker();
    sender();
    rssi = WiFi.RSSI();
    rssidouble = (0 - rssi) / 10.0;
  }

}

// this method makes a HTTP connection to the server
void sender()
{
  sendetid = millis();
  Serial.println("Skal sende..");

  client.stop();
  delay(400);


  if (client.connect(server, 443)) {  // changed this line to enable HTTPS





    // if there's a successful connection
    Serial.println("Connecting...");

    // send the HTTP PUT request
    client.print(F("GET /test/write_data.php"));
    client.print("?temperatur=");
    client.print(temp);
    client.print("&fuktighet=");
    client.print(fuktighet);
    client.print("&rssi=");
    client.print(rssi);
    client.println(F(" HTTP/1.0"));
    client.println(F("Host: infernusweb.net"));
    client.println("Connection: close");
    client.println();
    client.stop();
    // note the time that the connection was made

  }
  else {
    // if you couldn't make a connection
    Serial.println("Connection failed");
  }
  Serial.println("Har sendt!");
}






void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  rssi = WiFi.RSSI();
  rssidouble = (0 - rssi) / 10.0;
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


void sjekker()
{

  if (sht.readSample()) {

    temp = sht.getTemperature();  // get temp from SHT
    fuktighet = sht.getHumidity(); // get temp from SHT
  
  } else {
    Serial.print("Error in readSample()\n");
  }
  delay(500);


  Serial.print("Temperatur = ");
  Serial.print(temp);
  Serial.print(", Fuktighet = ");
  Serial.print(fuktighet);
  Serial.print(", RSSI = ");
  Serial.println(rssi);
}

Serial output:

[WiFiEsp] Initializing ESP module
[WiFiEsp] Initilization successful - 2.0.0
Attempting to connect to WPA SSID: Bluelight's WiFi
[WiFiEsp] Connected to Bluelight's WiFi
You're connected to the network
init(): success


Signal strength (RSSI):-55 dBm
Temperatur = 24.31, Fuktighet = 32.88, RSSI = -55
Skal sende..
[WiFiEsp] Connecting to infernusweb.net
[WiFiEsp] >>> TIMEOUT >>>
Connection failed
Har sendt!
Temperatur = 24.31, Fuktighet = 32.77, RSSI = -55
Skal sende..
[WiFiEsp] Disconnecting  3
[WiFiEsp] Connecting to infernusweb.net
[WiFiEsp] >>> TIMEOUT >>>
Connection failed
Har sendt!
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
Temperatur = 24.38, Fuktighet = 32.71, RSSI = 0
Skal sende..
[WiFiEsp] Disconnecting  3
[WiFiEsp] Connecting to infernusweb.net
[WiFiEsp] >>> TIMEOUT >>>
Connection failed
Har sendt!
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
Temperatur = 24.38, Fuktighet = 32.82, RSSI = 0
Skal sende..
[WiFiEsp] Disconnecting  3
[WiFiEsp] Connecting to infernusweb.net
[WiFiEsp] >>> TIMEOUT >>>
Connection failed
Har sendt!
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
ESP8266 wifi(&EspSerial);

On a Mega?

The Mega doesn't have enough memory to do HTTPS.

It has way more then the UNO, is there a way to get this to work?
As a last resort maybe I can edit .htaccess and exclude that page from HTTPS! :stuck_out_tongue:

How much memory do I need?
UNO has 2 kB
Mega has 8 kB

Alternative way, You can send HTTPS request from Arduino Uno or Mege use a PHPoC Shield. See this basic example and this project which make request to Google Oauth 2.0 and Google API

WiFiEsp library has connectSSL. it uses the AT firmware for secure TCP

the required keys calculation running on AVR would take more time then a connection timeout

I'll look into using the PHPoC Shield! Did see someone using the NodeMCU! It's sad that the Arduino has so limited use!
Edit: The timeout you see in the Serial Monitor is most likely some wrong code! I just added a fingerprint and the port 443, I have no idea what else needs to be changed, or if I have to add any other library!

if (client.connectSSL(server, 443)) {

Connection failed!

IoT_hobbyist:
Alternative way, You can send HTTPS request from Arduino Uno or Mege use a PHPoC Shield. See this basic example and this project which make request to Google Oauth 2.0 and Google API

a 168 MHz Cortex M4 MCU as shield for Uno? with a price of 80 €?

It costs $59.5 in US