Old working sketch doesn't compile on ESP32 - Seems to need FreeRTOS

Hi everybody, I'm facing a weird behavior. I've a sketch meant to create a web server on a WEMOS Mini D1 ESP32 and to receive commands from Alexa to turn lights on/off. It was working fine till January last year when the device was shelved . Retrieved yesterday from the shelf, it doesn't work anymore, it connects to the WLAN and that's it. So I've decided to recompile the sketch and reload it on the WEMOS Mini D1 ESP32. To my surprise the compilation fails with four baffling messages concerning FreeRTOS:
#error "include FreeRTOS.h" must appear in source files before "include semphr.h"
#error "include FreeRTOS.h" must appear in source files before "include queue.h"
#error "include FreeRTOS.h must appear in source files before include task.h"
#error "FreeRTOS.h must be included before list.h"
Now, I'm not using FreeRTOS and the errors seem to be related to AsyncTCP and ESPAsyncWebServer.
NOTE : The working sketch was compiled and linked using Arduino IDE 1.8.19, today I use Arduino IDE 2.2.1, always kept up-to-date and to my satisfaction, so far.
Has anybody any idea of what could be the issue here?
Many thanks in advance to whomever will provide any hindsight / help

The IDE version is not really relevant here, the ESP32 core version may have changed some things though.

Without the code ?

what is in list.h ?

#error "FreeRTOS.h must be included before list.h"

As I wrote, I'm not using FreeRTOS at all. I don't have the faintest idea of what is in each of the four .h files mentioned in the error messages and and where they are

So what are you using ? those files must be referenced within something else, quite possibly within the core even (i think hardwareSerial does use FreeRTOS for instance) anyway, regardless you can try and uninstall the current core and roll-back to an earlier version (or even install the current core again) and see if that fixes it.

Guess you are referring to ESP32 core, aren't you?

Done and also reverted back from 2.0.14 to 2.0.9, (2.0.13 to 2.0.10 included) with no success

Where is this sketch??? Did you write it yourself?

So why not go back to 1.18.19 along with the version of the ESP32 core that you used and see if it compiles again? If so, it seems you have a tool chain or core issue with your current setup.

You are using FreeRTOS, even if you don't know it. FreeRTOS is always running the ESP32. With a "traditional" Arduino scketch (setup() + loop() + Arduino Libraries) all the code runs in one FreeRTOS task. However, ESP32-specific libraries may launch other tasks. You are also free create additional tasks under the FreeRTOS framework.

My answers:

  • The sketch is a mix of some pieces of software taken from Randomnerds and some written by myself and it was perfectly fine the last time I used it (Xmas tree lights timer controlled by Alexa)
  • I was thinking of reverting to 1.8.19 but I don't remember which version of ESP32 core I was using and, actually, the sketch was compiled in November 2020. In other words I don't have the faintest idea of which release of 1.19, or 1.18, I was using not to mention the ESP32 core.
  • Quite interesting your info about FreeRTOS, I hope to be able to profit of it, in the future.

Right now I'm stuck

Out of desperation I've also installed the FreeRTOS library, using the IDE, and included it with no success. Whatever include I use: " " or <> , the compiler doesn't find it.

I've stripped the sketch of everything related to the Web serve (ESPAsyncWebServer, AsyncTCP and fauxmoESP), i.e. I just left the WiFi connect, MultiWiFi and WiFi reconnect. It compiles and it runs on the ESP32 without a glitch.

I'm considering to give a try to an old solution based on ESP8266 (replaced by the ESP32 because of better WiFi stability) but it's like to admit defeat ...

Isn't all that relevant, most likely cause is that with the installation of IDE 2.x you also installed a new ESP32 core over the top of an existing installation. (possibly an upgrade from version 1.x.x to 2.x.x ) That may have resulted in some files being incorrectly referenced, even to pre-compiled sections of the core or the libraries having incorrect references.

