Help with bridge widget

hi to all!
i have a rfid reader based on esp 8266 and a lock(and opening gate and switch light) on arduino uno with ethernet shild.When i read the card,I ordered through bridge widget to my arduino uno and door opened,but as soon as the key is read door open and arduino uno is ofline.I do not understand why.
У меня есть считыватель подключенный к esp82266 и ардуино уно которая управляет светом,воротами,дверью с эзернет шилдом.Я настроил на есп при считывании ключа открывать калитку при помощи виджета bridge.Иногда бывает что ключ считывается,калитка открывается и замок(электромагнитный) остается в открытом положении,а ардуино уходит в офлайн и перестает реагировать на команды.


 #include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "MFRC522.h"
SimpleTimer timer;
#define RST_PIN 5 // RST-PIN for RC522 - RFID - SPI - Modul GPIO15 
#define SS_PIN  2  // SDA-PIN for RC522 - RFID - SPI - Modul GPIO2
MFRC522 mfrc522(SS_PIN, RST_PIN);   // создаем картридер
unsigned long uidDec, uidDecTemp;  // для храниения номера метки в десятичном формате
char auth[] = "*******************";
// Set password to "" for open networks.
char ssid[] = "home";
char pass[] = "********";
IPAddress server_ip (192.168.0.156);
byte arduino_mac[] = { 0x8F, 0x21, 0x1A, 0xE4, 0x73, 0xED };
IPAddress device_ip  (192, 168,   0,  181);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip (192, 168,   0,   1);
IPAddress subnet_mask(255, 255, 255,   0);
WidgetBridge bridge1(V1);

BLYNK_CONNECTED()
{
  bridge1.setAuthToken("***************"); // Place the AuthToken of the second hardware here
 }
void setup()
{
   //Serial.begin(9600); 
   // Serial.println("Waiting for card...");
   pinMode(4, OUTPUT);
   SPI.begin();           // инициализируем SPI шину
   mfrc522.PCD_Init();    // инициализируем рфид
   timer.setInterval(1000L, rfid); //таймер для чтения карты каждые две секунды
   WiFi.config(device_ip, gateway_ip, subnet_mask);
   WiFi.begin(ssid, pass);
   Blynk.config(auth, server_ip, 8442);
   while (Blynk.connect() == false)
    {
   }
}
void rfid()
  {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
   // delay(50);
    return;
   }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
   // delay(50);
    return;
   }
   uidDec = 0;
   // Выдача серийного номера метки.
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    uidDecTemp = mfrc522.uid.uidByte[i];
    uidDec = uidDec * 256 + uidDecTemp;
  }
  //Serial.println("Card UID: ");
  //Serial.println(uidDec); // Выводим UID метки в консоль.
  Blynk.virtualWrite(V0,uidDec);// отправляем номер карты в придлжение

  if (uidDec == 899895353||uidDec == 2513558694||uidDec == 84924582||uidDec == 3849511846||uidDec == 35273910||uidDec == 3856195750) // Сравниваем Uid метки, если он равен заданому то серва открывает.
 //if (uidDec == 899895353||2513558694||84924582||3849511846||35273910||3856195750) // Сравниваем Uid метки, если он равен заданому то серва открывает.
 {
  tone(4, 2900, 400); // Делаем звуковой сигнал,карта верная
  bridge1.digitalWrite(8, LOW);//открываем калитку
  timer.setTimeout(1000, door_open);
  noTone(4);
  }
else
{
  tone(4, 200, 500); // Делаем звуковой сигнал,карта неверная
  timer.setTimeout(1000, tonestop);
}
 
}
void door_open()
{
  bridge1.digitalWrite(8, HIGH);//закрываем калитку
 }
void tonestop()
{
  noTone(4);
}
void loop()
{
      timer.run(); 
      Blynk.run();
}

Do you have any code running on the Uno that might be looping when detecting that the digital pins are going high?

Can you show that code as well. Thanks.

yes,i I follow the state of pin and turn on the lamp if If it is dark outside and door open.
Да я слежу за состоянием пина и вечером включаю свет при открытии калитки.

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
boolean buttonstate=false;
boolean flag=true;
SimpleTimer timer;
SimpleTimer timer1;
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V6);
WidgetLED led4(V7);
WidgetLED led5(V11);
WidgetLED led6(V12);
WidgetBridge bridge2(V8);
int relay1=6;
int relay2=7;
int ldr = 0;
boolean svet=false;
char auth[] = "********************************";
IPAddress server_ip(192, 168, 0, 156);
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0x8E, 0xED, 0xE6, 0x18, 0xFE, 0xED };
IPAddress arduino_ip ( 192,   168,   0,  180);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   0,   1);
IPAddress subnet_mask(255, 255, 255,   0);
#define W5100_CS  10
#define SDCARD_CS 4

