Invalid auth token message

Trying to migrate to Blynk 2.0. sorry to revive this old post but it fit my problem very closely. Thanks for reading.

Does this serial printout mean that I’m trying to connect to the legacy server?
I put at top of code:
#define BLYNK_TEMPLATE_ID “TMPLSz4tFC6X”
#define BLYNK_DEVICE_NAME “Quickstart Device”

serial printout:

3: FiOS-SO2CY 	Signal -86 dBm 	Encryption type: 4	Channel: 11

Attempting to connect to Network named: FiOS-SO2CY Westwood
Reason code: Connected
After 1 try,  Wifi is connected to ssid = FiOS-SO2CY at Westwood
IP Address assigned by router to Vacuumouse: 192.168.1.174
[12948] IP: 192.168.1.174
[12977] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino UNO WiFi Rev2

[13148] Connecting to blynk-cloud.com:80
[17110] Invalid auth token
[31147] Connecting to blynk-cloud.com:80
[31201] Invalid auth token

Code:

/*************************************************************

  This is a simple demo of sending and receiving some data.
  Be sure to check out other examples!
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
// Comment this out to disable prints and save space

#define BLYNK_TEMPLATE_ID           "TMPLSz4tFC6X"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_PRINT Serial
#define BLYNK_AUTH_TOKEN            "rKXfxxxxxxxx"
//                                   rKXfxxxxxxxxxx



#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
//#include <BlynkSimpleEthernet.h>
#include <WiFiNINA.h>
#include <SPI.h>
#include <BlynkSimpleWifi.h> //May need to install this library


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress googleDNS(8, 8, 8, 8); // google's primary DNS
const int timeZone = -5;  // Eastern Standard Time (USA)
//const int timeZone = -4;  // Eastern Daylight Time (USA)
EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

char auth[] = BLYNK_AUTH_TOKEN;

//#define W5100_CS  10
//#define SDCARD_CS 4
#define wifiLED 2  // The wifi LED is on digital pin 2 through a 2.7k ohm resistor to ground  HIGH will illuminate it.

//  WiFi credentials.
// Set password to "" for open networks.
char ssid[30] = "FiOS-SO2CY";  //initialize variables but not used.  alt0-2 are used below
char pass[30] = "delucawifi21";
char location[20] = "Westwood";
const int NUMBER_OF_LOCATIONS = 8; // change this to add locations and add location's ssid, pass, location text string
const int MAX_SIZE = 30;
int status = WL_IDLE_STATUS;  //sets the wifi status to its initial state
//----------------------------- Enter all known wifi credentials and location descriptions here ----------------------
// For future consideration, put this data into a separate header file for privacy if you ever wanted to share this code without disclosing wifi credentials.
int locIndex = 0;  // locaton index is used to index into the char array for ssid, pass and locDesc of each location
char locDesc [NUMBER_OF_LOCATIONS] [MAX_SIZE] = { // description of locations
  { "Westwood" },   // 0 locIndex V7
  { "Brownfield" }, // 1  V9
  { "Norwood" },     // 2  V8
  { "Nottingham" },     // 3  V10 "Nottingham" includes both David's house and the Lake because the ssids and passwords are the same
  { "Dedham-Erick" },  // 4  V11
  { "Sue DeLuca's iPhone" },    // 5 V12 is shared use only one at a time
  { "Dana's iPhone" },    // 6  V12
  { "Sherborn Diana's" }    // 7  V12
  
};
char altssid [NUMBER_OF_LOCATIONS] [MAX_SIZE]  = { // PUT ALL THE SSIDs HERE
  { "FiOS-SO2CY" },        // 0 Westwood locIndex
  { "CAMP" },    // 1 Brownfield locIndex
  { "Kevin1" },        // 2 Norwood locIndex
  { "Joyce" },     // 3 Nottingham locIndex
  { "Atitlan-V" },     // 4 Udi and Erick house
  { "Sue DeLuca's iPhone" },       // 5 Sue's phone as a wifi hotspot
  { "Dana's iPhone" },       // 6 Dana's phone as a wifi hotspot
  { "FeathersFinest.2.4" }    // 7
  
};
char altpass [NUMBER_OF_LOCATIONS] [MAX_SIZE]  = { // PUT ALL THE PASSWORDS HERE
  { "xxx" },        // 0 westwood
  { "xxx" },       // 1 brownfield
  { "xxx" },  // 2 norwood corrected in vers 1.82
  { "xxx" },       // 3 Nottingham
  { "xxx-para-Llevar" },       // 4
  { "xxx" },       // 5  
  { "xxx" },       // 6  to add any, don't forget the comma(,) after the next to last one
  { "xxxxx"}        // 7
};
//--------------------------------End of wifi credentials -----------------------------------------------------------------------

BlynkTimer timer;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  // Set incoming value from pin V0 to a variable
  int value = param.asInt();

  // Update state
  Blynk.virtualWrite(V1, value);
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.print(" Started up. "); Serial.print(millis()); Serial.println(" ms elapsed time");
  //pinMode(SDCARD_CS, OUTPUT);
  //digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  pinMode(wifiLED, OUTPUT); // pin 2 driving the LED is an output and is normally low.  Used to control the green wifi LED.
  digitalWrite(wifiLED, LOW); // initialize the LED off

 Serial.println("Start WiFi scan of neighborhood ");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n); Serial.println(" WiFi networks found in the neighborhood.");
    for (int i = 0; i < n; i++) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" \tSignal ");
      Serial.print(WiFi.RSSI(i));
      Serial.print(" dBm \tEncryption type: ");
      Serial.print(WiFi.encryptionType(i));
      Serial.print("\tChannel: ");
      Serial.println(WiFi.channel(i));
      /*Type of Encryption
          TKIP (WPA) = 2
          WEP = 5
          CCMP (WPA) = 4
          NONE = 7
          AUTO = 8 */
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(3000);

  int i = 0; // used to count while loop executions/  int could wrap and overflow which is undefined but it's only number of wifi locations
  int pingResult[6];
  //--------------------------------------- scan all known wifi networks  -------------------
  while (status != WL_CONNECTED) {
    locIndex = i % NUMBER_OF_LOCATIONS;  // cycles thorugh all known locations
    // try all known networks sequentially one at a time
    // i increments once every time through the while loop
    strcpy(ssid, altssid[locIndex]);   // try each alternative network
    strcpy(pass, altpass[locIndex]);   //
    strcpy(location, locDesc[locIndex]);  // record of our location retained when connected
    Serial.print("Attempting to connect to Network named: ");
    Serial.print(ssid);  Serial.print(" "); Serial.println (locDesc [locIndex]);
    WiFi.end();  // if connected, then disconnect.
    // WiFi.mode(WIFI_STA); // SETS TO STATION MODE!
    status = WiFi.begin(ssid, pass);
    Serial.print("Reason code: ");
    if (WiFi.reasonCode() == 0) {
      Serial.println("Connected");
      digitalWrite(wifiLED, HIGH); // illuninate wifi LED to indicate we are connected to a wifi network
    } else {
      Serial.print("Failed to connect because of reason code: ");
      Serial.println(WiFi.reasonCode());
    } //end of else
    delay(000); //why? reduced to 1s in 1.97.  As we increase known wifi networks to hunt for, this delays the find.
    i++;
  } // end of while loop
  
  Serial.print("After "); Serial.print(i); if( i == 1) Serial.print(" try, ");  else Serial.print(" tries, "); Serial.print(" Wifi is ");
  Serial.print("connected to ssid = "); Serial.print(ssid); Serial.print(" at "); Serial.println(location); // at this point is ssid current? Yes.
  //Serial.println(WiFi.SSID()); // redundant because ssid above is current
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address assigned by router to Vacuumouse: "); Serial.println(ip); // Print the IP address that the LAN router has assigned the Arduino


  //Blynk.begin(auth);
 // partly worked  Blynk.begin(auth, ssid, pass);  // but Invalid auth token

 //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  // You can also specify server:
  Blynk.begin(auth, "blynk.cloud", 80);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

I’ve split this into a new topic (again - you really should start your own topics and if necessary link to other potentially relayed ones if appropriate) because although your error message is the same, the cause is different.

Yes

You’re using the old version of the C++ library, you need to upgrade to 1.x.x

As you’re still using the old horse-drawn cart technology (AKA Arduino UNO WiFi Rev2) you’ll need to modify the 1.x.x library as described here…

to manually fix a bug relating to this board which hasn’t been resolved yet in the current release.

I’d also strongly suggest that you stop doing this…

and use Blynk.begin(auth); instead. However, as I’ve previously discussed in your other topic, you should really stop using Blynk.begin when you are managing your own network connection and instead use Blynk.config and Blynk.connect instead.

For your first attempt at using Blynk IoT I’d really recommend that you use a simple example sketch and get that working, then move on to something more complex, especially with this hardware.

Pete.

I’ve followed @Andyy 's instruction to modify the BlynkParam file and changed atoll to atol.
I cannot figure out how to add the modified file to the Arduino web editor Blnyk 1.1.0 library. I get an error saying that only .ino and one other type of file can be uploaded. .zip will not work. The file now is a .txt. How do I convert it to a file amenable to upload?

Thanks,
-Dana

I’d always recommend a local install of the IDE, or a portable install on removable media if you need to edit your files on multiple PCs.

You can’t simply change the file extension from .h to .txt - the compiler will be looking for a .h file and will terminate the compilation if the necessary file can’t be found.

Pete.

Pete,
I got to tell you… my horse and buggy UNO is online with the new server!
Moved to the local IDE as you suggested. Installed the modified library, changed from Blynk.begin to Blynk.configure and Blynk.connectWIFI, not to mention the other things you helped with. So thank-you. I’m glad that we have a such a resource as you.
It has not been able to sustain connectivity for more than 300 seconds, so that’s my next challenge but at least it connected a few times.

20:40:40.851 ->  Started up. 0 ms elapsed time
20:40:40.851 -> Start WiFi scan of neighborhood 
20:40:45.845 -> scan done
20:40:45.845 -> 8 WiFi networks found in the neighborhood.
20:40:45.925 -> 1: FiOS-SO2CY 	Signal -37 dBm 	Encryption type: 4	Channel: 11
20:40:45.965 -> 2: fatboyjackPOSXfin 	Signal -75 dBm 	Encryption type: 4	Channel: 6
20:40:46.045 -> 3: NETGEAR79 	Signal -77 dBm 	Encryption type: 4	Channel: 1
20:40:46.125 -> 4: FiOS-SO2CY 	Signal -79 dBm 	Encryption type: 4	Channel: 11
20:40:46.165 -> 5: Fios-fP6e3 	Signal -91 dBm 	Encryption type: 4	Channel: 1
20:40:46.245 -> 6: Verizon_L7BYFY-IoT 	Signal -93 dBm 	Encryption type: 4	Channel: 11
20:40:46.325 -> 7: SullySuperWireless 	Signal -93 dBm 	Encryption type: 4	Channel: 11
20:40:46.405 -> 8: RubyDoo 	Signal -95 dBm 	Encryption type: 4	Channel: 11
20:40:46.445 -> 
20:40:49.396 -> Attempting to connect to Network named: FiOS-SO2CY Westwood
20:40:53.397 -> Reason code: Connected
20:40:53.397 -> After 1 try,  Wifi is connected to ssid = FiOS-SO2CY at Westwood
20:40:53.477 -> IP Address assigned by router to Vacuumouse: 192.168.1.174
20:40:53.557 -> [12685] 
20:40:53.557 ->     ___  __          __
20:40:53.597 ->    / _ )/ /_ _____  / /__
20:40:53.597 ->   / _  / / // / _ \/  '_/
20:40:53.637 ->  /____/_/\_, /_//_/_/\_\
20:40:53.678 ->         /___/ v1.1.0 on Arduino UNO WiFi Rev2
20:40:53.717 -> 
20:40:53.717 ->  #StandWithUkraine    https://bit.ly/swua
20:40:53.758 -> 
20:40:53.758 -> 
20:40:53.758 -> [12905] IP: 192.168.1.174
20:40:53.797 ->  Blynk Not Connected 
20:40:53.797 -> [12957] Connecting to blynk.cloud:80
20:40:53.838 -> [13060] Ready (ping: 27ms).
20:45:42.614 -> [302954] Heartbeat timeout
20:45:42.654 -> [302956] Connecting to blynk.cloud:80
20:45:48.660 -> [309018] Login timeout
20:45:48.700 -> [309020] Connecting to blynk.cloud:80
20:46:17.012 -> [337474] Connecting to blynk.cloud:80
20:46:24.968 -> [345454] Ready (ping: 1938ms).
20:49:08.774 -> [509905] Heartbeat timeout
20:49:08.814 -> [509907] Connecting to blynk.cloud:80
20:49:31.627 -> [532848] Ready (ping: 5122ms).
20:50:34.999 -> [596472] Heartbeat timeout
20:50:35.039 -> [596474] Connecting to blynk.cloud:80
20:50:39.008 -> [600484] Ready (ping: 3985ms).

Here’s the code now.


/*************************************************************

  This is a simple demo of sending and receiving some data.
  Be sure to check out other examples!
 *************************************************************/

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
// Comment this out to disable prints and save space

#define BLYNK_TEMPLATE_ID           "TMPLSz4tFC6X"
#define BLYNK_DEVICE_NAME           "Quickstart Device"

#define BLYNK_PRINT Serial
//#define BLYNK_AUTH_TOKEN            "fqb-xx-0f"
#define BLYNK_AUTH_TOKEN            "rKXfxxx"
//                                  



#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
//#include <BlynkSimpleEthernet.h>
#include <WiFiNINA.h> //works
#include <SPI.h>
#include <BlynkSimpleWifi.h> //May need to install this library worked except invalid auth
// Blynk - Version: 1.1.0
#include <Blynk.h>



byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress googleDNS(8, 8, 8, 8); // google's primary DNS
const int timeZone = -5;  // Eastern Standard Time (USA)
//const int timeZone = -4;  // Eastern Daylight Time (USA)
EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

char auth[33] = BLYNK_AUTH_TOKEN;

#define wifiLED 2  // The wifi LED is on digital pin 2 through a 2.7k ohm resistor to ground  HIGH will illuminate it.

//  WiFi credentials.
// Set password to "" for open networks.
char ssid[30] = "FiOS-SO2CY";  //initialize variables but not used.  alt0-2 are used below
char pass[30] = "delucawifi21";
char location[20] = "Westwood";
const int NUMBER_OF_LOCATIONS = 8; // change this to add locations and add location's ssid, pass, location text string
const int MAX_SIZE = 30;
int status = WL_IDLE_STATUS;  //sets the wifi status to its initial state
//----------------------------- Enter all known wifi credentials and location descriptions here ----------------------
// For future consideration, put this data into a separate header file for privacy if you ever wanted to share this code without disclosing wifi credentials.
int locIndex = 0;  // locaton index is used to index into the char array for ssid, pass and locDesc of each location
char locDesc [NUMBER_OF_LOCATIONS] [MAX_SIZE] = { // description of locations
  { "Westwood" },   // 0 locIndex V7
  { "Brownfield" }, // 1  V9
  { "Norwood" },     // 2  V8
  { "Nottingham" },     // 3  V10 "Nottingham" includes both David's house and the Lake because the ssids and passwords are the same
  { "Dedham-Erick" },  // 4  V11
  { "Sue DeLuca's iPhone" },    // 5 V12 is shared use only one at a time
  { "Dana's iPhone" },    // 6  V12
  { "Sherborn Diana's" }    // 7  V12
  
};
char altssid [NUMBER_OF_LOCATIONS] [MAX_SIZE]  = { // PUT ALL THE SSIDs HERE
  { "FiOS-SO2CY" },        // 0 Westwood locIndex
  { "CAMP" },    // 1 Brownfield locIndex
  { "Kevin1" },        // 2 Norwood locIndex
  { "Joyce" },     // 3 Nottingham locIndex
  { "Atitlan-V" },     // 4 Udi and Erick house
  { "Sue DeLuca's iPhone" },       // 5 Sue's phone as a wifi hotspot
  { "Dana's iPhone" },       // 6 Dana's phone as a wifi hotspot
  { "FeathersFinest.2.4" }    // 7
  
};
char altpass [NUMBER_OF_LOCATIONS] [MAX_SIZE]  = { // PUT ALL THE PASSWORDS HERE
  { "xx" },        // 0 westwood
  { "xx" },       // 1 brownfield
  { "xx" },  // 2 norwood corrected in vers 1.82
  { "xx" },       // 3 Nottingham
  { "xx-para-Llevar" },       // 4
  { "xx" },       // 5  
  { "xx" },       // 6  to add any, don't forget the comma(,) after the next to last one
  { "xx"}        // 7
};
//--------------------------------End of wifi credentials -----------------------------------------------------------------------

BlynkTimer timer;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  // Set incoming value from pin V0 to a variable
  int value = param.asInt();

  // Update state
  Blynk.virtualWrite(V1, value);
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.print(" Started up. "); Serial.print(millis()); Serial.println(" ms elapsed time");

  pinMode(wifiLED, OUTPUT); // pin 2 driving the LED is an output and is normally low.  Used to control the green wifi LED.
  digitalWrite(wifiLED, LOW); // initialize the LED off

 Serial.println("Start WiFi scan of neighborhood ");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n); Serial.println(" WiFi networks found in the neighborhood.");
    for (int i = 0; i < n; i++) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" \tSignal ");
      Serial.print(WiFi.RSSI(i));
      Serial.print(" dBm \tEncryption type: ");
      Serial.print(WiFi.encryptionType(i));
      Serial.print("\tChannel: ");
      Serial.println(WiFi.channel(i));
      /*Type of Encryption
          TKIP (WPA) = 2
          WEP = 5
          CCMP (WPA) = 4
          NONE = 7
          AUTO = 8 */
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(3000);

  int i = 0; // used to count while loop executions/  int could wrap and overflow which is undefined but it's only number of wifi locations
  int pingResult[6];
  //--------------------------------------- scan all known wifi networks  -------------------
  while (status != WL_CONNECTED) {
    locIndex = i % NUMBER_OF_LOCATIONS;  // cycles thorugh all known locations
    // try all known networks sequentially one at a time
    // i increments once every time through the while loop
    strcpy(ssid, altssid[locIndex]);   // try each alternative network
    strcpy(pass, altpass[locIndex]);   //
    strcpy(location, locDesc[locIndex]);  // record of our location retained when connected
    Serial.print("Attempting to connect to Network named: ");
    Serial.print(ssid);  Serial.print(" "); Serial.println (locDesc [locIndex]);
    WiFi.end();  // if connected, then disconnect.
    // WiFi.mode(WIFI_STA); // SETS TO STATION MODE!
    status = WiFi.begin(ssid, pass);
    Serial.print("Reason code: ");
    if (WiFi.reasonCode() == 0) {
      Serial.println("Connected");
      digitalWrite(wifiLED, HIGH); // illuninate wifi LED to indicate we are connected to a wifi network
    } else {
      Serial.print("Failed to connect because of reason code: ");
      Serial.println(WiFi.reasonCode());
    } //end of else
    delay(000); //why? reduced to 1s in 1.97.  As we increase known wifi networks to hunt for, this delays the find.
    i++;
  } // end of while loop
  
  Serial.print("After "); Serial.print(i); if( i == 1) Serial.print(" try, ");  else Serial.print(" tries, "); Serial.print(" Wifi is ");
  Serial.print("connected to ssid = "); Serial.print(ssid); Serial.print(" at "); Serial.println(location); // at this point is ssid current? Yes.
  //Serial.println(WiFi.SSID()); // redundant because ssid above is current
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address assigned by router to Vacuumouse: "); Serial.println(ip); // Print the IP address that the LAN router has assigned the Arduino


 //Blynk.begin(auth);
//Blynk.begin(auth, ssid, pass);  // but Invalid auth token
Blynk.config(auth,  "blynk.cloud", 80);  // but 
 //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  // You can also specify server:
 // Blynk.begin(auth, "blynk.cloud", 80);  // also throws Invalid auth token
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
  
Blynk.connectWiFi(ssid, pass);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  
  if(Blynk.connected()) Serial.println(" Blynk connected "); else Serial.println(" Blynk Not Connected ");
}

void loop()
{
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Do you have a valid reason for including each of these library files?
If so, could you explain what each one is for please?

Why would you go to all of the trouble of creating a working WiFi connection, then use Blynk.connectWiFi to create another WiFi connection? As your board can’t support two simultaneous connections, this will either terminate your existing connection, or do nothing (except possibly confuse the Blynk library about witch transport method it is supposed to be using).

If you re-read what I’ve said before, you won’t find me recommending this approach.

Once you have an active internet connection and use Blynk.config(auth) the first execution of Blynk.run() should create the Blynk connection. However, I always prefer to use Blynk.conect() to trigger that initial connection in void setup, rather than allowing it to be created in the void loop. It’s cleaner to my mind, and also allows you to specify an optional timeout.

Pete.

Hi Pete,
SPI.h is for the on-board serial interface, which I used when I had a RTC on board and a 2x16 digital display. Figured they were harmless so left them in case I wanted to add RTC to my hardware, but currently don’t have. The fact it’s included twice is an oversight.
ethernet.h and ethernet.udp were part of the sample sketch I started with. I wanted to use ping and didn’t know if I needed UDP to support ping so when in doubt, I added it. Communication is via wifi but wifi ends up on ethernet so figured I needed ethernet too.
WiFiNINA.h is the library that supports Arduino Uno’s use of the NINA chip for wifi.
BlynkSimpleWifi.h Without this, sketch fails to compile giving ‘Blynk not declared in this scope’

'Why would you go to all of the trouble of creating a working WiFi connection, then use Blynk.connectWiFi to create another WiFi connection? ’

When I switch from Blynk.begin() to Blynk.config() and Blynk.connect() I thought since I was connecting over wifi that I would need Blynk.connectWiFi and didn’t know it would try to create another WiFi connection. Indeed, eliminating this in favor of a simple Blynk.connect() vastly improves performance. Yet the app still quits after 300 seconds of uptime. I added a serial print of upTime to the timer function and see that it does keep going. So, the device is actually still online and connected. The app indicates the device is online too, but the virtualWrite(V2) of upTime stops refreshing at 300. It’s as if there were a maximum value set somewhere. It always stops at 300. Meanwhile the serial prints I added keep going and a check of connection status remains affirmative.
One other anomaly: There is a banner on the app that says,

Now go to your computer.  Check your inbox for the code and instructions on how to get your device online.

I have long since retrieved that email which supplied the auth code for the Quickstart Device and got the device online. Don’t know why the banner persists.

Interestingly, although now connected to the Blynk 2.0 server and although now using the simple code of the Quickstart Device, the frequency of disconnects is about the same. In 6138 seconds, it disconnected and reconnected 3 times.
Thinking out loud… What didn’t change when I migrated? My hardware for one. What type of HW fault would cause a Blynk disconnect? A WiFi failure but there’s no evidence of that. A violation of Blynk rules but there’s no evidence of that either, except the disconnect event itself. A heartbeat timeout but there’s no report of that.

How do I check for disconnects? In a 60-sec timer.

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  unsigned long int upTime = millis() / 1000;
  Blynk.virtualWrite(V2, upTime);
  Serial.print(" Uptime is: "); Serial.println(upTime);
  if(Blynk.connected()) {Serial.println(" Blynk connected ");
  Serial.print("Reconnected "); Serial.print(reconnectTimes); Serial.println(" times.");
  }
  else {
    Serial.println(" Blynk Not Connected "); 
    Serial.println(" Attempting to reconnect... ");
    reconnectTimes++; 
  }
}

I’m not familiar with your hardware, as you know, but this statement seems so wrong to me on so many levels.

As I’ve said earlier…

Once you have a very simple Blynk sketch working, and staying connected, then use this as the basis for your more advanced sketch. But don’t just add additional libraries in to your more complex version, unless you’re 100% certain that they are needed.

I’ve said all along that you should shoot the horse and burn the cart, but I suspect that the real answer is what you’re doing with all these strange libraries, most of which I’m convinced aren’t needed and could well be causing issues. Using the hardware with a simple Blynk demo sketch should prove that the hardware is not at fault.
However, if you still have the issue then id start by looking at the power supply.
Also, have you tested this on one of your other WiFi networks, as it could be an ISP, internet or router issue.

Pete.

I would shoot and burn it, but I have invested a lot of time and energy designing and building the hardware into which the UNO board is embedded. And there are seven in existence. If I scale up, it will be with a new board.

I did start with a very simple Blynk sketch. It’s one of the given Quickstart Blynk test device code samples. Except for the extra libraries (which I’ve mostly eliminated see below), the code is pretty simple.

#include <WiFiNINA.h> 
#include <BlynkSimpleWifi.h> 
// Blynk - Version: 1.1.0
#include <Blynk.h>

The only code that could be considered non-trivial is the wifi connection initialization which uses the wifi libraries, and it’s all in setup(). It’s over before we connect to Blynk server.

The void loop has just the Blynk.run and timer.run. And the timer sends uptime to V2 which was p/o the sample code. Nothing else happens. I even deleted the portion of the sample code that mirrored back the incoming state of an app button V0 and writes it out to a button value widget V1. The only added code is to count the disconnects, so that I know, for example just now it disconnected twice in 914 seconds.

I have tried the old code with legacy Blynk on three different wifi networks with the same periodic disconnect result.

The work-around which I can probably live with, is to detect disconnect and reconnect. I have a device 150 miles away from me in Maine, running the old code with legacy Blynk, and that’s what it does. And just to make sure a router hang-up doesn’t take it down, the router is on a timer that powers the router down for one minute every 24 hrs thus rebooting the router. It’s been up and running like that for over a month, surviving disconnects and not-that-infrequent utility power outages.

That’s far from ideal in my mind. You don’t get a proper choice of hardware options with Quickstart so it doesn’t really help to guide you to the correct libraries.

If you look at the list of supported boards for Blynk it says this:

  • Arduino UNO WiFi Rev.2 (use the example for MKR WiFi 1010)

If you go to Examples/Blynk/Boards_WiFi/Arduino_MKR1010 then the sketch there uses these three libraries

#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>

Not really, the Blynk.begin command in void setup is where the connection to the Blynk server takes place.

Pete.