The recommendation stands. Uninstall the ESP32 core, check the packages folder (on windows, don't know where that is on Mac) to make sure alll files (mainly in the libraries section) have been removed and re-install the ESP32 core, and it may as well be the latest version.

If you want more help, you really need to post the code so we can compile it and verify it is working.
As stated before, the IDE version should not matter much since they will both use the same compiler, but if there are any remnants of a previous installed core somewhere this is most likely to cause issues.

Many thanks. I'll uninstall the ESP32 core and all the ESP32 files I'll find left in the Arduino 15 folder.
If reinstalling ESP32 from scratch it's not going to work I'll post the code.
By the way, I've quickly adapted the code to ESP8266 and it compiles like a charm. Definitely something related to ESP32 core

Only a single core so no FreeRTOS there is there.

Multi-core is not required for FreeRTOS. There are ports of the OS for single-core ARM, etc. Also, there are single-core ESP32 modules that still run FreeRTOS.

Well... Removing the ESP32 core and any related file didn't solve the problem. I got the same four errors related to FreeRTOS. Here is the code. Many thanks for the time you are spending to help me


```cpp
/*
 * Fabrizio M. Bianchi
 * Project for a smart switch derived from
 * 
 * Rui Santos 
 * Complete Project Details http://randomnerdtutorials.com
 * 
 * Created on 11 - 04 - 2021 and derived from the sketch used for ESP8266-01S with the intent of understanding
 * if the erratic behaviour of the ESP8266-01S is due to EM interference from the electric engine or else
 * 5 - 12 - 2021 Update : Added reconnect feature, copied from ESP8266-01S sketch. Robustness to EM interferences still 
 * to be checked but, apparently, only ESP8266 seems to suffer of multiple reset cause by EMI
 *  
 * Fixed IP Address introduced in order to retain association between a device name and
 * the IP address and facilitate distinction between two or more identical devices when connected 
 * to the local WiFi network 
 * 
 * To each device ( 1 x ESP8266-01S and a dual relay board ) must be assigned  a different fixed
 * IP address and different names for the two controlled Output Pins
 * 
 * Next steps : 
 * 
 * Step 1 : Introduce WiFiMulti to allow login into the strongest SSID
 *          DONE on 17 - 03 - 2021 (tested)
 * Step 2 : Introduce fixed IP
 *          DONE on 18 - 03 - 2021
 * Step 3 : Added WiFi.setAutoReconnect(true) and WiFi.persistent(true); to reconnect to WiFi
 *          DONE on 16 - 04 - 2021
 * Step 4 : Added OTA feature 09 - 12 -2021 - Needs to use port 8080 to avoid conflicts with fauxmoESP. Web server works but 
 *          not yet tested for sketch upload
 * 
 * Step 5 : Replaced ESP8266-01 with Mini ESP32 module. Apparently more robust to EMI - Under field test 09 - 12 - 2021
 *          
 * * IP addresses assigned to the five ESP8266-01S (225 used for testing with Mini D1 ESP32 as well) modules:
 * 
 * This specific version of the program is used for commanding the electric roller shutter
 * 
 * 1 = 192.168.1.221   **** ASSIGNED **** (Christmas Tree Lights)
 * 2 = 192.168.1.222   **** ASSIGNED **** (Roller Shutter Studio) This is being used also for the ESP32
 * 3 = 192.168.1.223   **** ASSIGNED **** (Roller Shutter Cucina)
 * 4 = 192.168.1.224
 * 5 = 192.168.1.225   **** USED FOR TESTING (ESP8266 and ESP32)
 * 
 */
#include <AsyncElegantOTA.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

//
// This section is modified for the ESP32 which uses the standard WiFi.h and WiFiMulti.h instead of 
// ESP8266WiFiMulti.h and ESP8266WiFi.h.
 
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <fauxmoESP.h>        //This is a library for ESP8266/ESP32-based devices that emulates Philips Hue devices
                              //Devices can be controlled by Alexa 
                              //After the latest updates to Alexa SW library version 3.3 IS NEEDED.
                              
//Pin assignment (need to check pinout list to verify suitability of pins)

//#define RELAY_PIN_1 12      // Not use with ESP32-WROOM Development  or Mini D1 ESP32-WROOM Module: boot fails if connected high
////#define RELAY_PIN_2 14        // Good for ESP32-WROOM Development or Mini D1 ESP32-WROOM Module - used till 08-12, pin named TMS on PCB
//#define RELAY_PIN_1 32      // Good for ESP32-WROOM Development Module
//#define RELAY_PIN_2 33      // Good for ESP32-WROOM Development Module
////#define RELAY_PIN_1 33        // Good for ESP32-WROOM Development Module / Mini D1 ESP32-WROOM - used till 08-12, pin named IO33 on PCB

// New pins for ease of connection in the current Smart Plug layout (Christmas Tree)  8 - 12 -2021

#define RELAY_PIN_1 16
#define RELAY_PIN_2 17

// Assign a name to each output pin to be used for Alexa Utterance
#define PLUG_1 "Presa Uno"
#define PLUG_2 "Presa Due"                               

// Network login credential multi AP
const char* ssid1 = "***************";
const char* password1 = "*************";
const char* ssid2 = "********";
const char* password2 = "*********";

//Assign fixed IP address

int local_address = 221; // Dual plug for Christmas Tree

// Create an emulation of Philips Hue device

fauxmoESP fauxmo;

// WiFi Multiple AP setup

WiFiMulti wifiMulti;

/* Initiating Web Server   09 - 12 -2021 Pay attention to not conflict with other
 * ports.
 * In this case we need to use port 8080 because port 80 is taken by fauxmo ESP
 */

AsyncWebServer server(8080);

//

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.println('\n');
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid1, password1);
  wifiMulti.addAP(ssid2, password2);

  
// Set your Static IP address
   IPAddress local_IP(192, 168, 1, local_address);
    
// Set your Gateway IP address
    
   IPAddress gateway(192, 168, 1, 1);
   IPAddress subnet(255, 255, 0, 0);
   IPAddress primaryDNS(8, 8, 8, 8);   //optional
   IPAddress secondaryDNS(8, 8, 4, 4); //optional

// Checking static IP address
   if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
       Serial.println("STA Failed to configure");
       delay(500);
   }
// Init serial port and clean garbage
   //Serial.println("Connecting Wifi...");
   while (wifiMulti.run() != WL_CONNECTED) {
     delay(10);
     //Serial.println(".");
   }
// Checking SSID and IP address
    Serial.print('\n');
    Serial.println("WiFi connected to");
    Serial.println(WiFi.SSID());
    Serial.println("IP address:\t ");
    Serial.println(WiFi.localIP());

// Reconnect ESP8266 NodeMCU to Wi-Fi Network After Lost Connection 
    WiFi.setAutoReconnect(true);
    WiFi.persistent(true);

 // Activating Web Server with a simple response to an inquiry 09 - 12 - 2021

 server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });

// End activating Web Server response 09 - 12 -2021

// Begin Starting Elegant OTA  09 - 12 -2021

  AsyncElegantOTA.begin(&server);    // Start ElegantOTA
  server.begin();
//  Serial.println("HTTP server started");

// End Starting Elegant OTA  09 - 12 -2021

// LED or Relays output set up at boot 
// (HIGH = LED ON. For Relay board see below)
  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, HIGH);  //Use for Relays boards with Optocoupler (Relais switches on input LOW)
//digitalWrite(RELAY_PIN_1, LOW); //Use for Relays directly coupled with a transistor as a driver

  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_2, HIGH);  //Use for Relays with Optocoupler (Relais switches on input LOW)
//digitalWrite(RELAY_PIN_2, LOW); //Use for Relays directly coupled with a transistor as a driver

// By default, fauxmoESP creates it's own webserver on the defined port
// The TCP port must be 80 for gen3 devices (default is 1901)
// This has to be done before the call to enable()
  fauxmo.createServer(true); // not needed, this is the default value
  fauxmo.setPort(80); // This is required for gen3 devices

// You have to call enable(true) once you have a WiFi connection
// You can enable or disable the library at any moment
// Disabling it will prevent the devices from being discovered and switched
  fauxmo.enable(true);
// You can use different ways to invoke alexa to modify the devices state:
// "Alexa, accendi albero uno"

// Add virtual devices
  fauxmo.addDevice(PLUG_1);
  fauxmo.addDevice(PLUG_2);

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
// Callback when a command from Alexa is received. 
// You can use device_id or device_name to choose the element to perform an action onto (relay, LED,...)
// State is a boolean (ON/OFF) and value a number from 0 to 255 (if you say "set kitchen light to 50%" you will receive a 128 here).
// Just remember not to delay too much here, this is a callback, exit as soon as possible.
// If you have to do something more involved here set a flag and process it in your main loop.
//  Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
    if ( (strcmp(device_name, PLUG_1) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 1 switched by Alexa");
      //digitalWrite(RELAY_PIN_1, !digitalRead(RELAY_PIN_1));
      if (state) {
        digitalWrite(RELAY_PIN_1, LOW);
        //digitalWrite(RELAY_PIN_1, HIGH); //Use for Relays directly coupled with a transistor as a driver
      } else {     
        digitalWrite(RELAY_PIN_1, HIGH);
        //digitalWrite(RELAY_PIN_1, LOW); //Use for Relays directly coupled with a transistor as a driver
      }
    }
    if ( (strcmp(device_name, PLUG_2) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 2 switched by Alexa");
      if (state) {
        digitalWrite(RELAY_PIN_2, LOW);
        //digitalWrite(RELAY_PIN_2, HIGH); //Use for Relays directly coupled with a transistor as a driver
      } 
      else {
        digitalWrite(RELAY_PIN_2, HIGH);
        //digitalWrite(RELAY_PIN_2, LOW); //Use for Relays directly coupled with a transistor as a driver
      }
    }
  });
}

void loop() {

 // ElegantOTA loop 09 - 12 - 2021

    AsyncElegantOTA.loop();

// End ElegantOTA loop 09 - 12 -2021

// fauxmoESP uses an async TCP server but a sync UDP server
// Therefore, we have to manually poll for UDP packets

    fauxmo.handle();
  
}

Curious, did you try adding what it is asking for??
make your first include..

#include "freertos/FreeRTOS.h"

probably going to be more to fix up..
good luck.. ~q

OK, first of all, editing the sketch for posting it caused me to make some errors. Now the sketch posted should be OK. Adding the #include "freertos/FreeRTOS.h" caused old errors to disappear and the following new ones to show up:
...../libraries/ESPAsyncWebServer/WebAuthentication.cpp.o:(.literal._ZL6getMD5PhtPc+0x4): undefined reference to mbedtls_md5_starts' ...../libraries/ESPAsyncWebServer/WebAuthentication.cpp.o: in function getMD5(unsigned char*, unsigned short, char*)':
/Users/fabriziobianchi/Documents/Arduino/libraries/ESPAsyncWebServer/src/WebAuthentication.cpp:73: undefined reference to `mbedtls_md5_starts'

Seems like your best bet might be to scrap what you have and start over from scratch in your new build environment / ESP32 core. Build the application up piece by piece until it breaks (or not). I've never needed to add #include "freertos/FreeRTOS.h" ... even to code that extensively uses FreeRTOS features.

Here i am doing all the extra work to fix the sketch you posted first.
It was the asyncTCP that was reporting the need for the FreeRTOS.h btw.

But now that i have, this actually compiles, (be it with some warning that the ElegantOTA library is deprecated, but that is just a warning)


/*
   Fabrizio M. Bianchi
   Project for a smart switch derived from

   Rui Santos
   Complete Project Details http://randomnerdtutorials.com

   Created on 11 - 04 - 2021 and derived from the sketch used for ESP8266-01S with the intent of understanding
   if the erratic behaviour of the ESP8266-01S is due to EM interference from the electric engine or else
   5 - 12 - 2021 Update : Added reconnect feature, copied from ESP8266-01S sketch. Robustness to EM interferences still
   to be checked but, apparently, only ESP8266 seems to suffer of multiple reset cause by EMI

   Fixed IP Address introduced in order to retain association between a device name and
   the IP address and facilitate distinction between two or more identical devices when connected
   to the local WiFi network

   To each device ( 1 x ESP8266-01S and a dual relay board ) must be assigned  a different fixed
   IP address and different names for the two controlled Output Pins

   Next steps :

   Step 1 : Introduce WiFiMulti to allow login into the strongest SSID
            DONE on 17 - 03 - 2021 (tested)
   Step 2 : Introduce fixed IP
            DONE on 18 - 03 - 2021
   Step 3 : Added WiFi.setAutoReconnect(true) and WiFi.persistent(true); to reconnect to WiFi
            DONE on 16 - 04 - 2021
   Step 4 : Added OTA feature 09 - 12 -2021 - Needs to use port 8080 to avoid conflicts with fauxmoESP. Web server works but
            not yet tested for sketch upload

   Step 5 : Replaced ESP8266-01 with Mini ESP32 module. Apparently more robust to EMI - Under field test 09 - 12 - 2021

 * * IP addresses assigned to the five ESP8266-01S (225 used for testing with Mini D1 ESP32 as well) modules:

   This specific version of the program is used for commanding the electric roller shutter

   1 = 192.168.1.221   **** ASSIGNED **** (Christmas Tree Lights)
   2 = 192.168.1.222   **** ASSIGNED **** (Roller Shutter Studio) This is being used also for the ESP32
   3 = 192.168.1.223   **** ASSIGNED **** (Roller Shutter Cucina)
   4 = 192.168.1.224
   5 = 192.168.1.225   **** USED FOR TESTING (ESP8266 and ESP32)

*/
#include "freertos/FreeRTOS.h"
#include <AsyncElegantOTA.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

//
// This section is modified for the ESP32 which uses the standard WiFi.h and WiFiMulti.h instead of
// ESP8266WiFiMulti.h and ESP8266WiFi.h.

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <fauxmoESP.h>        //This is a library for ESP8266/ESP32-based devices that emulates Philips Hue devices
//Devices can be controlled by Alexa
//After the latest updates to Alexa SW library version 3.3 IS NEEDED.

//Pin assignment (need to check pinout list to verify suitability of pins)

//#define RELAY_PIN_1 12      // Not use with ESP32-WROOM Development  or Mini D1 ESP32-WROOM Module: boot fails if connected high
////#define RELAY_PIN_2 14        // Good for ESP32-WROOM Development or Mini D1 ESP32-WROOM Module - used till 08-12, pin named TMS on PCB
//#define RELAY_PIN_1 32      // Good for ESP32-WROOM Development Module
//#define RELAY_PIN_2 33      // Good for ESP32-WROOM Development Module
////#define RELAY_PIN_1 33        // Good for ESP32-WROOM Development Module / Mini D1 ESP32-WROOM - used till 08-12, pin named IO33 on PCB

// New pins for ease of connection in the current Smart Plug layout (Christmas Tree)  8 - 12 -2021

#define RELAY_PIN_1 16
#define RELAY_PIN_2 17

// Assign a name to each output pin to be used for Alexa Utterance
#define PLUG_1 "Presa Uno"
#define PLUG_2 "Presa Due"

// Network login credential multi AP
const char* ssid1 = "***************";
const char* password1 = "*************";
const char* ssid2 = "********";
const char* password2 = "*********";

//Assign fixed IP address

int local_address = 221; // Dual plug for Christmas Tree

// Create an emulation of Philips Hue device

fauxmoESP fauxmo;

// WiFi Multiple AP setup

WiFiMulti wifiMulti;

/* Initiating Web Server   09 - 12 -2021 Pay attention to not conflict with other
   ports.
   In this case we need to use port 8080 because port 80 is taken by fauxmo ESP
*/

AsyncWebServer server(8080);

//

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.println('\n');
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid1, password1);
  wifiMulti.addAP(ssid2, password2);


  // Set your Static IP address
  IPAddress local_IP(192, 168, 1, local_address);

  // Set your Gateway IP address

  IPAddress gateway(192, 168, 1, 1);
  IPAddress subnet(255, 255, 0, 0);
  IPAddress primaryDNS(8, 8, 8, 8);   //optional
  IPAddress secondaryDNS(8, 8, 4, 4); //optional

  // Checking static IP address
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
    delay(500);
  }
  // Init serial port and clean garbage
  //Serial.println("Connecting Wifi...");
  while (wifiMulti.run() != WL_CONNECTED) {
    delay(10);
    //Serial.println(".");
  }
  // Checking SSID and IP address
  Serial.print('\n');
  Serial.println("WiFi connected to");
  Serial.println(WiFi.SSID());
  Serial.println("IP address:\t ");
  Serial.println(WiFi.localIP());

  // Reconnect ESP8266 NodeMCU to Wi-Fi Network After Lost Connection
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);

  // Activating Web Server with a simple response to an inquiry 09 - 12 - 2021

  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(200, "text/plain", "Hi! I am ESP32.");
  });

  // End activating Web Server response 09 - 12 -2021

  // Begin Starting Elegant OTA  09 - 12 -2021

  AsyncElegantOTA.begin(&server);    // Start ElegantOTA
  server.begin();
  //  Serial.println("HTTP server started");

  // End Starting Elegant OTA  09 - 12 -2021

  // LED or Relays output set up at boot
  // (HIGH = LED ON. For Relay board see below)
  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, HIGH);  //Use for Relays boards with Optocoupler (Relais switches on input LOW)
  //digitalWrite(RELAY_PIN_1, LOW); //Use for Relays directly coupled with a transistor as a driver

  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_2, HIGH);  //Use for Relays with Optocoupler (Relais switches on input LOW)
  //digitalWrite(RELAY_PIN_2, LOW); //Use for Relays directly coupled with a transistor as a driver

  // By default, fauxmoESP creates it's own webserver on the defined port
  // The TCP port must be 80 for gen3 devices (default is 1901)
  // This has to be done before the call to enable()
  fauxmo.createServer(true); // not needed, this is the default value
  fauxmo.setPort(80); // This is required for gen3 devices

  // You have to call enable(true) once you have a WiFi connection
  // You can enable or disable the library at any moment
  // Disabling it will prevent the devices from being discovered and switched
  fauxmo.enable(true);
  // You can use different ways to invoke alexa to modify the devices state:
  // "Alexa, accendi albero uno"

  // Add virtual devices
  fauxmo.addDevice(PLUG_1);
  fauxmo.addDevice(PLUG_2);

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    // Callback when a command from Alexa is received.
    // You can use device_id or device_name to choose the element to perform an action onto (relay, LED,...)
    // State is a boolean (ON/OFF) and value a number from 0 to 255 (if you say "set kitchen light to 50%" you will receive a 128 here).
    // Just remember not to delay too much here, this is a callback, exit as soon as possible.
    // If you have to do something more involved here set a flag and process it in your main loop.
    //  Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
    if ( (strcmp(device_name, PLUG_1) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 1 switched by Alexa");
      //digitalWrite(RELAY_PIN_1, !digitalRead(RELAY_PIN_1));
      if (state) {
        digitalWrite(RELAY_PIN_1, LOW);
        //digitalWrite(RELAY_PIN_1, HIGH); //Use for Relays directly coupled with a transistor as a driver
      } else {
        digitalWrite(RELAY_PIN_1, HIGH);
        //digitalWrite(RELAY_PIN_1, LOW); //Use for Relays directly coupled with a transistor as a driver
      }
    }
    if ( (strcmp(device_name, PLUG_2) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 2 switched by Alexa");
      if (state) {
        digitalWrite(RELAY_PIN_2, LOW);
        //digitalWrite(RELAY_PIN_2, HIGH); //Use for Relays directly coupled with a transistor as a driver
      }
      else {
        digitalWrite(RELAY_PIN_2, HIGH);
        //digitalWrite(RELAY_PIN_2, LOW); //Use for Relays directly coupled with a transistor as a driver
      }
    }
  });
}

