Pre-Requisite Setup
Before you begin you'll want to make sure your Feather ESP8266 is running properly, you have drivers installed, Arduino IDE etc.
Required Libraries
You'll need a few libraries installed in Arduino to continue. Here's a list of them, install by downloading the linked Zip file, uncompressing and installing in your sketchbook's libraries folder. See our Arduino Libraries Guide for details if you've never installed libraries
Open up the Arduino library manager:
- ESPAsyncTCP library (to download zip click here)
- ESPAsyncUDP library (to download zip click here)
- FauxMoESP library (to download zip click here and then select download repository)
Search for the FauxMoExp library and install it
The rest of the required libraries aren't available on the Arduino library manager. Install these by downloading the linked Zip files, uncompressing them and installing them in your sketchbook's libraries folder. See our Arduino Libraries Guide for details if you've never installed libraries
Install the ESPAsyncTCP library from the link below
Install the ESPAsyncUDP library from the link below
// SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Arduino.h> #include <ESP8266WiFi.h> #include <ESPAsyncTCP.h> #include "fauxmoESP.h" #define WIFI_SSID "YOUR_SSID" #define WIFI_PASS "YOUR_WIFI_PASSWORD" #define SERIAL_BAUDRATE 115200 fauxmoESP fauxmo; // ----------------------------------------------------------------------------- // Wifi // ----------------------------------------------------------------------------- void wifiSetup() { // Set WIFI module to STA mode WiFi.mode(WIFI_STA); // Connect Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASS); // Wait while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(100); } Serial.println(); // Connected! Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str()); } void setup() { // Init serial port and clean garbage Serial.begin(SERIAL_BAUDRATE); Serial.println("FauxMo demo sketch"); Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'"); // Wifi wifiSetup(); // Fauxmo fauxmo.addDevice("relay"); fauxmo.addDevice("pixels"); // Gen3 Devices or above fauxmo.setPort(80); // Allow the FauxMo to be discovered fauxmo.enable(true); fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) { Serial.print("Device: ");Serial.print(device_name); Serial.print(" state"); if(state) { Serial.println("ON!"); } else { Serial.println("off"); } }); } void loop() { fauxmo.handle(); }
Just change
#define WIFI_SSID "..." #define WIFI_PASS "..."
To your SSID & Password for your WiFi network!
Try to compile it (no need to upload yet!)
Compilation Problems?
Please note: as of November 27, 2016 the ESP8266 release core v2.3.0 did not have the right lwip code so there were some compilation issues. If you get a complaint about udp_set_multicast_ttl not being defined, you'll need to uninstall the ESP8266 board support, then manually install the most recent core from https://github.com/esp8266/arduino by following the instructions at https://github.com/esp8266/arduino#using-git-version
Essentially, you'll need to git clone https://github.com/esp8266/Arduino.git
into your Arduino sketchbook folder under hardware/esp8266com/esp8266 and then in a terminal shell in hardware/esp8266com/esp8266/tools run python get.py
Once that's done, go back and test out your ESP8266 to make sure you can compile/upload code to it.
The Alexa app should recognize the new pixels & relay devices as seen above. If it doesn't, try resetting the Feather and running the discovery process again.
Now open up the Arduino IDE serial console at 115200 baud.
Ask your Alexa (or Echo):
"Alexa, turn pixels on"
and
"Alexa, turn pixels off"
You'll see the ESP8266 print out the commands it received!
You can also try it with relay, the second device it is emulating
Now that you have it working you can change the names of the devices. Try to make them things that are easy to pronounce so the Alexa/Echo can understand them when yelled! :)
Text editor powered by tinymce.