Is blynk cloud down? Region: ny3

Thanks @Dmitriy
I use old-school connections and check connectivity periodically with a timer. Code below.
I’m using ESP8266 (generics) and ESP32 (Adafruit Feathers - love 'em).

I had assumed Blynk would reconnect itself once a good WiFi connection was made. I will soon modify this code to reboot if Blynk cannot connect for a long period.

All comments welcome. I have rebooted each of my devices and am reconnected with your servers.

Code piece 1 - libraries I use - all SSL
Code piece 2 - my connectToWLANandBlynk() routine I use in all my Blynk sketches
Code piece 3 - my timer-driven WiFi and Blynk connection checker. This is the code I will modify to reboot after too many failed attempts at a Blynk connection.

(The mySerialP and mySerialPln macros simply translate to Serial.print and Serial.println.)

Code piece 1 - libraries I use - all SSL

// This is WiFiMulti library selection for ESP32 or 8266
#define USE_SSL true // Always for primary Blynk connection
#if ESP8266
  #include <ESP8266WiFiMulti.h>
  ESP8266WiFiMulti wifiMulti;                    // set up the WiFi object
  const uint32_t connectTimeoutMs = 8000;        // timing for WiFiMulti testing connection
  #include <WiFiClientSecure.h>                  // HTTPS client
  #include <BlynkSimpleEsp8266_SSL.h>

#elif ESP32
  #include <WiFiMulti.h>
  WiFiMulti wifiMulti;                           // set up the WiFi object
  const uint32_t connectTimeoutMs = 5000;        // timing for WiFiMulti testing connection
  #include <WiFiClientSecure.h>                  // HTTPS client
  #include <BlynkSimpleEsp32_SSL.h> 
#endif

Code piece 2 - my connectToWLANandBlynk() routine I use in all my Blynk sketches

// Connects to MultiWiFi and to Blynk gracefully
// Call in Setup()
// #include after BLYNK and WIFI_CREDENTIALS

// #include "CONNECT_TO_WIFI_AND_BLYNK.h"

void connectToWLANandBlynk()  
{
  WiFi.persistent ( false ); // Don't save anything in EEPROM or LittleFS 
  WiFi.mode ( WIFI_STA );    // Station mode

  
  // Register multi WiFi networks
  wifiMulti.addAP ( MY_WIFI_SSID,  MY_WIFI_PASSWORD );
  wifiMulti.addAP ( MY_WIFI_SSID2, MY_WIFI_PASSWORD2 );


  int WiFiTries = 0; 
  while ( WiFiTries < 5 )
  if ( wifiMulti.run ( connectTimeoutMs ) == WL_CONNECTED ) 
  {
    mySerialP ( "WiFi connected just fine to ");
    mySerialP ( WiFi.SSID() ); mySerialP ( " at " ); mySerialPln ( WiFi.localIP() );
#if USE_IFTTT
    String message = "WiFi connected at " + String ( WiFi.RSSI() ) + "dBm"; 
    postToIFTTT ( message ); 
#endif
    break; 
  } 
  else 
  { 
    WiFiTries++; 
    mySerialP ( "WiFi not connected... #" ); mySerialPln ( WiFiTries ); 
    if ( WiFiTries >= 5 )
    {
      mySerialPln ( "RESTARTING!\n\n" );  
      delay ( 5000 ); 
      ESP.restart(); 
    }
    delay ( 5000 ); 
  }


  mySerialPln ( "Next, connect to Blynk. \n" );  
  Blynk.config ( MY_BLYNK_AUTHCODE );
  Blynk.connect() ; 
  
  if ( Blynk.connected() ) 
  {
    mySerialPln ( "\nBlynk connected just fine. " ); 

#if ( USE_LITTLEFS )
    mySerialPln ( "Blynk using LittleFS." );
#else
    mySerialPln ( "Blynk using EEPROM." );
#endif  
  }
  else mySerialPln ( "Blynk NOT CONNECTED \n\n" );  
  
  mySerialPln();  
    
} // end connectToWLANandBlynk

Code piece 3 - my timer-driven WiFi and Blynk connection checker - runs every 5 minutes or so. This is the code I will modify to reboot after too many failed attempts at Blynk connection.

// Check on Blynk connection - reboot if not connected to WiFi
// Run on a timer so it doesn't keep executing
void checkBlynkAndWiFiConnections()
{
  mySerialPln(); 
  mySerialPln( "checkBlynkAndWiFiConnections called..." ); 

  if ( Blynk.connected() ) return;

  mySerialPln ( ">Blynk not connected... checking WiFi" );  
#if USE_IFTTT
  postToIFTTT ( "checkBlynkAndWiFiConnections WiFi ON - Blynk OFF" );
#endif
  if ( WiFi.status() == WL_CONNECTED ) return; // Blynk will reconnect by itself if WiFi is connected

  mySerialPln ( "->REBOOTING" ); delay ( 1000 ); 
  
  // Reboot to restart Wifi and Blynk reconnection sequence
  ESP.restart(); 
  
} // end checkBlynkAndWiFiConnections
2 Likes

I only started with Blynk in July and thought it was a good concept developing so I only followed up on Edgent for the OTA and provisioning etc. But with reconnect problems and connecting to wifi being a blocking function it makes me think.But its new and things will get ironed out over time I am sure. @steve1, I had 2 NodeMCUs that disconnected frequently from WIFI, nothing worked for me…until I simply replaced them and all was fine.
All my 6 devices with Edgent went down and stayed down after the server came back online, all ESP8266 based with different programs and some with different templates and dynamic tokens.
A software reset as I thought initially is no good since in Edgent everything basically stops in the programme so currently it would need a hardware watchdog.
Or has anyone tried the ESP32 dual core and tried running something like a logging function in the other core while Edgent waits to reconnect? I might make this a different topic.
Thanks for looking into it Dimitriy. Blynk is a nice looking product.

1 Like

Good day all.

Also in Aus and all of my devices went down.

I saw that they started broadcasting their SSID’s as per the initial Edgent setup process. A simple restart of each device solved the problem.

The interesting thing is that I’m not using the Edgent provisioning method or libraries as I hard code SSID, pass, names and authority tokens in each device. (multiple mcu’s on one blynk device).

Anyway all is well in this neighbourhood. Good to see that the simultaneous drop out of multiple devices was not something I did.

I am pretty new to the whole world of IOT and coding but have managed to find my way through the Blynk maze. I have had a few weird things happen with different boards, thinking it was me, only to find a new board with the same sketch worked fine.
I do like the Blynk platform and, when V2 came around, tried the Edgent wifi provisioning but went back to my OTA over HTTP with static provisioning. Edgent worked fine but I found the OTA approach was a bit more robust when I had issues with power failures, boards reconnecting to wifi but not the server (I do think this may be something to do with my router setup rather than the Blynk end although this server outage suggests there might be something at the Blynk end as well). If I can connect to the board via wifi (via a VPN), I can force a reboot by uploading the sketch again. I’m sure this could also be solved by coding.

Hey @thorathome,
Would love to see your server connection check and reboot code when you have had a chance to modify. I think this will solve some of my problems when I have power failures and boards connect to wifi again but not the server.
Cheers

Just wondering what the thought process is on preventing this in the future? I am working towards launching new products with Blynk (currently have a product on the old version), and my main concern after reading through this is the need to reset the device. The server issue of course is a problem (stuff happens), but having to ask customers to reset their devices isn’t great, especially if they are outside or not somewhere that can be easily accessed.

Is there something that can be done to make manual resetting not required if this happens again?

Thanks.

Happy to help @steve1. It took me some time to get to this.

Three pieces of code below, all for ESP8266 and ESP32. I use Arduino IDE.
I hope this is helpful.

1: set up timer for checking WiFi and Blynk connectivity using routine checkBlynkAndWiFiConnections

  • This is only a timer setup function, called once in void setup().
  • Timer interval of 3-5 minutes seems to work for me.
  • I always put in a slight randomization on the timer to keep multiple devices from always doing things at the same time.

2: routine checkBlynkAndWiFiConnections

  • Called periodically by interval timer (AND by connectToWLANandBlynk when no initial Blynk connection is found).
  • Check for WiFi connection, reboot ESP if no connection.
  • New code: Check for Blynk connection. If cannot find Blynk connection after 5 tries (after 5 timer cycles), reboot the ESP.

3: routine connectToWLANandBlynk to create initial WiFi and Blynk connections

  • Called only once in void setup()
  • First, connect to WiFi, reboot ESP after 5 tries.
  • Next, connect to Blynk. If no connection, call the checkBlynkAndWiFiConnections routine once to start the count. After 5 timer cycles with no Blynk connection, checkBlynkAndWiFiConnections will reboot the ESP.
  • This uses the ESP…WiFiMulti libraries, shown below with the code

Repeating descriptions below for the three code pieces.

1: set up timer for checking WiFi and Blynk connectivity using routine checkBlynkAndWiFiConnections

  • This is only a timer setup function, called once in void setup().
  • Timer interval of 3-5 minutes seems to work for me.
  • I always put in a slight randomization on the timer to keep multiple devices from always doing things at the same time.

Code starts here:

// Timer: Test if WiFi and Blynk are connected - reboot if not
#define CHECK_BLYNK_AND_WIFI_CONNECTIONS_INTERVAL 3 * 60 * 1000  // should be 3 minutes 3 * 60 * 1000
int checkBlynkAndWiFiConnectionsTimerID;



// SET UP BLYNK TIMERS FOR EVERYTHING
// call setupBlynkTimers from setup()
void setupBlynkTimers()
{
 // Check periodically to see if Blynk and WiFi are connected
  long randomizedInterval = CHECK_BLYNK_AND_WIFI_CONNECTIONS_INTERVAL + random ( -250, +250 );   // plus of minus quarter of a second
  Serial.print ( "... checkBlynkAndWiFiConnectedInterval = " ); Serial.println ( randomizedInterval );
  checkBlynkAndWiFiConnectionsTimerID = myTimer.setInterval ( randomizedInterval, checkBlynkAndWiFiConnections );   


  Serial.println ( "... Blynk timers set up." );  
  
} // end setupBlynkTimers

2: routine checkBlynkAndWiFiConnections

  • Called periodically by interval timer (AND by connectToWLANandBlynk when no initial Blynk connection is found).
  • Check for WiFi connection, reboot ESP if no connection.
  • New code: Check for Blynk connection. If cannot find Blynk connection after 5 tries (after 5 timer cycles), reboot the ESP.

Code starts here

// Check on Blynk connection - reboot if not connected
// Run on a timer so it doesn't keep executing

// Global variable
int blynkDisconnectedCount = 0; // Counts number of times in a row we find WiFi ON and Blynk OFF

void checkBlynkAndWiFiConnections()
{
  Serial.println(); 
  Serial.println( "checkBlynkAndWiFiConnections called..." ); 

  if ( WiFi.status() != WL_CONNECTED ) // Blynk will reconnect by itself if WiFi is connected
  {
    Serial.println ( "->REBOOTING" ); delay ( 1000 ); 
  
    // Reboot to restart Wifi and Blynk reconnection sequence
    ESP.restart(); //////////////////////////////////////////////////////////
  }
   
   
  if ( Blynk.connected() ) 
  {
    blynkDisconnectedCount = 0; // Reset any count we may have
    
    Serial.println ( "... all connected up nicely\n" ); 
    return; /////////////////////////////////////////////////////////////////
  }

  Serial.println ( "checkBlynkAndWiFiConnections WiFi ON - Blynk OFF" );  

  blynkDisconnectedCount++; 
  if ( blynkDisconnectedCount >= 5 ) // Reboot if WiFi is good and Blynk is off 5 times
  {
    Serial.println ( "->REBOOTING" ); delay ( 1000 ); 
  
    // Reboot to restart Wifi and Blynk reconnection sequence
    ESP.restart(); ////////////////////////////////////////////////////////
  }
} // end checkBlynkAndWiFiConnections

3: routine connectToWLANandBlynk to create initial WiFi and Blynk connections

  • Called only once in void setup()
  • First, connect to WiFi, reboot ESP after 5 tries.
  • Next, connect to Blynk. If no connection, call the checkBlynkAndWiFiConnections routine once to start the count. After 5 timer cycles with no Blynk connection, checkBlynkAndWiFiConnections will reboot the ESP.
  • This uses the ESP…WiFiMulti libraries, shown below with the code

Code starts here:

// This is WiFiMulti library selection for ESP32 or 8266
#define USE_SSL true // Always for primary Blynk connection
#if ESP8266
  #include <ESP8266WiFiMulti.h>
  ESP8266WiFiMulti wifiMulti;                    // set up the WiFi object
  const uint32_t connectTimeoutMs = 8000;        // timing for WiFiMulti testing connection
  #include <BlynkSimpleEsp8266_SSL.h>

#elif ESP32
  #include <WiFiMulti.h>
  WiFiMulti wifiMulti;                           // set up the WiFi object
  const uint32_t connectTimeoutMs = 5000;        // timing for WiFiMulti testing connection
  #include <BlynkSimpleEsp32_SSL.h> 
#endif



// Connects to MultiWiFi and to Blynk gracefully
// Call in void setup()
// Insert after BLYNK and WIFI_CREDENTIALS established
#define MY_WIFI_SSID       "WiFi SSID1"
#define MY_WIFI_PASSWORD   "SSID1 password"
#define MY_WIFI_SSID2      "WiFi SSID2"
#define MY_WIFI_PASSWORD2  "SSID2 password"
#define MY_BLYNK_AUTHCODE  "ehiowuneikekn"



void connectToWLANandBlynk()  // No more Blynk_WM.
{
  WiFi.persistent ( false ); // Don't save anything in EEPROM or LittleFS 
  WiFi.mode ( WIFI_STA );    // Station mode

  
  // Register multi WiFi networks
  wifiMulti.addAP ( MY_WIFI_SSID,  MY_WIFI_PASSWORD );
  wifiMulti.addAP ( MY_WIFI_SSID2, MY_WIFI_PASSWORD2 );


  int WiFiTries = 0; 

  // Test for WiFi connectivity. Reboot after 5 tries. 
  while ( wifiMulti.run ( connectTimeoutMs ) != WL_CONNECTED ) 
  {
    WiFiTries++; 
    Serial.println ( "WiFi not connected... #" ); Serial.println ( WiFiTries ); 
    if ( WiFiTries >= 5 )
    {
      Serial.println ( "RESTARTING!\n\n" );  
      delay ( 5000 ); 
      ESP.restart(); 
    }
    delay ( 2000 ); // delay is ok for OTA and Blynk prior to WiFi connection
  }
  
  Serial.println ( "WiFi connected just fine to ");
  Serial.println ( WiFi.SSID() ); mySerialP ( " at " ); mySerialPln ( WiFi.localIP() );


  Serial.println ( "Next, connect to Blynk. \n" );  
  Blynk.config ( MY_BLYNK_AUTHCODE );
  Blynk.connect() ; 
  
  if ( Blynk.connected() ) 
  {
    Serial.println ( "\nBlynk connected just fine. " ); 
  }
  
  else 
  {
    Serial.println ( "Blynk NOT CONNECTED \n\n" );  
    
    checkBlynkAndWiFiConnections();  // Start the Blynk-not-connected recovery sequence (timer will check again in a few minutes)
  }
  
  Serial.println();
    
} // end connectToWLANandBlynk
1 Like

@vshymanskyy investigating that. If that could be fixed with the Blynk firmware - it will be fixed. However, it could be a hardware bug, or esp core bug, etc. So we’ll see. We need more time to find the real root cause. Hardware is hard :).

