cannot run HTTPS server when Secure MQTT is running on ESP8266

Hello all,
when I run secure MQTT on an ESP8266 HTTPS doesn’t respond to any request. the problem has the following symptoms:

  • when running HTTPS without MQTT or when closing the MQTT connection using client.stop(); https works fine.

  • when connecting to non secure MQTT (port 1883) HTTPS works fine.

  • while connected to secure MQTT (port 8883) HTTPS doesn’t answer any requests

here is my code:

#include <ESP8266WiFi.h>
#include <rgb_lcd.h>            // include the grove RGB LCD library
#include <ESP8266WebServerSecure.h>
#include <ESP8266mDNS.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

...
...

BearSSL::WiFiClientSecure client;  

BearSSL::ESP8266WebServerSecure server(443);

Adafruit_MQTT_Client MQTT(&client, ADASERVER, ADAPORT, ADAUSERNAME, ADAKEY);

...
...

void setup() {

...
...

  client.setFingerprint( fingerprint );
  MQTT.subscribe( &MQTT_FEED);    
  server.getServer().setRSACert( new BearSSL::X509List( cert ), new BearSSL::PrivateKey( key ) );
  server.on("/", respond );
  server.onNotFound( respond );
  server.begin();    
  mqttConnect();              


}

void loop() {

  // static Variables to store the time of each task's last call
  static unsigned long CFF_LC = 0,    
                       LCD_LC = 0,    // time of lcdUpdate last call
                       SHR_LC = 0,    // time of shareReadings last call
                       TASK4LC = 0;

  static unsigned long currentMillis;   // store current time in milli seconds
  static unsigned long currentSeconds;  // store current time in seconds

  currentMillis = millis();               
  currentSeconds = currentMillis / 1000 + 1;    // added + 1 so currentSeconds is never 0, to avoid division by 0
   
  MDNS.update();
//###########################################
  server.handleClient();  ///###########//// doesn't work unless I do clinet.stop();
//###########################################

  if ( currentMillis - CFF_LC >= CFF_INT ) {
    CFF_LC = currentMillis ;                
    countPress();
  }

  // execute lcdUpdate when the time passed is more than the countFootfall interval
  if ( currentMillis - LCD_LC >= LCD_INT ) {
    LCD_LC = currentMillis ;                // lcdUpdate last call = now
    float currentMinutes = currentSeconds / 60.0;
    averagePress = totalPress / currentMinutes;
    mqttSubscribeToFeeds();
    lcdUpdate();
  }

  if ( currentMillis - SHR_LC >= SHR_INT ) {
    SHR_LC = currentMillis;
    mqttConnect();
    shareReadings();
  }

Please any ideas on why this is happening and how to solve the problem ?

Do you know whether this is supposed to work? Maybe the library uses some data structure that is only instantiated once but would be needed twice. I found a page where it was stated that the ESP8266 has no special cryptography hardware. Maybe there are limitation for the implementation on the ESP8266. Just a guess, since it sounds like you go the protocols running independently.

@zoxerus, I have run into the same issue. I think that @Klaus_K is likely correct that there is something common that is causing the issue. That said, I am still interested in what that might be.

My project has the need to both communicate to MQTT (securely) and be able to respond to HTTPS requests.

@zoxerus, you seem to be a few months ahead of me on this issue, did you happen to make any progress? A work around or maybe just a deeper understanding of the issue?

If anyone has any advice on where I could start to dig for a better understanding, that would be appreciated as well.

Hi, unfortunately I couldn't come up with a solution, I even tried to trace the issue inside the library but it was too much work to do

I was doing this project for a University course and after discussing the issue with my teacher he suggested me to use HTTP for one application and HTTPS for the other.