Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include "fauxmoESP.h"
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4); // your I2C address
- #define WIFI_SSID "xxxx" // your wifi ssid
- #define WIFI_PASS "xxxx" //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 callback(uint8_t device_id, const char * device_name, bool state) {
- Serial.print("Device ");
- Serial.print(device_name);
- lcd.setCursor(0, 3);
- lcd.print(" ");
- lcd.setCursor(0, 3);
- lcd.print(device_name);
- lcd.setCursor(8, 3);
- lcd.print(state);
- Serial.print(" state: ");
- if (state) {
- Serial.println("ON");
- } else {
- Serial.println("OFF");
- }
- }
- 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'");
- lcd.init();
- lcd.backlight();
- // Wifi
- wifiSetup();
- // Fauxmo
- fauxmo.addDevice("lights");
- fauxmo.addDevice("fans");
- fauxmo.onMessage(callback);
- }
- void loop() {
- fauxmo.handle();
- }
Add Comment
Please, Sign In to add comment