Blynk slow response / no response at all

Dear Blynk,

I came across this platform yesterday, and I’ve been testing and trying some stuff with it. I would like to integrate it with something bigger, and that’s what I’ve been trying.

I’m using the Arduino Uno, wired to my PC via USB. I’m running a local server on that PC and my phone is connected via the same network over wifi.

That’s all working, it’s connecting etc. But the thing is, the response time of the app is very slow. Some buttons don’t even seem to work, even though they’re (I think) programmed correctly and on a very rare occasion they do work.

Here a screenshot of the app and all the code for the program (there’s a lot of math but I don’t think that’s the problem. Let me know if you need some more explanation or something else.

Thanks for helping me out!

PICTURE:

CODE:

#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT DebugSerial

SoftwareSerial DebugSerial(2, 3);
WidgetLED led1(V25);

char auth[] = "___";

#include <Servo.h>
#include <math.h>

Servo camerarotatemotor;
Servo drivemotor;

double pi = M_PI;
double rg = (180/pi);

double camerarotate;
double motordolly = 0;
double gradenperstap = 1;
double gradenperstapcam = 1;
int isTracking = 0;
int getFocus = 0;

double distance = 3; 
double radius = 8.11;

double ypoint_focus;
double xpoint_focus;

double ypointCamera;
double xpointCamera;

double angleposition;
int driveposition = 0;

BLYNK_WRITE(V5)
{
  distance = param.asInt();
}
BLYNK_WRITE(V6)
{
  isTracking = param.asInt();
  if(isTracking == 1)
  {
    led1.setValue(255);
  }
  else
  {
    led1.setValue(0);
  }
}
BLYNK_WRITE(V7)
{
   getPointFocusCoordinates(driveposition, angleposition);
}
BLYNK_WRITE(V8)
{
  if(isTracking != 1)
  {
    driveposition = param.asInt();
  }
}
BLYNK_WRITE(V9)
{
  if(isTracking != 1)
  {
    angleposition = param.asInt();
  }
}

void setup() 
{
  DebugSerial.begin(9600);
  Serial.begin(9600);
  Blynk.begin(auth, Serial);

  camerarotatemotor.attach(8);
  camerarotatemotor.write(0);

  drivemotor.attach(9);
  drivemotor.write(30);
}



void loop() 
{
  Blynk.run();
  Blynk.virtualWrite(V1, angleposition);
  Blynk.virtualWrite(V2, driveposition);

  if(isTracking == 1)
  {
    for(int i = -30; i<=30; i++)    
    {
      angleposition = giveposition(i);
      Blynk.virtualWrite(V1, angleposition);
      Blynk.virtualWrite(V2, driveposition);

      driveposition = i;
      if(isTracking != 1)
      {
        break;
      }
      delay(2000);
    }
  }
  delay(10);
 
}


double giveposition(double dollyang)
{ 
   xpointCamera = -radius * sin(dollyang / rg);
   ypointCamera = radius * cos(dollyang / rg) ;

   double dTempX = xpoint_focus - xpointCamera;
   double dTempY = ypoint_focus - ypointCamera;
   double dTempA = sqrt(dTempX * dTempX + dTempY * dTempY);
   
   double slopeangle  = (asin(-dTempX / dTempA) * rg);
  if(dTempY < 0)
  {
    slopeangle = 180 - slopeangle;
  }
  return angleposition =  slopeangle - dollyang;   
}


void getPointFocusCoordinates(double dollyangstart, double camerarotstart)
{

   xpointCamera = -radius * sin(dollyangstart / rg);
   ypointCamera = radius * cos(dollyangstart / rg);
   
   xpoint_focus = -(distance * sin((camerarotstart  + dollyangstart) / rg)) + xpointCamera;
   ypoint_focus = (distance * cos((camerarotstart  + dollyangstart) / rg)) + ypointCamera;
   Blynk.virtualWrite(V20, xpoint_focus);
   Blynk.virtualWrite(V21, ypoint_focus);

}

I do know the basics of C though. I’m using the Arduino IDE and without the Blynk part, if I were to just Serial.print some results everything works perfectly fine.

I was hoping that anyone would be able to look at my code and maybe say where it goes wrong :grimacing:

Thanks though

@Speedpiano your loop() is not acceptable for use with Blynk and that is why you downloaded SimpleTimer along with the other 5 libraries when you started Blynking.

SimpleTimer.

Please check “Recommendations” section of blynk documentation
http://docs.blynk.cc/#blynk-main-operations-limitations-and-recommendations

Thank you all!

I’ve started from scratch, keeping those things in mind.

I will need to use a for loop sometimes, and in my testing I see that BLYNK_WRITE functions are called when the for loop is over, which is not something I want because the for loop might take long in something like a timelapse. Is there some way I can get input processing done during a for loop or is it just better to use a timeInterval there as well?

Thanks again for all the support

Avoid this as it will cause issues with Blynk

This was probably your biggest issue. No sleeping permitted ;)… Blynk is always demanding attention, else it quits communicating.