Closed Dom2955774 closed 3 years ago
bool onLockState(String deviceId, bool &lockState) {
if (lockState == false) {
digitalWrite(relay,HIGH);
Serial.println("Lock is unlocked");
delay(3000);
digitalWrite(relay,LOW);
Serial.println("Lock is locked again");
lockState = true; // <-- let the server know that the lock is locked again
}
return true;
}
100% thank you so much Savir2311
hi, when i press unlock on sinric pro my relay switches for 3 seconds and then goes back to a locked state, the problem im having is that sinric pro stays on the unlocked state. when i press the unlock button on sinric pro i need sinric pro to go back to the locked state after. here is my code
define ENABLE_DEBUG
ifdef ENABLE_DEBUG
endif
include
ifdef ESP8266
endif
ifdef ESP32
endif
include "SinricPro.h"
include "SinricProLock.h"
define WIFI_SSID ""
define WIFI_PASS ""
define APP_KEY ""
define APP_SECRET ""
define LOCK_ID ""
define BAUD_RATE 115200
define relay D7
bool onLockState(String deviceId, bool &lockState) { if (lockState == false) { digitalWrite(relay,HIGH); delay(3000); digitalWrite(relay,LOW); } Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState?"locked":"unlocked"); return true; }
void setupWiFi() { Serial.printf("\r\n[Wifi]: Connecting"); WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) { Serial.printf("."); delay(250); } IPAddress localIP = WiFi.localIP(); Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]); }
void setupSinricPro() { SinricProLock &myLock = SinricPro[LOCK_ID]; myLock.onLockState(onLockState);
// setup SinricPro SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); }); SinricPro.begin(APP_KEY, APP_SECRET); }
void setup() { pinMode(relay, OUTPUT); Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); setupWiFi(); setupSinricPro(); }
void loop() { SinricPro.handle(); }