sspence65

Alexa ESP8266 LCD

Mar 31st, 2018
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <ESP8266WiFi.h>
  3. #include "fauxmoESP.h"
  4. #include <LiquidCrystal_I2C.h>
  5. LiquidCrystal_I2C lcd(0x27,20,4); // your I2C address
  6.  
  7. #define WIFI_SSID "xxxx" // your wifi ssid
  8. #define WIFI_PASS "xxxx" //your wifi password
  9. #define SERIAL_BAUDRATE 115200
  10.  
  11. fauxmoESP fauxmo;
  12.  
  13. // -----------------------------------------------------------------------------
  14. // Wifi
  15. // -----------------------------------------------------------------------------
  16.  
  17. void wifiSetup() {
  18.  
  19. // Set WIFI module to STA mode
  20. WiFi.mode(WIFI_STA);
  21.  
  22. // Connect
  23. Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  24. WiFi.begin(WIFI_SSID, WIFI_PASS);
  25.  
  26. // Wait
  27. while (WiFi.status() != WL_CONNECTED) {
  28. Serial.print(".");
  29. delay(100);
  30. }
  31. Serial.println();
  32.  
  33. // Connected!
  34. Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
  35. }
  36.  
  37. void callback(uint8_t device_id, const char * device_name, bool state) {
  38. Serial.print("Device ");
  39. Serial.print(device_name);
  40. lcd.setCursor(0, 3);
  41. lcd.print(" ");
  42. lcd.setCursor(0, 3);
  43. lcd.print(device_name);
  44.  
  45. lcd.setCursor(8, 3);
  46. lcd.print(state);
  47.  
  48.  
  49. Serial.print(" state: ");
  50. if (state) {
  51. Serial.println("ON");
  52.  
  53. } else {
  54. Serial.println("OFF");
  55.  
  56. }
  57. }
  58.  
  59. void setup() {
  60. // Init serial port and clean garbage
  61. Serial.begin(SERIAL_BAUDRATE);
  62. Serial.println("FauxMo demo sketch");
  63. Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'");
  64.  
  65.  
  66. lcd.init();
  67. lcd.backlight();
  68.  
  69.  
  70.  
  71. // Wifi
  72. wifiSetup();
  73.  
  74. // Fauxmo
  75. fauxmo.addDevice("lights");
  76. fauxmo.addDevice("fans");
  77. fauxmo.onMessage(callback);
  78. }
  79.  
  80. void loop() {
  81. fauxmo.handle();
  82. }
Add Comment
Please, Sign In to add comment