I think that programming an automatic reboot into the code will work. I have always checked periodically for WiFi connectivity, forcing a reboot if WiFi remains persistently disconnected. I now ALSO test for Blynk connectivity AFTER I check for WiFi connectivity. If Blynk remains persistently disconnected with WiFi connected, I now force a reboot of my ESP devices.

Hopefully, this will eliminate the need to manually reboot anything. We will see.

Hi @thorathome,
many thanks for the code. Really appreciate it. I had a play based on yours which just looks at the server connection (I rarely if ever have had wifi connection issues - and I’ve probably just jinxed myself :rofl:)
My code just uses a timer rather than a disconnection count. I’ve used 15 mins as my app isn’t that critical if offline for that long and my modem can take a while to reboot (power failure has been the main source of my server connection problems).
In setup I initialise a timer

timer.setInterval(900000L, blynkReconnect);

and then the routine

void blynkReconnect()  // Routine to check blynk server connection status
{
  Serial.println("Checking server connection");
  if (Blynk.connected() == false) //check whether blynk is connected to server.  if not, reset board
  {
    Serial.println("Server not connected - resetting board");
    ESP.restart();
  delay(1000);
  }
  else {
    Serial.println("Server connection OK");
  }
}

The check works ok but I haven’t tested yet with a simulated power failure. Only thing I was wondering was whether my initial connection code might be problematic. I suspect the loops may stop the timers and hence the connection check being initiated. I’ll do a few tests to confirm. My initial connection code is:

