[Alexa integration]error: 'fauxmo' does not name a type

Dear community,

I have successfully build a 4 temperature sensor using an ESP8266 including an OLED and upload of the measurements to thingspeak.

Now I would like to include Alexa controls. Do I have included the following libraries as described in many tutorials:

#include <AsyncPrinter.h>
#include <async_config.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncTCPbuffer.h>
#include <SyncClient.h>
#include <tcp_axtls.h>

#include <fauxmoESP.h>

Defined the following:

#define ID_OLED           "OLED Display"
fauxmoESP fauxmo;

and then the following setup for the Alexa control:

//Setup Alexa control
//------------------------------------------
void FauxMoSetup(){ 
  // 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);
  // Add virtual devices
  fauxmo.addDevice(ID_OLED);
}

 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, ID_OLED) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("OLED display switched by Alexa");
  
      if (state) {
        displayState = true; //Flag to switch on the display in the Mainloop
      } else {
        displayState = false; //Flag to switch off the display in the Mainloop
      }
    }
    
  });

I get the following error message when compiling:

HTTP_DS18B20:279:2: error: 'fauxmo' does not name a type

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {

  ^

HTTP_DS18B20:298:4: error: expected unqualified-id before ')' token

   });

    ^

exit status 1
'fauxmo' does not name a type

Can anyone point me in the right direction on how to resolve this issue?

Thanks a lot in advance!

The fauxmo.onSetState call is executable code, but you've put it outside of any function.

Move it up into FauxMoSetup.

You were right, of course. It solved the issue, thank you!