void loop() {

  //    ElegantOTA loop 09 - 12 - 2021

  AsyncElegantOTA.loop();

  // End ElegantOTA loop 09 - 12 -2021

  // fauxmoESP uses an async TCP server but a sync UDP server
  // Therefore, we have to manually poll for UDP packets

  fauxmo.handle();

}

I've opened a new sketch and copied the sketch you so kindly worked on. It doesn't pass compilation. It gives the known warnings about elegantOTA and the same three new errors I reported above

/Users/fabriziobianchi/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /private/var/folders/t3/r4bqgnld4r17zmry7thrv95r0000gn/T/arduino/sketches/55853C99084C06DA2E42B0944BB63AD8/libraries/ESPAsyncWebServer/WebAuthentication.cpp.o:(.literal._ZL6getMD5PhtPc+0x4): undefined reference to `mbedtls_md5_starts'
/Users/fabriziobianchi/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /private/var/folders/t3/r4bqgnld4r17zmry7thrv95r0000gn/T/arduino/sketches/55853C99084C06DA2E42B0944BB63AD8/libraries/ESPAsyncWebServer/WebAuthentication.cpp.o: in function `getMD5(unsigned char*, unsigned short, char*)':
/Users/fabriziobianchi/Documents/Arduino/libraries/ESPAsyncWebServer/src/WebAuthentication.cpp:73: undefined reference to `mbedtls_md5_starts'
collect2: error: ld returned 1 exit status

Now I've a doubt, which board are you using for the compilation ? (assuming that it matters even if the MCU is an ESP32 in both cases. I'm using a WEMOS Mini D1 ESP32

this is what i got after compilation

In file included from C:\Users\deva_\AppData\Local\Temp\arduino_modified_sketch_587511\sketch_dec05b.ino:46:
C:\Data\Arduino\Sketches\libraries\AsyncElegantOTA\src/AsyncElegantOTA.h:4:2: warning: #warning AsyncElegantOTA library is deprecated, Please consider moving to newer ElegantOTA library which now comes with an Async Mode. Learn More: https: [-Wcpp]
 #warning AsyncElegantOTA library is deprecated, Please consider moving to newer ElegantOTA library which now comes with an Async Mode. Learn More: https://docs.elegantota.pro/async-mode/
  ^~~~~~~
In file included from C:\Data\Arduino\Sketches\libraries\AsyncElegantOTA\src\AsyncElegantOTA.cpp:1:
C:\Data\Arduino\Sketches\libraries\AsyncElegantOTA\src/AsyncElegantOTA.h:4:2: warning: #warning AsyncElegantOTA library is deprecated, Please consider moving to newer ElegantOTA library which now comes with an Async Mode. Learn More: https: [-Wcpp]
 #warning AsyncElegantOTA library is deprecated, Please consider moving to newer ElegantOTA library which now comes with an Async Mode. Learn More: https://docs.elegantota.pro/async-mode/
  ^~~~~~~
Sketch uses 848893 bytes (64%) of program storage space. Maximum is 1310720 bytes.
Global variables use 44640 bytes (13%) of dynamic memory, leaving 283040 bytes for local variables. Maximum is 327680 bytes.

I had to install a few of the libraries used, which does mean i got the newest versions.

That is just 1 error !
Something about the MD5 authentication.
try updating the AsyncWebserver library.

edit, v1.0.1 was release 2 weeks ago