Comments (14)
What exact is the issue?
I don't see any servo related code.
from esp8266-esp32-sdk.
I tried adding servo related code but it didn't work.
I am new to using Arduino so can you please help me to add the servo code to it
from esp8266-esp32-sdk.
I suggest first to finish your servo code without SinricPro.
If you got it running, implement SinricPro.
from esp8266-esp32-sdk.
That is very good advice. Implement using a button or even just an on/off loop using standard servo library code. When you figure out how to do it, then copy the servo code into the onLockState function in the code you supplied. When you get an "open", rotate your servo in one direction. When you get a "close" rotate it in the other direction. But I think you're apt to have a problem, as at power off, the servo could return to 0 deg. That could open your door lock. But I have no idea how you've set up your hardware.
from esp8266-esp32-sdk.
I think you going to need a reed switch to check the status of the door
https://www.sparkfun.com/products/13247
from esp8266-esp32-sdk.
i am aware of the reed switch,thanks @kakopappa .
Also thanks for your advice @khorner116 , will try to implement and will share the update of it.
from esp8266-esp32-sdk.
Hello, @khorner116 , with your advice I have try to update the code made by @kakopappa, but I am having some issues with it, after Unlocking the door, it cannot be locked again by pressing the Lock button and also just after pressing the unlock button, it get disconnects from Sinric server after some amount of time, can you help me to overcome this issue.
''
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProLock.h"
#define WIFI_SSID "Mitali"
#define WIFI_PASS "mitalibakliwal"
#define APP_KEY "0xxxxxc-xxxx-4500-xxxx-954xxxxxx40a"
#define APP_SECRET "6exxxx5f-xxxx-48f9-86aa-4f73bff23861-xxxxxxxx-2738-xxxx-9940-3e47xxxxxxf0"
#define LOCK_ID "5e6e0exxxxxxx22d498dd56b76"
#define BAUD_RATE 9600
#include <Servo.h>
#define LOCK_PIN D4// PIN where the lock is connected to: HIGH = locked, LOW = unlocked
#define LOCK_STATE_PIN D2 // PIN where the lock feedback is connected to (HIGH:locked, LOW:unlocked)
Servo myservo;
bool lastLockState;
bool onLockState(String deviceId, bool lockState) {
int pos;
for (pos = 0; pos <= 180;) // goes from 0 degrees to 180 degrees
{
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(0); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0;) // goes from 180 degrees to 0 degrees
{
myservo.write(90); // tell servo to go to position in variable 'pos'
delay(0); // waits 15ms for the servo to reach the position
}
Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState?"locked":"unlocked");
digitalWrite(LOCK_PIN, lockState);
return true;
}
void checkLockState() {
bool currentLockState = digitalRead(LOCK_STATE_PIN); // get current lock state
if (currentLockState == lastLockState) return; // do nothing if state didn't changed
Serial.printf("Lock has been %s manually\r\n", currentLockState?"locked":"unlocked"); // print current lock state to serial
lastLockState = currentLockState; // update last known lock state
SinricProLock &myLock = SinricPro[LOCK_ID]; // get the LockDevice
myLock.sendLockStateEvent(currentLockState); // update LockState on Server
}
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() {
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() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
pinMode(LOCK_PIN, OUTPUT);
pinMode(LOCK_STATE_PIN, INPUT);
setupWiFi();
setupSinricPro();
myservo.attach(D4);
}
void loop() {
SinricPro.handle();
checkLockState();
}
''
from esp8266-esp32-sdk.
Remove the for loops... They do nothing except blocking the complete code. Thats why after unlocking nothing is working anymore. Only the delay keeps the ESP from crashing.
Just do a simple myServo.write depending to the lockState.
I cant deliver complete code right now because i am on my Mobile Phone right now.
from esp8266-esp32-sdk.
#define POSITION_LOCK 0 // define servo lock position
#define POSITION_UNLOCK 90 // define servo unlock position
bool onLockState(const String &deviceId, bool &lockState){
myServo.write(lockState?POSITION_LOCK:POSITION_UNLOCK);
Serial.printf("Device %s is %s\r\n", deviceId.c_str(), lockState ? "locked" : "unlocked");
lastLockState = lockState;
return true;
}
-
deviceId is
const String&
! -
lockState is
bool&
! -
myServo.write(lockState?POSITION_LOCK:POSITION_UNLOCK);
is the same as:
if (lockState == true) {
myServo.write(POSITION_LOCK);
} else {
myServo.write(POSITION_UNLOCK);
}
from esp8266-esp32-sdk.
Thanks @sivar2311, your code helped me to overcome several issues.
Now the Lock gets Locked and Unlocked withot crashing, but I am facing a issue in the Sinric Pro app, when I press Unlock the device gets unlocked but the system shows that its still locked. Can you help me that what I am missing out?
''
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProLock.h"
#include <Servo.h>
#define WIFI_SSID "Mitali"
#define WIFI_PASS "mitalibakliwal"
#define APP_KEY "01b92a6c-ead4-4500-bf5d-9543867f840a"
#define APP_SECRET "6e892e5f-df0a-48f9-86aa-4f73bff23861-52ce696e-2738-4251-9940-3e47bca923f0"
#define LOCK_ID "5e6e0e2586622d498dd56b76"
#define BAUD_RATE 9600
#define LOCK_PIN D4// PIN where the lock is connected to: HIGH = locked, LOW = unlocked
#define LOCK_STATE_PIN D2 // PIN where the lock feedback is connected to (HIGH:locked, LOW:unlocked)
#define POSITION_LOCK 90 // define servo lock position
#define POSITION_UNLOCK 0 // define servo unlock position
Servo myservo;
bool lastLockState;
bool onLockState(const String &deviceId, bool &LockState){
if (LockState == true) {
myservo.write(POSITION_LOCK);
} else {
myservo.write(POSITION_UNLOCK);
}
Serial.printf("Lock has been %s manually\r\n", LockState?"locked":"unlocked");
lastLockState = LockState;
return true;
}
void checkLockState() {
bool currentLockState = digitalRead(LOCK_STATE_PIN); // get current lock state
if (currentLockState == lastLockState) return; // do nothing if state didn't changed
Serial.printf("Lock has been %s manually\r\n", currentLockState?"locked":"unlocked"); // print current lock state to serial
lastLockState = currentLockState; // update last known lock state
SinricProLock &myLock = SinricPro[LOCK_ID]; // get the LockDevice
myLock.sendLockStateEvent(currentLockState); // update LockState on Server
}
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() {
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() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
pinMode(LOCK_PIN, OUTPUT);
pinMode(LOCK_STATE_PIN, INPUT);
setupWiFi();
setupSinricPro();
myservo.attach(D4);
}
void loop() {
SinricPro.handle();
checkLockState();
}
''
from esp8266-esp32-sdk.
Please check if this issue happens to Dashboard and AlexaApp too. Or is it just SinricPro-App?
from esp8266-esp32-sdk.
It happens with the Dashboard too.
I haven't checked it with the Alexa yet but will let you know.
from esp8266-esp32-sdk.
Your code makes use of checkLockState() which reads the current lockstate back from pin D2.
Is there anything connected to D2 which returns the current lock state?
Otherwise you have to remove this code.
from esp8266-esp32-sdk.
Yes, you were right. Thanks for your help.
Also thanks to all of you.
from esp8266-esp32-sdk.
Related Issues (20)
- SinricPro sketch problem with Arduino Uno R4 HOT 2
- Problem with SinricPro on ESP8266 HOT 18
- Device did not handle set power state. HOT 10
- 5050 led Strip Sinric Pro with Google Home onPowerState not responding and onColour strangely white HOT 3
- Dimmer switch not working HOT 18
- Relay status not syncing correctly with Sinric Pro dashboard HOT 5
- for multi switches and dimmer with pwm and zero crossing HOT 2
- esp8266 after upload the code issue 365 HOT 1
- Connection HOT 13
- sha1 conflict with rweather/Crypto@^0.4.0 Library in PIO. HOT 2
- Relay status at startup HOT 7
- Capacitive Soil Moisture Sensor data not Reaching Alexa HOT 7
- device turns off for on and on for off what changes should i make in the onPowerstate HOT 2
- Device shows as unresponsive in App and Dashboard after router IP rotation, but is actually responsive HOT 6
- Sin ric pro How do I "mirror" WS2812b led strips with ESP32 HOT 2
- Sinric pro.h HOT 3
- garage status HOT 40
- Emulating a momentary switch with Sinric Pro HOT 2
- I'm stuck coding for multiple devices. (ESP8266) HOT 10
- missing capability on AC Unit HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp8266-esp32-sdk.