Comments (40)
Hi @Neu59 !
You can use sendDoorStateEvent
to send the current state or update the state on the server.
from esp8266-esp32-sdk.
Thanks for answering, I use this line to send the status of the door but it gives me an error when compiling.
SinricPro.sendDoorStateEvent(GARAGEDOOR_ID_2, true);
'class SINRICPRO_3_0_1::SinricProClass' has no member named 'sendEvent'; did you mean 'sendQueue'?
from esp8266-esp32-sdk.
Unfortunately, this is wrong.
SinricPro
object does not have such a function, but SinricProGarageDoor
has!
// get GarageDoor object
SinricProGarageDoor& myGarageDoor = SinricPro[GARAGEDOOR_ID_2];
// send event
myGarageDoor.sendDoorStateEvent(true);
from esp8266-esp32-sdk.
Thanks friend for the help but I continue with the compilation problem.
'class SINRICPRO_3_0_1::SinricProClass::Proxy' has no member named 'sendDoorStateEvent'
SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(false);
from esp8266-esp32-sdk.
#include <Arduino.h>
#include <WiFiManager.h>
#include "SinricPro.h"
#include "SinricProGarageDoor.h"
#define APP_KEY "xxxxxxxxxxxxxxxxxxxxxxxxx0"
#define APP_SECRET "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxee-48e7-860b-7df34825a937"
#define BAUD_RATE 115200
const int GARAGE_DOOR_PIN_1 = 22;
const int GARAGE_DOOR_PIN_2 = 23;
const char* GARAGEDOOR_ID_1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char* GARAGEDOOR_ID_2 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
bool doorState = false;
unsigned long lastOpenTime = 0;
const unsigned long doorCloseDelay = 20000; // 20 seconds delay before closing the door
bool onDoorState(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor %s is %s now.\r\n", deviceId.c_str(), doorState?"closed":"open");
if (deviceId == GARAGEDOOR_ID_1) {
digitalWrite(GARAGE_DOOR_PIN_1, LOW); // Activa el relé
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Desactiva el relé
} else if (deviceId == GARAGEDOOR_ID_2) {
digitalWrite(GARAGE_DOOR_PIN_2, LOW); // Activa el relé
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Desactiva el relé
}
// Send the event to the Sinric Pro server to update the status of the door
if (doorState) {
// Si la puerta está cerrada, enviar evento de puerta abierta
SinricPro[GARAGEDOOR_ID_1].sendDoorStateEvent(true);
SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(true);
} else {
// Si la puerta está abierta, enviar evento de puerta cerrada
SinricPro[GARAGEDOOR_ID_1].sendDoorStateEvent(false);
SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(false);
}
return true;
}
void setupSinricPro() {
SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID_1];
myGarageDoor1.onDoorState(onDoorState);
SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID_2];
myGarageDoor2.onDoorState(onDoorState);
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");
WiFiManager wifiManager;
wifiManager.autoConnect("GarageDoorAP");
pinMode(GARAGE_DOOR_PIN_1, OUTPUT);
pinMode(GARAGE_DOOR_PIN_2, OUTPUT);
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Set initial state to off
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Set initial state to off
setupSinricPro();
}
void loop() {
SinricPro.handle();
if (doorState && (millis() - lastOpenTime >= doorCloseDelay)) {
// If the door was opened and it's been more than 20 seconds, close the door
doorState = false;
Serial.println("Closing garage door...");
// You can add your code here to trigger the event to close the door in the Sinric Pro app
// SinricPro[GARAGEDOOR_ID_1].sendDoorStateEvent(false);
// SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(false);
}
}
error when compiling
'class SINRIC PRO_3_0_1::Sinric Pro Class::Proxy' has no member named 'sendDoorStateEvent'
from esp8266-esp32-sdk.
I just want the open door indicators in the application to show a closed door again after 20 seconds after opening.
from esp8266-esp32-sdk.
let me check
from esp8266-esp32-sdk.
if (doorState) {
// Si la puerta está cerrada, enviar evento de puerta abierta
SinricPro[GARAGEDOOR_ID_1].sendDoorStateEvent(true);
SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(true);
} else {
// Si la puerta está abierta, enviar evento de puerta cerrada
SinricPro[GARAGEDOOR_ID_1].sendDoorStateEvent(false);
SinricPro[GARAGEDOOR_ID_2].sendDoorStateEvent(false);
}
This code is wrong and makes no sense inside the onDoorState callback.
Please remove this.
I don't understand your setup and what you want to acheive.
- Two garagedoors with the same state?
Please explain your setup in detail and what you're trying to acheive.
I'm off for now and will answer to your reply in about two hours.
from esp8266-esp32-sdk.
// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif
#include <WiFiManager.h> // Include the library
#include "SinricPro.h"
#include "SinricProGarageDoor.h"
#include <SimpleTimer.h>
#define APP_KEY "xxxxxxxxxxxxxxxxxxx-f6be5a8e2f40" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "xxxxxxxxxxxxxxxxxx-9e514e9b7f21-eec12790-4aee-48e7-860b-7df34825a937" // Should look like "
#define BAUD_RATE 115200 // Change baudrate to your need
SimpleTimer timer;
bool paso1 = true;
bool paso2 = true;
const int GARAGE_DOOR_PIN_1 = 22;
const int GARAGE_DOOR_PIN_2 = 23;
const char* GARAGEDOOR_ID_1 = "xxxxxxxxxxxxxxxxxxxxxx32"; // Should look like "5dc1564130xxxxxxxxxxxxxx"
const char* GARAGEDOOR_ID_2 = "xxxxxxxxxxxxxxxxxxxxf537ddf"; // Should look like "5dc1564130xxxxxxxxxxxxxx"
int Segundos;
int Segundos2;
bool onDoorState(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor %s is %s now.\r\n", deviceId.c_str(), doorState?"closed":"open");
if (deviceId == GARAGEDOOR_ID_1) {
digitalWrite(GARAGE_DOOR_PIN_1, LOW); // Activa el relé
paso1 = false;
Segundos = 0;
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Desactiva el relé
} else if (deviceId == GARAGEDOOR_ID_2) {
digitalWrite(GARAGE_DOOR_PIN_2, LOW); // Activa el relé
paso2 = false;
Segundos2 = 0;
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Desactiva el relé
}
return true;
}
void setupSinricPro() {
SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID_1];
myGarageDoor1.onDoorState(onDoorState);
SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID_2];
myGarageDoor2.onDoorState(onDoorState);
// 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);
Segundos ++;
Segundos2 ++;
if(Segundos >= 20 && paso1 == false)
{
Serial.println("envio estado P11111111111111111");
myGarageDoor1.sendDoorStateEvent(true);
paso1 = true;
}
if(Segundos2 >= 20 && paso2 == false)
{
Serial.println("envio estado P222222222222222222");
myGarageDoor2.sendDoorStateEvent(true);
paso2 = true;
}
if(Segundos >=25)
{
Segundos = 0;
}
if(Segundos2 >=25)
{
Segundos2 = 0;
}
}
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
WiFiManager wifiManager; // Create an instance of WiFiManager
wifiManager.autoConnect("GarageDoorAP"); // Start WiFiManager
pinMode(GARAGE_DOOR_PIN_1, OUTPUT);
pinMode(GARAGE_DOOR_PIN_2, OUTPUT);
// Invert logic for relay control
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Set initial state to off
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Set initial state to off
timer.setInterval(1000, setupSinricPro);
}
void loop() {
SinricPro.handle();
timer.run();
}
Thanks friend for your information, I solved it that way
my goal was. After pressing open in the app, it went back to closed after 20 seconds and it worked fine.
from esp8266-esp32-sdk.
Ok, I think I begin understand what you want to acheive and your approach looks promising.
But don't do this in setupSinricPro!
Write an extra function for this and call it in setIntervall
!
Otherwise SinricPro.begin()
is called everytime the timer fires! -> not good.
from esp8266-esp32-sdk.
// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif
#include <WiFiManager.h> // Include the library
#include "SinricPro.h"
#include "SinricProGarageDoor.h"
#include <SimpleTimer.h>
#define APP_KEY "d0465cxxxxxxxxxxxxxxxx" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // Should look like
"5f36xxxxxxxxxxxxxxxxxx-333d65xxxxxx"
#define BAUD_RATE 115200 // Change baudrate to your need
SimpleTimer timer;
WiFiManager wifiManager;
bool paso1 = true;
bool paso2 = true;
const int GARAGE_DOOR_PIN_1 = 22;
const int GARAGE_DOOR_PIN_2 = 23;
const int RESET = 21;
const char* GARAGEDOOR_ID_1 = "6xxxxxxxxxxxxxxxxxxxxxxxx"; // Should look like "5dc1564130xxxxxxxxxxxxxx"
const char* GARAGEDOOR_ID_2 = "6xxxxxxxxxxxxxxxxxxxxxxx"; // Should look like "5dc1564130xxxxxxxxxxxxxx"
int Segundos;
int Segundos2;
bool onDoorState(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor %s is %s now.\r\n", deviceId.c_str(), doorState?"closed":"open");
if (deviceId == GARAGEDOOR_ID_1) {
digitalWrite(GARAGE_DOOR_PIN_1, LOW); // Activa el relé
paso1 = false;
Segundos = 0;
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Desactiva el relé
} else if (deviceId == GARAGEDOOR_ID_2) {
digitalWrite(GARAGE_DOOR_PIN_2, LOW); // Activa el relé
paso2 = false;
Segundos2 = 0;
delay(500); // Espera 0.5 segundos
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Desactiva el relé
}
return true;
}
void setupSinricPro() {
// 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 SetInterval()
{
SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID_1];
myGarageDoor1.onDoorState(onDoorState);
SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID_2];
myGarageDoor2.onDoorState(onDoorState);
Segundos ++;
Segundos2 ++;
if(Segundos >= 20 && paso1 == false)
{
Serial.println("envio estado P11111111111111111");
myGarageDoor1.sendDoorStateEvent(true);
paso1 = true;
}
if(Segundos2 >= 20 && paso2 == false)
{
Serial.println("envio estado P222222222222222222");
myGarageDoor2.sendDoorStateEvent(true);
paso2 = true;
}
if(Segundos >=25)
{
Segundos = 0;
}
if(Segundos2 >=25)
{
Segundos2 = 0;
}
}
void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
// WiFiManager wifiManager; // Create an instance of WiFiManager
wifiManager.autoConnect("GarageDoorAP"); // Start WiFiManager
pinMode(GARAGE_DOOR_PIN_1, OUTPUT);
pinMode(GARAGE_DOOR_PIN_2, OUTPUT);
pinMode(RESET, INPUT_PULLUP);
// Invert logic for relay control
digitalWrite(GARAGE_DOOR_PIN_1, HIGH); // Set initial state to off
digitalWrite(GARAGE_DOOR_PIN_2, HIGH); // Set initial state to off
setupSinricPro ();
timer.setInterval(1000, SetInterval);
}
void loop() {
SinricPro.handle();
timer.run();
if(digitalRead(RESET) == LOW)
{
wifiManager.resetSettings();
}
}
```
is ok??
from esp8266-esp32-sdk.
Looks better now :)
This is how I would do it (without Timer library)
#include <Arduino.h>
#include <SinricPro.h>
#include <SinricProGarageDoor.h>
const char* WIFI_SSID = "";
const char* WIFI_PASS = "";
const char* APP_KEY = "";
const char* APP_SECRET = "";
const char* GARAGEDOOR_ID_1 = "";
const char* GARAGEDOOR_ID_2 = "";
const int doorPin1 = 22;
const int doorPin2 = 23;
unsigned long timerDoor1 = 0;
unsigned long timerDoor2 = 0;
const int DELAY_TIME = 2000;
void startDoorTimer(unsigned long& timerReference) {
timerReference = millis();
}
void triggerDoor(const int doorPin) {
digitalWrite(doorPin, LOW);
delay(500);
digitalWrite(doorPin, HIGH);
}
bool onDoorState(const String& deviceId, bool& state) {
if (state) {
if (deviceId == GARAGEDOOR_ID_1) {
triggerDoor(doorPin1);
startDoorTimer(timerDoor1);
}
if (deviceId == GARAGEDOOR_ID_2) {
triggerDoor(doorPin2);
startDoorTimer(timerDoor2);
}
}
return true;
}
void handleDoorTimer(unsigned long& timer, const String& deviceId) {
if (timer && millis() - timer >= DELAY_TIME) {
SinricProGarageDoor& myGarageDoor = SinricPro[deviceId];
myGarageDoor.sendDoorStateEvent(false);
timer = 0;
}
}
void handleDoorTimers() {
handleDoorTimer(timerDoor1, GARAGEDOOR_ID_1);
handleDoorTimer(timerDoor2, GARAGEDOOR_ID_2);
}
void setupGarageDoors() {
pinMode(doorPin1, OUTPUT);
digitalWrite(doorPin1, HIGH);
pinMode(doorPin2, OUTPUT);
digitalWrite(doorPin2, HIGH);
}
void setupWiFi() {
Serial.println("Connecting WiFi");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("Connected");
}
void setupSinricPro() {
SinricProGarageDoor& myGarageDoor1 = SinricPro[GARAGEDOOR_ID_1];
SinricProGarageDoor& myGarageDoor2 = SinricPro[GARAGEDOOR_ID_2];
myGarageDoor1.onDoorState(onDoorState);
myGarageDoor2.onDoorState(onDoorState);
SinricPro.onConnected([](){ Serial.println("SinricPro connected");});
SinricPro.onDisconnected([](){ Serial.println("SinricPro disconnected");});
Serial.println("Connecting SinricPro...");
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(115200);
setupGarageDoors();
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
handleDoorTimers();
}
from esp8266-esp32-sdk.
#include <Arduino.h>
#include <WiFiManager.h>
#include <SinricPro.h>
#include <SinricProGarageDoor.h>
const char* APP_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxx";
const char* APP_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdf34825a937";
const char* GARAGEDOOR_ID_1 = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
const char* GARAGEDOOR_ID_2 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const int doorPin1 = 22;
const int doorPin2 = 23;
unsigned long timerDoor1 = 0;
unsigned long timerDoor2 = 0;
const int RESET = 21;
const int DELAY_TIME = 2000;
WiFiManager wifiManager;
void startDoorTimer(unsigned long& timerReference) {
timerReference = millis();
}
void triggerDoor(const int doorPin) {
digitalWrite(doorPin, LOW);
delay(500);
digitalWrite(doorPin, HIGH);
}
bool onDoorState(const String& deviceId, bool& state) {
if (state) {
if (deviceId == GARAGEDOOR_ID_1) {
triggerDoor(doorPin1);
startDoorTimer(timerDoor1);
}
if (deviceId == GARAGEDOOR_ID_2) {
triggerDoor(doorPin2);
startDoorTimer(timerDoor2);
}
}
return true;
}
void handleDoorTimer(unsigned long& timer, const String& deviceId) {
if (timer && millis() - timer >= DELAY_TIME) {
SinricProGarageDoor& myGarageDoor = SinricPro[deviceId];
myGarageDoor.sendDoorStateEvent(false);
timer = 0;
}
}
void handleDoorTimers() {
handleDoorTimer(timerDoor1, GARAGEDOOR_ID_1);
handleDoorTimer(timerDoor2, GARAGEDOOR_ID_2);
}
void setupGarageDoors() {
pinMode(doorPin1, OUTPUT);
digitalWrite(doorPin1, HIGH);
pinMode(doorPin2, OUTPUT);
digitalWrite(doorPin2, HIGH);
}
void setupWiFi() {
wifiManager.autoConnect("GarageDoorAP");
}
void setupSinricPro() {
SinricProGarageDoor& myGarageDoor1 = SinricPro[GARAGEDOOR_ID_1];
SinricProGarageDoor& myGarageDoor2 = SinricPro[GARAGEDOOR_ID_2];
myGarageDoor1.onDoorState(onDoorState);
myGarageDoor2.onDoorState(onDoorState);
SinricPro.onConnected([](){ Serial.println("SinricPro connected");});
SinricPro.onDisconnected([](){ Serial.println("SinricPro disconnected");});
Serial.println("Connecting SinricPro...");
SinricPro.begin(APP_KEY, APP_SECRET);
// WiFiManager wifiManager; // Create an instance of WiFiManager
wifiManager.autoConnect("GarageDoorAP"); // Start WiFiManager
}
void setup() {
Serial.begin(115200);
pinMode(RESET, INPUT_PULLUP);
setupGarageDoors();
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
handleDoorTimers();
if(digitalRead(RESET) == LOW)
{
wifiManager.resetSettings();
}
}
Sinric.Pro.2.Door.Garage.mp4
Thank you teacher for the code with much more class than mine.
I have added Wifi Manager.
The problem is that the relay only works when I press close, when I press open the relay does not work.
from esp8266-esp32-sdk.
Sorry, misunderstanding on my side.
I'm not on my PC right now.
I'll send you the code later.
from esp8266-esp32-sdk.
Perfect, no problem, thank you very much
Remember that after pressing open after 20 seconds I need the app to be closed again without activating the relay.
from esp8266-esp32-sdk.
You need to change
const int DELAY_TIME = 20000;
and
bool onDoorState(const String& deviceId, bool& state) {
if (deviceId == GARAGEDOOR_ID_1) {
triggerDoor(doorPin1);
if (state) startDoorTimer(timerDoor1);
}
if (deviceId == GARAGEDOOR_ID_2) {
triggerDoor(doorPin2);
if (state) startDoorTimer(timerDoor2);
}
return true;
}
from esp8266-esp32-sdk.
Friend, your help is a great honor for me, the code is solved now the relays work well.
The problem is the text Closed and open in the app. The first time after a restart you press open and after 20 seconds the text in the app says closed, perfect, but if you press open again the relay works ok but the text in the app After 20 seconds it does not change to closed.
For it to change from open to closed you must first press close and then open, so if it works after 20 seconds it indicates closed.
In summary you have to cycle press open close and open the text changes to closed ok, but if you only press open several times only the first one works well.
I hope you understood me.
from esp8266-esp32-sdk.
Can you please explain your system.
Why should the status be automatically closed again after 20 seconds? Does your door close again automatically after 20 seconds? I don't quite understand that.
Perhaps you can show a video of the system that clearly shows how it works.
from esp8266-esp32-sdk.
Friend Sivar.
My system closes the door after 20 seconds, so I don't need to press close, just open.
With your code after a reset of the esp32 it works fine by pressing open 20 seconds later the app changes its text from open to close, but if I press open again after 20 seconds it does not change the text from open to close.
Well, your code is great, very professional.
I will use mine if it works the way I want it to, thank you
status2.change.mp4
from esp8266-esp32-sdk.
As you can see in the video, the first time it works well, it changes the state, but the second time it does not change the state.
The only option for it to change state is by clicking close and then open.
from esp8266-esp32-sdk.
Hi @Neu59
Sorry, I confused myself with the status (open / closed).
I have completely revised the sketch
- Supports up to N garage doors
- The
garageDoors
array can be expanded until you run out of garage doors, DeviceIDs or memory ;)
- The
- Each garage door has it's own name, which is used for serial output
- Each garage door can have its own closing time (not fixed for all to 20 seconds)
- Code split into low-, mid- and high-level functions for better readability and understanding
The code consist of 2 files now:
You can rename the "main.cpp" to anything you want, like "GarageDoor.ino" - whatever you prefer
from esp8266-esp32-sdk.
Master, thank you for generating the code for this situation.
In the main code I can't find the lines
const char* GARAGEDOOR_ID_1 = " ";
const char* GARAGEDOOR_ID_2 = " "
from esp8266-esp32-sdk.
See lines 14-15
from esp8266-esp32-sdk.
If you want to add another garagedoor, simply expand the array.
from esp8266-esp32-sdk.
Garage Door.h: No such file or directory
Friend, do I need a library?
from esp8266-esp32-sdk.
You need to create a file called "GarageDoor.h"
Copy the content from the gist file into your local "GarageDoor.h" file.
from esp8266-esp32-sdk.
If this is too complicated change the main.cpp like so:
#include <Arduino.h>
#include <SinricPro.h>
#include <SinricProGarageDoor.h>
const char* WIFI_SSID = "WIFI_SSID_HERE";
const char* WIFI_PASS = "WIFI_PASS_HERE";
const char* APP_KEY = "APP_KEY_HERE";
const char* APP_SECRET = "APP_SECRET_HERE";
struct GarageDoor {
GarageDoor(const String& name, const String& deviceId, const int pin, const int delayTime) : name(name), deviceId(deviceId), pin(pin), delayTime(delayTime), timer(0) {}
const String name;
const String deviceId;
const int pin;
const unsigned long delayTime;
unsigned long timer;
};
GarageDoor garageDoors[]{
// name deviceId pin delay time (ms)
{"GarageDoor1", "DEVICE_ID_DOOR1_HERE", 22, 20000},
{"GarageDoor2", "DEVICE_ID_DOOR2_HERE", 23, 20000}
};
// rest of the code ....
See Multiple Garagedoors (single file version)
from esp8266-esp32-sdk.
Master, now it works perfectly, thank you very much.
from esp8266-esp32-sdk.
You're welcome.
I highly recommend to use a (hardware) switch to detect the close state.
The current implementation for the closed state is only based on the timers and does not reflect the real door state.
from esp8266-esp32-sdk.
I have added wifimanager and in the gpio21 I press LOW and reset the wifi configuration
#include <Arduino.h>
#include <WiFiManager.h> // Incluimos la biblioteca WiFiManager
#include "GarageDoor.h"
#include <SinricPro.h>
#include <SinricProGarageDoor.h>
const char* APP_KEY = "d0465c32-b7e1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char* APP_SECRET = "c9bb2cab-5213-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const int RESET = 21;
WiFiManager wifiManager;
GarageDoor garageDoors[]{
// name deviceId pin delay time (ms)
{"GarageDoor1", "66354xxxxxxxxxxx", 22, 20000},
{"GarageDoor2", "66354xxxxxxxxxxx", 23, 20000}
};
void triggerGarageDoor(GarageDoor& garageDoor) {
digitalWrite(garageDoor.pin, LOW);
delay(500);
digitalWrite(garageDoor.pin, HIGH);
Serial.printf("[%s]: triggered\r\n", garageDoor.name.c_str());
}
void startGarageDoorTimer(GarageDoor& garageDoor) {
Serial.printf("[%s]: timer started\r\n", garageDoor.name.c_str());
garageDoor.timer = millis();
}
void stopGarageDoorTimer(GarageDoor& garageDoor) {
Serial.printf("[%s]: timer stopped\r\n", garageDoor.name.c_str());
garageDoor.timer = 0;
}
void openGarageDoor(GarageDoor& garageDoor) {
Serial.printf("[%s]: opening door\r\n", garageDoor.name.c_str());
triggerGarageDoor(garageDoor);
startGarageDoorTimer(garageDoor);
}
void closeGarageDoor(GarageDoor& garageDoor) {
Serial.printf("[%s]: closing door\r\n", garageDoor.name.c_str());
triggerGarageDoor(garageDoor);
stopGarageDoorTimer(garageDoor);
}
bool garageDoorTimerIsExpired(GarageDoor& garageDoor) {
if (garageDoor.timer && millis() - garageDoor.timer >= garageDoor.delayTime) {
Serial.printf("[%s]: timer expired\r\n", garageDoor.name.c_str());
return true;
}
return false;
}
void sendGarageDoorCloseEvent(GarageDoor& garageDoor) {
SinricProGarageDoor& myGarageDoor = SinricPro[garageDoor.deviceId];
myGarageDoor.sendDoorStateEvent(true);
Serial.printf("[%s]: close event sent\r\n", garageDoor.name.c_str());
}
void handleGarageDoorTimer(GarageDoor& garageDoor) {
if (garageDoorTimerIsExpired(garageDoor)) {
stopGarageDoorTimer(garageDoor);
sendGarageDoorCloseEvent(garageDoor);
}
}
void handleGarageDoorTimers() {
for (auto& garageDoor : garageDoors) handleGarageDoorTimer(garageDoor);
}
bool onDoorState(const String& deviceId, bool& state) {
for (auto& garageDoor : garageDoors) {
if (deviceId == garageDoor.deviceId) {
if (state) {
closeGarageDoor(garageDoor);
} else {
openGarageDoor(garageDoor);
}
return true;
}
}
return false;
}
void setupGarageDoor(GarageDoor& garageDoor) {
int pin = garageDoor.pin;
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
SinricProGarageDoor& door = SinricPro[garageDoor.deviceId];
door.onDoorState(onDoorState);
}
void setupGarageDoors() {
for (auto& garageDoor : garageDoors) setupGarageDoor(garageDoor);
}
void setupWiFi() {
// Creamos un objeto WiFiManager
// WiFiManager wifiManager;
// Conectamos al WiFi, si no se puede conectar, se abrirá un portal de configuración de WiFi
if (!wifiManager.autoConnect("GarageDoorAP")) {
Serial.println("failed to connect and hit timeout");
// Reiniciar y volver a intentar la conexión si no se puede conectar
ESP.restart();
delay(1000);
}
Serial.println("connected... :)");
}
void setupSinricPro() {
SinricPro.onConnected([]() { Serial.println("[SinricPro]: connected"); });
SinricPro.onDisconnected([]() { Serial.println("[SinricPro]: disconnected"); });
Serial.println("[SinricPro]: connecting...");
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(115200);
setupGarageDoors();
setupWiFi();
setupSinricPro();
pinMode(RESET, INPUT_PULLUP);
}
void loop() {
SinricPro.handle();
handleGarageDoorTimers();
if(digitalRead(RESET) == LOW)
{
wifiManager.resetSettings();
}
}
from esp8266-esp32-sdk.
Are you referring to a magnetic sensor to know when it opens and closes?
from esp8266-esp32-sdk.
setupWiFi looks okay!
Suggestion: put the code for the reset button into a separate function "handleResetButton" and call this from the loop.
from esp8266-esp32-sdk.
ok I will
In my case it is a community of neighbors, the door has a photo cell to stop due to obstruction and automatic closing.
Is that okay, Master?
from esp8266-esp32-sdk.
Better... I'll correct your code later today to make it perfect. I have to leave now.
from esp8266-esp32-sdk.
Friend, is it possible to share the app with the family?
from esp8266-esp32-sdk.
cc @kakopappa :
Friend, is it possible to share the app with the family?
from esp8266-esp32-sdk.
from esp8266-esp32-sdk.
Sinric pro is great, thank you very much
from esp8266-esp32-sdk.
Here comes the final sketch Multiple garage doors (single file version) with WiFiManager and reset button
from esp8266-esp32-sdk.
thanks friend now I have a professional code
from esp8266-esp32-sdk.
Related Issues (20)
- 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
- 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
- Manual Push switch not working when disconnected from internet. HOT 8
- Connection rest by peer HOT 12
- Compilation error: invalid user-defined conversion from 'SINRICPRO_3_0_1::SinricProClass::Proxy' to 'SinricProDoorbell&&' {aka 'SINRICPRO_3_0_1::SinricProDoorbell&&'} [-fpermissive] HOT 5
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.