Advertisement
babyyoda_

Sinric

May 8th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef ENABLE_DEBUG
  2.        #define DEBUG_ESP_PORT Serial
  3.        #define NODEBUG_WEBSOCKETS
  4.        #define NDEBUG
  5. #endif
  6.  
  7. #include <Arduino.h>
  8. #ifdef ESP8266
  9.        #include <ESP8266WiFi.h>
  10. #endif
  11. #ifdef ESP32  
  12.        #include <WiFi.h>
  13. #endif
  14.  
  15. #include "SinricPro.h"
  16. #include "SinricProSwitch.h"
  17.  
  18. #define WIFI_SSID         ""    
  19. #define WIFI_PASS         ""
  20. #define APP_KEY           ""      // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
  21. #define APP_SECRET        ""   // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
  22. #define SWITCH_ID         ""    // Should look like "5dc1564130xxxxxxxxxxxxxx"
  23. #define BAUD_RATE         9600                // Change baudrate to your need
  24.  
  25. #define RELAY_PIN         13                  // Pin where the relay is connected (D5 = GPIO 14 on ESP8266)
  26.  
  27. bool onPowerState(const String &deviceId, bool &state) {
  28.   digitalWrite(RELAY_PIN, state);             // set pin state
  29.   return true;                                // request handled properly
  30. }
  31.  
  32. void setup() {
  33.   pinMode(RELAY_PIN, OUTPUT);                 // set relay-pin to output mode
  34.   WiFi.begin(WIFI_SSID, WIFI_PASS);           // start wifi
  35.  
  36.   SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];   // create new switch device
  37.   mySwitch.onPowerState(onPowerState);                // apply onPowerState callback
  38.   SinricPro.begin(APP_KEY, APP_SECRET);               // start SinricPro
  39. }
  40.  
  41. void loop() {
  42.   SinricPro.handle();                         // handle SinricPro commands
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement