Converting from Blynk Legacy to Blynk 2.0 - Device cycles through on-line/off-line

Hi,
I have need for a support, if anyone can share few minutes of their time.

I have had devices connected to Blynk Legacy since early 2017 and now I am trying convert to Blynk 2.0 without full success.

I have used and have in hand the bad reputation Robotdyn Uno with combined ESP8266 board, using Hardware Serial communication between the UNO and ESP8266 part.
They have worked fine with Blynk Legacy, after steep learning curve in the beginning.

To start with, my aim was only to get connection and therefore used the QuickStart code which the Blynk supplies.
In addition to the code supplied in the example, I needed to add the Hardware serial communication between the UNO and the ESP8266.
The ESP8266 contains the standard firmware and is unchanged from the Blynk Legacy setup.
It answers AT message and I have confirmed it has ip-number and I have tried using baud rate from 9600 to 115200.

I have used the very good instruction from Pete on the serial communication in the FAQ:

Which are in line fully rhymes with what I found out when I started to use boards of this kind.

The issue I have is that the board goes online for 9 seconds and then goes offline for 26 seconds.
Always the same time sequence.
It though never connects as the uptime never increases.
My thought is that the board re-boots for some reason or is thrown off the server.

Using:
IDE 2.0.3
Blynk library 1.1.0
ESP8266_Lib.h from 2016
ESP8266 Firmware version: 1.4.0.0

Following is the code I try to run:

/*************************************************************
  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
#define BLYNK_TEMPLATE_ID           "TMPLAIhuZiTj"
#define BLYNK_DEVICE_NAME           "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "************"


// Comment this out to disable prints and save space
//#define BLYNK_PRINT Serial // Defines the object that is used for printing
//#define BLYNK_DEBUG        // Optional, this enables more detailed prints

//Works with Blynk Legacy and now but cuts off
#include <SPI.h>
#include <ESP8266_Lib.h> //Was used with Blynk legacy
#include <BlynkSimpleShieldEsp8266.h> //Was used with Blynk legacy

BlynkTimer timer; // Create a timer object

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "********"; // Access point name
char pass[] = "*******"; // Your WiFi credentials. Set password to "" for open networks.


//____________________________________________________
// Serial setup
//____________________________________________________
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX


#define EspSerial Serial //For Uno with Uno to ESP8266 through Hardware serial

//#define ESP8266_BAUD 115200 // Define your ESP8266 baud rate --> Worked in Temp sketch on Legacy
//#define ESP8266_BAUD 57600
#define ESP8266_BAUD 115200
//#define ESP8266_BAUD 9600 //Check this speed

ESP8266 wifi(&EspSerial); // Tell the Blynk library to use the HardwareSerial port for WiFi..

// 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");
}

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

void setup()
{
  EspSerial.begin(ESP8266_BAUD);   // Set ESP8266 baud rate
 
   delay(10);
 
  Blynk.begin(auth, wifi, ssid, pass);
 
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

}

void loop()
{
  Blynk.run();
  timer.run(); // runs the timer in the loop
  // 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!
}

Are the Serial libraries I use wrong if using Blynk 2.0?
The QuickStart code, when Arduino and Wi-Fi is chosen, shows libraries:

#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>

Which do not compile with my code.

The instruction from Pete show libraries:

#include<ESP8266_Lib.h>
#include<BlynkSimpleShieldEsp8266.h>

Which are the ones I used for Blynk Legacy.

The QuickStart code uses for Blynk connection :

Blynk.begin(auth, ssid, pass);

But the code from Pete uses:

Blynk.begin(auth, wifi, ssid, pass);

Does this matter?

If you have a sketch which works with your hardware and Blynk Legacy then why don’t you simply use that sketch with Blynk IoT.
In most cases you’ll simply need to create a template and a device from that template, to give you the three lines of code to add to the top of your existing sketch.

Pete.

Hi Pete,
Thanks for taking the time to reply.
I actually did what you suggest but did not mention it.
That gave same result and then I thought that more changes were needed and went back to beginning with the QuickStart.
Based on you answer I presume that the serial setup is ok and can be the same as in Blynk Legacy.

These are the messages the Uno is sending to ESP:

AT+CIPSTART=1,“TCP”,“blynk.cloud”,80
AT+CIPCLOSE=1
AT+CIPCLOSE=1
AT+CIPSTART=1,“TCP”,“blynk.cloud”,80
AT+CIPCLOSE=1

Bjorgvin

TBH, I have no idea.

Based on what you’re saying, your Legacy setup used the ESP-01 connected to the Serial port rather than to a SoftwareSerial port. That has the disadvantage of preventing you seeing any serial debug messages, and without that information it’s difficult to say what’s going wrong.

Pete.

Thanks Pete,
You are correct. Uno with Hardware communication with ESP.
No way to see the Serial communication for debugging.
Self-inflicted terror with the choice of board, but used as it sounded good idea at the time of purchase and worked after steep curve in the beginning.

I though found out what was the issue.

This part of the QuickStart sketch kills the communication and throws the board off-line:

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");
}

When the Blynk.setProperty lines are commented out, the board now stays on-line and the uptime updates.

Bjorgvin