WiFi.config(arduino_ip, dns_ip, gateway_ip, subnet_mask);
  WiFi.begin(ssid, pass);
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin(ssid, pass);
    delay(1000);
  }

  Blynk.config(auth, "ny3.blynk.cloud", 8080);
  if (Blynk.connected() == false) //wait for Blynk to connect before proceeding
  {
    Blynk.config(auth, "ny3.blynk.cloud", 8080);
    delay(1000);
  }

Cheers
Steve

Thanks for sharing code, @steve1

I have not made the effort to see what happens to Blynk timers when sitting in a WiFi reconnect loop. I do not start my Blynk timers until an initial WiFi connection is reached. Because I use OTA and Blynk, I try to avoid delay(x); commands, relying on Blynk timers, instead. For the Blynk reconnect loop while WiFi is connected, I use Blynk timers exclusively to avoid those delay(x); statements. The exceptions I make are in the WiFi connect loop like you do, and just prior to a reboot in the hopes that I’ll see the Serial.print.

In general, I do find that any WiFi disconnects usually result in rebooting which starts all the Blynk timers again anyway.

Not shown in my code is IFTTT. I use IFTTT for performance monitoring of all my Blynk apps. If anything of significance, positive or negative, happens to one of my apps, it tells IFTTT which writes an entry to a google sheet. Having that record of app startups, significant changes, and critical errors is very helpful especially with these devices running in the wild.

