BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

HM10 Blynk, keeps reconnecting after being ready for few seconds

My code:

#include <Blynk.h>

#define BLYNK_PRINT Serial

const int FSR_PIN = A0; // Pin connected to FSR/resistor divider

// Measure the voltage at 5V and resistance of your 3.3k resistor, and enter
// their value's below:
const float VCC = 3.94; // Measured voltage of Ardunio 5V line
const float R_DIV = 3000.0; // Measured resistance of 3.3k resistor

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>

#include <BlynkSimpleSerialBLE.h>

SoftwareSerial SerialBLE(10, 11);


int steps = 0;
int pinValue;

BLYNK_WRITE(V3)
{
  pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
  // process received value
  if (pinValue == 1) {
    steps = 0;
    Blynk.virtualWrite(V2, 0);
  }
}


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "47ea30fe632b458485e9ebd69fa3d35e";

void setup()
{
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);
  pinMode(7, INPUT);
  Blynk.virtualWrite(V2, 0);
}

int i = 0;

void loop()
{
  Blynk.run();

  int fsrADC = analogRead(FSR_PIN);

  if (fsrADC != 0) // If the analog reading is non-zero
  {
    // Use ADC reading to calculate voltage:
    float fsrV = fsrADC * VCC / 1023.0;
    // Use voltage and static resistor value to 
    // calculate FSR resistance:
    float fsrR = R_DIV * (VCC / fsrV - 1.0);

    // Guesstimate force based on slopes in figure 3 of
    // FSR datasheet:
    float force;
    float fsrG = 1.0 / fsrR; // Calculate conductance
    // Break parabolic curve down into two linear slopes:
    if (fsrR <= 600) 
      force = (fsrG - 0.00075) / 0.00000032639;
    else
      force =  fsrG / 0.000000642857;
    if (i % 5 == 0) {
      Blynk.virtualWrite(V1, force);
    }
    i++;
    delay(100);
  }

  if (digitalRead(7) == HIGH) {
    steps++;
    Blynk.virtualWrite(V2, steps);
    delay(100);
  }
}

When I upload, blynk shows it the way i want. But i need to present in front of others my project which is a smart shoe that connects to bluetooth. The bluetooth disconnects like every few seconds. ON serial monitor it shows (ready ping) for a few seconds and it works on the app. then it keep looping reconnecting for like 20 seconds then again ready for only few seconds.

I need it to be steady ready for atleast a minute to be able to show my project!
please I need help ASAP im presenting on Saturday in NYC

  1. Check the limitations section on our docs: http://docs.blynk.cc/#blynk-main-operations-limitations-and-recommendations and look into this topic about avoiding using writes in the loop: Don't write code in void loop! :D
  2. Please use code formatting in your post, it is very hard to read it.
  3. Add mode details on what version of the library you are using, what device you are using with what app’s version.

@natan679 I have formatted your code as required for proper forum viewing… please follow this procedure in the future. Thank You.

Bluetooth/ BLE is still listed as BETA and while I have personally found it basicly functional, it is limited and susceptible to interruptions in the App <–> Hardware connection, particularly if reading or controlling something in a constant loop for more than a few seconds…

I don’t know what your sketch is trying to accomplish, but as already mentioned, you need to remove the main action out of the void loop() and run it in a Blynktimer loop. And avoid delays whenever possible, even short ones, use timers instead.