[Solved] Garage door opener project keeps resetting :(

Hi. I need help my door opener project keeps resetting. Here’s the code :slight_smile:


 #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <SimpleTimer.h>
SimpleTimer timer_door_contact;
//SimpleTimer Force_WiFi_Timer;

/* 
void Post_WiFi_Signal(){
String Force_WiFi;

String All_Infos;
 All_Infos = getCurrentDate() + String("  ") + getCurrentTime() + String("  Wifi: ") + map(WiFi.RSSI(), -105, -40, 0, 100) + String('%');
 RSSI_LCD.print(0,0, All_Infos);
}
*/

#define ssid "VIDEOTRON2944"
#define pass "K7E97YHEA9JAM"

// garage MARC
char auth[] = "0d23539d01984293a0675b7041d027e6";

// garage MAMAN
char bridge_auth[] = "a414457c01284b78a505981409724e96";

/*
/////////////////////////////////////////////////////////////
// IFTTT setup
const char *host = "maker.ifttt.com";
const char *Maker_Event = "Your EVENT Name";
const char *Your_Key = "Your key on Maker Channel";
/////////////////////////////////////////////////////////////
*/

#define GARAGE_LOCK      D1
#define DOOR_SENSOR      D7
#define LED_GARAGE_OPEN  D5
#define LED_GARAGE_CLOSE D6

WidgetBridge bridge1(V1);
WidgetLCD lcd(V3);

/*
 *  PORTE DE GARAGE FERMÉE  = 1
 *  PORTE DE GARAGE OUVERTE = 0
 * 
 */
void check_door_contact(){
 lcd.clear();
 lcd.print(0, 0, "PORTE DE GARAGE "); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")

 int valueDoorContact = digitalRead(DOOR_SENSOR);

 if (valueDoorContact == HIGH){
  lcd.print(5, 1, "FERMEE");
  bridge1.virtualWrite(V6, 0);
   
  digitalWrite(LED_GARAGE_OPEN, LOW);
  digitalWrite(LED_GARAGE_CLOSE, HIGH);
 }

  if (valueDoorContact == LOW){
   bridge1.virtualWrite(V6, 1);
   lcd.print(5,1, "OUVERTE");
   digitalWrite(LED_GARAGE_OPEN, HIGH);
   digitalWrite(LED_GARAGE_CLOSE, LOW);
  }
}  // void check_door_contact()

void Ecrit_Force_WiFi(){
 String Force_WiFi;
 Force_WiFi = map(WiFi.RSSI(), -105, -40, 0, 100) + String('%');
 Blynk.virtualWrite(V5, String(Force_WiFi));
}

////////////////////////////////////
// setup
void setup(){
 Serial.begin(115200);
 pinMode(GARAGE_LOCK, OUTPUT);
 digitalWrite(GARAGE_LOCK, LOW);

 pinMode(DOOR_SENSOR, INPUT);
 pinMode(LED_GARAGE_OPEN, OUTPUT);
 digitalWrite(LED_GARAGE_OPEN, LOW);

 pinMode(LED_GARAGE_CLOSE, OUTPUT);
 digitalWrite(LED_GARAGE_CLOSE, LOW); 
 
////////
 timer_door_contact.setInterval(10000L, check_door_contact);
 //Force_WiFi_Timer.setInterval(5000L, Ecrit_Force_WiFi);
 
////////
 Blynk.begin(auth, ssid, pass);
 while (Blynk.connect() == false){
  // Wait until connected...
 } 
  lcd.clear();
  // ...
}

// loop
void loop(){  
 Blynk.run();
 timer_door_contact.run();
 //Force_WiFi_Timer.run();
}

bool firstConnect = true;
BLYNK_CONNECTED(){
 bridge1.setAuthToken(bridge_auth); 

if (firstConnect) // When we first connect to Blynk
 {
  Serial.println("First Blynk connected...");
  Blynk.notify("Garage Door Opener MPE Started!");
  lcd.clear();
  
  Blynk.syncAll(); 
  firstConnect = false;
 }
}

// This function will be called every time
// when App writes value to Virtual Pin 0
BLYNK_WRITE(V0)
{
 BLYNK_LOG("Got a value: %s", param.asStr());

 int myValue = param.asInt(); 
 if (myValue == 1){
  digitalWrite(GARAGE_LOCK, HIGH); 
  delay(1000);
  digitalWrite(GARAGE_LOCK, LOW);
  delay(1000);
  bridge1.virtualWrite(V0, myValue);
 }
}

Code snippets should be formatted. Please edit your initial post:

How to do that:


 ``` cpp <--put 3 backticks BEFORE your code starts  ("cpp" means C++ language) 

   //Put your code here
   //..................
   //..................

 ``` <--insert 3 backticks AFTER your code

**This makes your code readable and with highlighted syntax, like this

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}
1 Like

Looks like these 2 delays are your problem…

Thank you for your response even if i don’t push-pull on The Button it’s still dis connecting :frowning: What do you think about The timer To check The door state ?
Thank you.
Marc.

You don’t, but Blynk.syncAll(); does it for you :slight_smile: I’m not sure, but because of repeated disconnect these delays may also trigger WDT soft reset at ESP?. Have you got serial output from ESP?

I have removed the syncAll();

thank you very much for all!!

Have a nice holidays.
Marc.

solved thanks! :slight_smile: