### Initialize Espalexa with begin() Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Initializes the Espalexa library. Must be called after adding devices in setup. ```cpp espalexa.begin(); ``` -------------------------------- ### Add device with espalexa.addDevice Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Adds a device in the setup function after WiFi connection. The first parameter is the invocation name, the second is the callback function name. An optional third uint8_t parameter sets the default brightness at boot. ```cpp espalexa.addDevice("Alexa name of the device", firstDeviceChanged); ``` -------------------------------- ### Enable async mode with ESPALEXA_ASYNC Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Add this define before including Espalexa.h to use the library asynchronously with ESPAsyncWebServer. Requires manual installation of ESPAsyncWebServer and its dependencies. ```cpp #define ESPALEXA_ASYNC #include ``` -------------------------------- ### Create and add EspalexaDevice instance Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Creates a new EspalexaDevice with the same parameters as addDevice and adds it to the library. This allows manual value updates. ```cpp d = new EspalexaDevice("Alexa name of the device", firstDeviceChanged); espalexa.addDevice(d); ``` -------------------------------- ### Integrate Espalexa with existing ESP8266WebServer Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Add this handler below your server.on() page definitions when using an existing ESP8266WebServer. It forwards unmatched requests to Espalexa's API handler and returns a 404 if not handled. ```cpp server.onNotFound([](){ if (!espalexa.handleAlexaApiCall(server.uri(),server.arg(0))) { server.send(404, "text/plain", "Not found"); } }); ``` -------------------------------- ### Enable debug output with ESPALEXA_DEBUG Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Add this define before including Espalexa.h to enable debug output to the serial monitor. Useful when troubleshooting device discovery or control issues. ```cpp #define ESPALEXA_DEBUG #include ``` -------------------------------- ### Manipulate EspalexaDevice values Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Shows how to manually set and retrieve device values using the EspalexaDevice pointer. setValue sets the brightness, getValue returns it, and getName returns the device name. ```cpp d->setValue(22); uint8_t bri = d->getValue(); //bri will have the device value String name = d->getName(); //just in case you forget it ``` -------------------------------- ### Set maximum device count with ESPALEXA_MAXDEVICES Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Change the maximum number of virtual devices by defining ESPALEXA_MAXDEVICES before including Espalexa.h. Set it to the exact number of devices to optimize memory usage. ```cpp #define ESPALEXA_MAXDEVICES 20 #include ``` -------------------------------- ### Call espalexa.loop() in main loop Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Processes incoming requests and must be called repeatedly in the loop() function. ```cpp espalexa.loop(); ``` -------------------------------- ### Global Espalexa object and callback prototype Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Declares the Espalexa object and a prototype for the callback function that will be called when a device state changes. This is required before adding devices. ```cpp #include void firstDeviceChanged(uint8_t brightness); Espalexa espalexa; ``` -------------------------------- ### Device callback function for Espalexa Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Defines the callback function that Espalexa calls when a device is changed. The brightness parameter holds the new state: 0 is off, 255 is on, and 1-254 are dimmed values. ```cpp void firstDeviceChanged(uint8_t brightness) { //brightness parameter contains the new device state (0:off,255:on,1-254:dimmed) //do what you'd like to happen here (e.g. control an LED) } ``` -------------------------------- ### Global EspalexaDevice pointer declaration Source: https://github.com/aircoookie/espalexa/blob/main/readme.md Declares a pointer to an EspalexaDevice object in global scope for the advanced device management method. ```cpp EspalexaDevice* d; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.