BLYNK_CONNECTED()
{
   bridge2.setAuthToken("***********************");
}
void setup()
{
 pinMode(relay1, OUTPUT);// ворота
 pinMode(relay2, OUTPUT);//ворота
 pinMode(8, OUTPUT);//свет
 pinMode(9, OUTPUT);//калитка
 pinMode(3, INPUT);
 pinMode(5, INPUT);
 digitalWrite(6, HIGH);
 digitalWrite(7, HIGH);
 digitalWrite(8, HIGH);
 digitalWrite(9, HIGH);
 pinMode(SDCARD_CS, OUTPUT);
 digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
//  Serial.begin(9600);
  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
}
void Vorota_Open_ON() 
{ 
      timer1.setTimeout(60000, Vorota_Open_OFF);
    //  timer.setTimeout(180000, Vorota_Open_OFF);
     
      digitalWrite(relay1,LOW);
      led1.on();
      led2.off();
      buttonstate=true; 
}
void Vorota_Open_OFF()
{
     digitalWrite(relay1,HIGH);
     
     
     
} 
//закрытие ворот
void Vorota_Close_ON() 
{ 
      timer.setTimeout(60000, Vorota_Close_OFF);
      
      digitalWrite(relay2,LOW);
      led2.on();
      led1.off();
      
}
void Vorota_Close_OFF()
{
      digitalWrite(relay2,HIGH);
  
      buttonstate=false;
} 
//включение света
BLYNK_WRITE(V5) 
{
    if (param.asInt())
    {
      //HIGH
      digitalWrite(9,LOW);
      led3.on();
      led4.off();
      svet=true;
    }
    else 
    {
    digitalWrite(9,HIGH);
      led3.off();
      led4.on();
      svet=false;
    }
}
//Включение света при открытии калитки
    void Svet_On()
    {
      timer.setTimeout(30000,Svet_Off);
      digitalWrite(9,LOW);
      bridge2.digitalWrite(49,LOW); //свет над входом в дом
      led3.on();
      led4.off();
    }
    void Svet_Off()
    {
      digitalWrite(9,HIGH);
      bridge2.digitalWrite(49,HIGH);
      led3.off();
      led4.on();
    }
//блокировка ворот
BLYNK_WRITE(V4) 
{
    if (param.asInt())
    {
      //HIGH
      flag=true;
      led5.off();
      led6.on();

    }
    else 
    {
      flag=false;
      led5.on();
      led6.off();
      digitalWrite(relay1,HIGH);
      digitalWrite(relay2,HIGH);
    }
}
//открытие ворот с телефона
BLYNK_WRITE(0) 
{
       if (param.asInt()&& buttonstate==false)
       {
        //HIGH
        Vorota_Open_ON();
       } 
       else if (param.asInt()&& buttonstate==true){
        digitalWrite(relay1,HIGH);
        Vorota_Close_ON();
       }
}
void loop()
{
 Blynk.run();
      timer.run();
      if (digitalRead(3)==HIGH && flag == true)
      {
      timer.setTimeout(500,Vorota_Open_ON);
       digitalWrite(relay2,HIGH);
      }
      if (digitalRead(5)==HIGH && flag == true)
      {
      timer.setTimeout(500,Vorota_Close_ON);
      digitalWrite(relay1,HIGH);
      }
      if (digitalRead(8) == LOW && analogRead(ldr) < 1 && svet == false)
      {
        Svet_On();
      }
}

Without spending too much time, trying to think through the exact steps in your code… I would suggest that you take the above snippet out of the void loop() and put it in it’s own timed loop.

Even if it doesn’t help immediately, it will help in tracking down the block of code that is causing the UNO’s communication drop. Always try to keep the void loop() as clear as possible: http://docs.blynk.cc/#troubleshooting-delay

Also, if you have any particularly long loop, it wouldn’t hurt to insert a Blynk.run(); call at an appropriate place within it: Introduction - Blynk Documentation

thanks, I’ll try)

I did as you said and the problem is gone.Thanks!!

1 Like