Here is possibly an easier example to start with for the Mega…
//#define BLYNK_DEBUG // Advanced diagnostic data... also drastically slows entire sketch
#define BLYNK_PRINT Serial // This prints to Serial Monitor
#define BLYNK_USE_128_VPINS
#include <ESP8266_Lib.h> // ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h> // ESP-01 Link
ESP8266 wifi(&Serial1); // Pins 18 & 19 on MEGA - For ESP-01 link
BlynkTimer timer;
#define HTB 13 // Set HeartBeat LED pin.
char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "blynk-cloud.com";
int port = 8080;
void setup() {
pinMode(HTB, OUTPUT);
Serial.begin(115200); // BLYNK_PRINT data - For Serial Monitor
Serial1.begin(115200); // Set baud rate - For ESP-01 link
wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
Blynk.config(wifi, auth, server, port);
if (Blynk.connectWiFi(ssid, pass)) {
Blynk.connect();
}
// Timed Lambda Function - UpTime counter
timer.setInterval(1000L, []() { // Run every second
Blynk.virtualWrite(V0, millis() / 1000); // Display the UpTime in Seconds to Widget on V0
}); // END Lambda Function
}
void loop() {
timer.run();
Blynk.run();
}