HELP: login timeout and cycle into BLYNK_WRITE

Hello, i’m trying to add bluetooth with my Arduino UNO with HC-05 module with blynk but i’m new to this and i’m having some trouble. My project is a led strip controller that can:
-change colour from the app.
-fade this color if a button is pressed .
-respond to music time when a button is pressed.
-change the speed of the fade.

in the app i have:
-zRGBa widget to V0 to send RGB values.
-a fade button in switch mode to V1.
-a music button in switch mode to V2
-a fade speed slider to V3.

PROBLEMS:
-in the serial port i’m receiving “connecting…” and then “login timeout” in loop. so i don’t understand why it’s not connecting. however i receive all virtual pins values.

-for now i’m only able to change color but there is a random delay from when i touch the widget and when the colour changes, maybe because the module is trying to connect and prevent data to be sended in the meanwhile?

-i’ve tried to write a “while” loop in the BLYNK_WRITE(V1) function but is not working properly, just loop forever, i can’t update the exit value inside the cicle, and even “Blynk.syncVirtual(V3)” that should call BLYNK_WRITE(V3) to update fade speed is not working. maybe because of my first problem as well?

-Interrupt does not work, when the BLYNK_WRITE(V2) function is called the R G B output pins just get all low.

Thank you al lot if you are going to help me :wink:

here is my code:

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG 

struct rec
{
  int fade,music;
  int del;
  int r,g,b;
  
};

rec data = {0, 1, 5, 255, 0, 255};  //default values for all the bt data
       

const int R = 9;
const int G = 10;
const int B = 11;

const int SI = 2;

const int RX = 0;
const int TX = 1;

int intflag = 0;

char auth[] = "4a8519321fcd4709959979919868a3a4";


#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

SoftwareSerial SerialBLE(RX, TX); //0 1
void setup() 
{  
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);
  
  pinMode(B,OUTPUT); //outupts to mosfets
  pinMode(R,OUTPUT);
  pinMode(G,OUTPUT);

  pinMode(SI,INPUT_PULLUP); // sound sensor input for interrupt
}

void loop() 
{
  Blynk.run();
 
}

BLYNK_CONNECTED()
{
  Blynk.syncAll();//should get all the pins value from bt
}

BLYNK_WRITE(V0) //get rgb
{
   data.r = param[0].asInt();
   data.g = param[1].asInt();
   data.b = param[2].asInt();

   color(data.r,data.g,data.b); //function that send PWM values to mosfets
   
}


BLYNK_WRITE(V1) //get fade
{
  data.fade = param.asInt();
  while(data.fade==1)
  {
    Blynk.syncVirtual(V3);   //read value of data.del?
    fade(data.del);  //function that fade with a specified delay the already present color
    data.fade = param.asInt(); //should update data.fade value from bt in order to exit the cicle?
  }
}    

BLYNK_WRITE(V2) //get music
{
  data.music = param.asInt();

  if(data.music==1)
    attachInterrupt(digitalPinToInterrupt(SI),off , RISING); //sound sensor attached to interrupt,off turn off all 
                                                                                         //leds
  else                 
    detachInterrupt(digitalPinToInterrupt(SI));
}

BLYNK_WRITE(V3) //get del
{
  data.del = param.asInt();
}

void fade (int del)
 {
  int con,conr,cong,conb,max=255;

  conr=0;
  cong=0;
  conb=0;
  
 for(con=0;con<max;con++)
  {
     if(conr<data.r)
      conr++;
      
     analogWrite(R,conr);

     if(cong<data.g)
      cong++;

     analogWrite(G,cong);

     if(conb<data.b)
      conb++;

     analogWrite(B,conb);
     
     delay(del);
    
   }

    conr=data.r;
    cong=data.g;
    conb=data.b;
    
    for(con=0;con<max;con++)
    {
      if(conr>0)
      conr--;
      
     analogWrite(R,conr);

     if(cong>0)
      cong--;

     analogWrite(G,cong);

     if(conb>0)
      conb--;

     analogWrite(B,conb);
     delay(del);
    }
  }




  void color (int r,int g,int b)
  {
    analogWrite(R,r);
    analogWrite(G,g);
    analogWrite(B,b);
  }

  void off ()
  {
    analogWrite(R,0);
    analogWrite(G,0);
    analogWrite(B,0);
  }

First off… don’t use SoftwareSerial when connecting directly to the Hardware UART pins… and this will also conflict with your serial monitor (#define BLYNK_PRINT Serial) as a serial port can only be used by one thing at a time.

Move your SoftwareSerial and BT module to different (supported) pins.

Use of delay() can also cause disconnection… even via BT/BLE.

And I don’t know if Blynk.syncAll(); is even supported on BT/BLE??

Thank you for your suggestions. i will apply changes to the code. i don’t know if Blynk.syncall()is supported via bt anyway is not that necessary.
Do you know if it is possibile to create a loop with an exit condition sent from the app in the BLYNK_WRITE function?
and if it is possibile in some way to use interrupts?

As long as your loop doesn’t block Blynk.run() and has some form of flag check, then you can use a BLYNK_WRITE() call to toggle said flag. But probably best to use timers instead of repeating loops.

Sure, just use them the normal way I guess… I don’t really use them myself, so do some searching of this forum for the keyword and see what others have said.

Thank you, now blynk is connected and the colors are changing with no delay, and with the timer function i’ve managed to get the fade mode working good.

Do you know if Blink.syncVirtual is compatible with bt? the manual don’t say much about it, but it seems like it should call BLYNK_WRITE in order to get an updated value from the buffer, but in my code just do nothing.

Since it is syncing with the server… which is NOT connected in BT/BLE, so I guess that is a no.