Created
November 11, 2020 20:37
-
-
Save sivar2311/6955526793ad6f2181bf37a058351924 to your computer and use it in GitHub Desktop.
Very basic relay control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SinricPro.h" | |
#include "SinricProSwitch.h" | |
#define WIFI_SSID "YOUR-WIFI-SSID" | |
#define WIFI_PASS "YOUR-WIFI-PASS" | |
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" | |
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" | |
#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx" | |
#define BAUD_RATE 9600 // Change baudrate to your need | |
#define RELAY_PIN D5 // pin where Relay is connected to | |
bool onPowerState(const String &deviceId, bool &state) { | |
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off"); | |
digitalWrite(RELAY_PIN, state); | |
return true; // request handled properly | |
} | |
void setupWiFi() { | |
Serial.printf("\r\n[Wifi]: Connecting"); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.printf("."); | |
delay(250); | |
} | |
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str()); | |
} | |
void setupSinricPro() { | |
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID]; | |
mySwitch.onPowerState(onPowerState); | |
SinricPro.begin(APP_KEY, APP_SECRET); | |
} | |
void setup() { | |
pinMode(RELAY_PIN, OUTPUT); // define LED GPIO as output | |
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); | |
setupWiFi(); | |
setupSinricPro(); | |
} | |
void loop() { | |
SinricPro.handle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment