Wont connect to Blynk.Cloud 9/10 tries

I am using Sparkfun’s ESP32 Thing and Blynk 2.0 and successfully programmed the Thing, connected to my WiFi and connected to cloud, and successfully controlled my project using the new Blynk app. AFter a few days, the connection was lost and now it wont reconnect. Interrogating by Serial monitor, the ESP32 successfully connects to WiFi but endlessly tries to connect to Blynk.Cloud, unsuccessfully.

12:55:59.585 → [166053] Connecting to blynk.cloud:443

12:56:13.563 → [180045] Secure connection failed

12:56:13.596 → [180045] Timeout

12:56:13.596 → [180056] Connecting to blynk.cloud:443

12:56:57.817 → [224263] Secure connection failed

12:56:57.817 → [224273] Connecting to blynk.cloud:443

12:57:15.979 → [242471] Secure connection failed

12:57:15.979 → [242471] Timeout

12:57:16.021 → [242482] Connecting to blynk.cloud:443

etc etc

Once in while, If i reset the THing and try over and over, it will successfully connect and the Blynk app correctly controls the device

[49391] Secure connection failed

[49401] Connecting to blynk.cloud:443

[80624] Secure connection failed

[80624] Timeout

[80635] Connecting to blynk.cloud:443

[88496] Certificate OK

[88709] Ready (ping: 211ms).

[88845] CONNECTING_CLOUD => RUNNING

But this obviously is not acceptable behavior. What can I do about this? Thanks

Can you post your sketch please?
billd

It would probably also be useful if you shared the contents of your Settings.h file.

Pete.

Thanks Bill and Pete for responding. Here is the sketch. It monitors and controls a powered gate on the driveway. Comments included, template and device ids have been censored. THe Settings.h file is copied after that

#define BLYNK_TEMPLATE_ID "-----------------"

#define BLYNK_DEVICE_NAME "------------------"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial

#define APP_DEBUG 

#include "BlynkEdgent.h"

#include "TimeLib.h"

BlynkTimer timer;

String Currentwkdaytext;

BLYNK_CONNECTED() { //when device is connected to server....

  Blynk.sendInternal("rtc", "sync");  //request current local time for device. This runs once at the beginning when connected. Stores it in InternalPinRTC

}

BLYNK_WRITE(V0)  //checks to see if V0 pin (Gate Control button on app) has changed

{

  int pinValue = param.asInt();  //assigning incoming value from pin V0 to a variable

  digitalWrite(5,pinValue);  //sends High or Low value to digital pin 5 on ESP32 Thing.  This is connected to gate control circuit

}

BLYNK_WRITE(InternalPinRTC) //check the value of InternalPinRTC where time is stored internally. Reports time when gate status was last checked - which is every second

{

  long t = param.asLong();  //store the time in t variable if it has changed

time_t current = t;   //this section uses Time Library to convert Unix time to normal time

int CurrentSecond = second(current);

int CurrentMinute = minute(current);

int CurrentHour = hour(current);

int CurrentDay = day(current);

int CurrentMonth = month(current);

int CurrentYear = year(current);

int CurrentWeekday = weekday(current);

String NewTime = "";  //this section formats each component of time so it can be displayed on app

if (CurrentWeekday == 1)

{ NewTime += String("Sun  ");

}

if (CurrentWeekday == 2)

{ NewTime += String("Mon  ");

}

if (CurrentWeekday == 3)

{ NewTime += String("Tue  ");

}

if (CurrentWeekday == 4)

{ NewTime += String("Wed  ");

}

if (CurrentWeekday == 5)

{ NewTime += String("Thu  ");

}

if (CurrentWeekday == 6)

{ NewTime += String("Fri  ");

}

if (CurrentWeekday == 7)

{ NewTime += String("Sat  ");

}

      NewTime += String(CurrentMonth) + "/";

      NewTime += String(CurrentDay) + "/";

      int yearshort = CurrentYear-2000;  //shortens 2017 to just 17

      NewTime += String(yearshort) + "  ";

      int newHour = CurrentHour; //next lines convert 24 hr clock to 12 hr clock

     if (newHour > 12)

      {

      newHour = CurrentHour - 12;

      NewTime += String(newHour) + ":";

     if (CurrentMinute<10)

      {

      NewTime += String("0");

      }

     NewTime += String(CurrentMinute) + ":";

     if (CurrentSecond<10)

      {

      NewTime += String("0");

      }

    NewTime += String(CurrentSecond);

    NewTime += String(" PM");

      }

  else

    {

    NewTime += String(newHour) + ":";

    if (CurrentMinute<10)

      {

      NewTime += String("0");

      }

    NewTime += String(CurrentMinute) + ":";

    if (CurrentSecond<10)

      {

      NewTime += String("0");

      }

    NewTime += String(CurrentSecond);

    NewTime += String(" AM");

    }

Blynk.virtualWrite(V2, NewTime);

}

void myTimer()  //This runs once a second and sends gate status to app, and updates time from server to internal pin, which is reported out in code above

{

  uint8_t switchState = digitalRead(25); // Read the door switch pin

  // Pin 25 is pulled low internally. If the switch (and door) is open,

  // pin 25 is LOW. If the switch is closed (door too), pin 25 is HIGH.

  // LOW = open

  // HIGH = closed

   Blynk.sendInternal("rtc", "sync"); //updates internal pin with current time

  if (switchState)  //if pin 25 is high

    Blynk.virtualWrite(V1, "CLOSED"); // Update virtual variable

  else

    Blynk.virtualWrite(V1, "OPEN");

}

void setup()

{

  pinMode(5,OUTPUT);

  pinMode(25,INPUT);

  timer.setInterval(1000L, myTimer);

  Serial.begin(115200);

  BlynkEdgent.begin();

}

void loop() {

  BlynkEdgent.run();

  timer.run();

}
Settings.h //this was taken directly from the Blynk example file
/*

 * Board configuration (see examples below).

 */

#if defined(USE_WROVER_BOARD)

  #define BOARD_BUTTON_PIN            15

  #define BOARD_BUTTON_ACTIVE_LOW     true

  #define BOARD_LED_PIN_R             0

  #define BOARD_LED_PIN_G             2

  #define BOARD_LED_PIN_B             4

  #define BOARD_LED_INVERSE           false

  #define BOARD_LED_BRIGHTNESS        128

#elif defined(USE_TTGO_T7)

  #warning "This board does not have a button. Connect a button to gpio0 <> GND"

  #define BOARD_BUTTON_PIN            0

  #define BOARD_BUTTON_ACTIVE_LOW     true

  #define BOARD_LED_PIN               19

  #define BOARD_LED_INVERSE           false

  #define BOARD_LED_BRIGHTNESS        64

#elif defined(USE_TTGO_T_OI)

  #warning "This board does not have a button. Connect a button to gpio0 <> GND"

  #define BOARD_BUTTON_PIN            0

  #define BOARD_BUTTON_ACTIVE_LOW     true

  #define BOARD_LED_PIN               3

  #define BOARD_LED_INVERSE           false

  #define BOARD_LED_BRIGHTNESS        64

#elif defined(USE_ESP32C3_DEV_MODULE)

  #define BOARD_BUTTON_PIN            9

  #define BOARD_BUTTON_ACTIVE_LOW     true

  #define BOARD_LED_PIN_WS2812        8

  #define BOARD_LED_INVERSE           false

  #define BOARD_LED_BRIGHTNESS        32

#elif defined(USE_ESP32S2_DEV_KIT)

  #define BOARD_BUTTON_PIN            0

  #define BOARD_BUTTON_ACTIVE_LOW     true

  #define BOARD_LED_PIN               19

  #define BOARD_LED_INVERSE           false

  #define BOARD_LED_BRIGHTNESS        128

#else

  #warning "Custom board configuration is used"

  #define BOARD_BUTTON_PIN            0                     // Pin where user button is attached

  #define BOARD_BUTTON_ACTIVE_LOW     true                  // true if button is "active-low"

  //#define BOARD_LED_PIN             4                     // Set LED pin - if you have a single-color LED attached

  //#define BOARD_LED_PIN_R           15                    // Set R,G,B pins - if your LED is PWM RGB

  //#define BOARD_LED_PIN_G           12

  //#define BOARD_LED_PIN_B           13

  //#define BOARD_LED_PIN_WS2812      4                     // Set if your LED is WS2812 RGB

  #define BOARD_LED_INVERSE           false                 // true if LED is common anode, false if common cathode

  #define BOARD_LED_BRIGHTNESS        64                    // 0..255 brightness control

#endif

/*

 * Advanced options

 */

#define BUTTON_HOLD_TIME_INDICATION   3000

#define BUTTON_HOLD_TIME_ACTION       10000

#define BUTTON_PRESS_TIME_ACTION      50

#define BOARD_PWM_MAX                 1023

#define BOARD_LEDC_CHANNEL_1          1

#define BOARD_LEDC_CHANNEL_2          2

#define BOARD_LEDC_CHANNEL_3          3

#define BOARD_LEDC_TIMER_BITS         10

#define BOARD_LEDC_BASE_FREQ          12000

#if !defined(CONFIG_DEVICE_PREFIX)

#define CONFIG_DEVICE_PREFIX          "Blynk"

#endif

#if !defined(CONFIG_AP_URL)

#define CONFIG_AP_URL                 "blynk.setup"

#endif

#if !defined(CONFIG_DEFAULT_SERVER)

#define CONFIG_DEFAULT_SERVER         "blynk.cloud"

#endif

#if !defined(CONFIG_DEFAULT_PORT)

#define CONFIG_DEFAULT_PORT           443

#endif

#define WIFI_CLOUD_MAX_RETRIES        500

#define WIFI_NET_CONNECT_TIMEOUT      50000

#define WIFI_CLOUD_CONNECT_TIMEOUT    50000

#define WIFI_AP_IP                    IPAddress(192, 168, 4, 1)

#define WIFI_AP_Subnet                IPAddress(255, 255, 255, 0)

//#define WIFI_CAPTIVE_PORTAL_ENABLE

//#define USE_TICKER

//#define USE_TIMER_ONE

//#define USE_TIMER_THREE

//#define USE_TIMER_FIVE

#define USE_PTHREAD

#define BLYNK_NO_DEFAULT_BANNER

#if defined(APP_DEBUG)

  #define DEBUG_PRINT(...)  BLYNK_LOG1(__VA_ARGS__)

  #define DEBUG_PRINTF(...) BLYNK_LOG(__VA_ARGS__)

#else

  #define DEBUG_PRINT(...)

  #define DEBUG_PRINTF(...)

#endif

@wmklmr Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

Sorry, first time poster. Hopefully this reads better

So instead of uncommenting one of the board types in the .ino file you’ve deleted them all.
You also have no LED pin defined in the custom board section of the Settings.h file, so your LED isn’t working?

That makes it difficult when you get to the provisioning part where it asks if the LED is flashing rapidly before you proceed.

Does your switch on GPIO0 successfully clear the stored credentials?

Pete.

PeteKnight and Bill_Donnelly: Thanks for trying to help. For whatever reason, today the board has no trouble connecting. Apparently this is/was a temporary issue with communication between my ISP and Blynk.Cloud. I assume this, because the provisioning/connection to my WiFi was successful, and my WiFi connection to the internet passed troubleshooting and speed tests - and the code appears OK since it works fine before and after the problem appeared. If you can think of any code issue that might contribute to the unreliability of the connection to Blynk.Cloud, let me know.

I will look at cleaning up the issues Pete raised anyway. Will repost if the problem recurrs. Thanksagain

1 Like