The recent long Blynk outage caused me to send a huge number of messages to IFTTT, which this rewrite cures.

I want my code to be cleaner, separating the WiFi connect loop from the Blynk connect loop, but the code I posted works. My IFTTT logs indicate that the Blynk servers go offline pretty frequently, although not for long, so the software has to manage those interruptions.

Hope all this is helpful. I appreciate seeing how you solve these same issues. Thanks.

Great! Thanks for answering. And yes it is hard… and annoying haha.

Hi @thorathome,
Many thanks for the response. As an absolute non-coder, these tips are great to help me learn all this IOT coding stuff. I did a power failure test today, restarting my modem and boards (ESP8266). Got the same initial response where the boards connected to wifi but not to the server. Serial monitor indicated that the connection loops I was concerned about didn’t seem to block the remainder of the code running.
Waited 15 mins and VOILA - reset kicked in and all is good. I will transfer this code to all my boards as a standard going forward.

Cheers
Steve

Fighting issues in USA… can’t figure out if it is mods to code or if the blynk servers are intermittent… for Blynk IOT
The statement below is hanging. Sometimes returning… sometimes hanging and never returning.
Might be nice to have a status window available on the web that shows the health of each blynk server and whether up or down.

Blynk.begin(BLYNK_auth, WiFi_ssid, WiFi_pass,"blynk.cloud",80);

Was my software, the dreaded fixed IP loosing DNS… so all on my end.

But it might be good to have an online status of blynk cloud health sometime in the future?