Advertisement
Guest User

esp8266 home automation

a guest
Dec 27th, 2017
5,803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <ESP8266WiFi.h>
  3. #include "fauxmoESP.h"
  4.  
  5. #define WIFI_SSID "ATT6s3ENT4"
  6. #define WIFI_PASS "69z5f2s4+e4p"
  7. #define SERIAL_BAUDRATE                 115200
  8.  
  9. fauxmoESP fauxmo;
  10.  
  11. // -----------------------------------------------------------------------------
  12. // Wifi
  13. // -----------------------------------------------------------------------------
  14.  
  15. void wifiSetup() {
  16.  
  17.     // Set WIFI module to STA mode
  18.     WiFi.mode(WIFI_STA);
  19.  
  20.     // Connect
  21.     Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  22.     WiFi.begin(WIFI_SSID, WIFI_PASS);
  23.  
  24.     // Wait
  25.     while (WiFi.status() != WL_CONNECTED) {
  26.         Serial.print(".");
  27.         delay(100);
  28.     }
  29.     Serial.println();
  30.  
  31.     // Connected!
  32.     Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
  33. }
  34.  
  35. void callback(uint8_t device_id, const char * device_name, bool state) {
  36.   Serial.print("Device "); Serial.print(device_name);
  37.   Serial.print(" state: ");
  38.   if (state) {
  39.     Serial.println("ON");
  40.   } else {
  41.     Serial.println("OFF");
  42.   }
  43. }
  44.  
  45. void setup() {
  46.     // Init serial port and clean garbage
  47.     Serial.begin(SERIAL_BAUDRATE);
  48.     Serial.println("FauxMo demo sketch");
  49.     Serial.println("After connection, ask Alexa/Echo to 'turn <devicename> on' or 'off'");
  50.  
  51.     // Wifi
  52.     wifiSetup();
  53.  
  54.     // Fauxmo
  55.     fauxmo.addDevice("Fish Tank");
  56.     //fauxmo.addDevice("pixels");
  57.     fauxmo.onMessage(callback);
  58. }
  59.  
  60. void loop() {
  61.   fauxmo.handle();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement