Code stop to run if don't find wifi (mega & esp-01)

hello everyone
my project work fine if WiFi signal is available
i want it too work with or without WiFi signal
i tried every solution i found in the forum and didn’t work

I’m using arduino mega with esp-01

here’s my code

#include <Wire.h>

#include <Adafruit_MLX90614.h>

#include "max32664.h"

#define RESET_PIN 04

#define MFIO_PIN 02


#define BLYNK_TEMPLATE_ID "************"

#define BLYNK_DEVICE_NAME "**************"

#define BLYNK_AUTH_TOKEN "****************"

// Send Blynk user messages to the hardware serial port…

#define BLYNK_PRINT Serial1

#include <ESP8266_Lib.h>

#include <BlynkSimpleShieldEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "*********";

char pass[] = "*********";

// Hardware Serial on Mega, Leonardo, Micro...

#define EspSerial Serial1

// Your ESP8266 baud rate:

#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

void setup(){







  // Debug console for ESP and to restore the Serial monitor update (ask mohammed it hard to explain)


  // Set ESP8266 baud rate



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

  // You can also specify server:

  //Blynk.begin(auth, wifi, ssid, pass, "", 80);

  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second

  timer.setInterval(1000L, myTimerEvent);




void loop(){;; // Initiates BlynkTimer

    //some codes here



// This function sends Arduino's up time every second to Virtual Pin (5).

// In the app, Widget's reading frequency should be set to PUSH. This means

// that you define how often to send data to Blynk App.

void myTimerEvent()


//  // You can send any value at any time.

//  // Please don't send more that 10 values per second.








Blynk.begin() is a blocking function.
If a connection to the internet or the Blynk server can’t be established then all code execution will halt at that point.

Your options are limited with the hardware you are using, you’d be better with an ESP8366 or ESP32 as you can then manage your own WiFi connection and use Blynk.config() and Blynk.connect()

Also, these three lines of code…

need to be the FIRST THREE lines of your sketch.


thanks for your response Pete

is there any other solution with the type of hardware I’m using ?
i tried to use blynk.config() as i saw in other posts in the forum but it didn’t work, now i know way

My days of messing around with the Uno/Mega and ESP-01 are long gone, and I forget exactly what is possible with that hardware.
There are some old posts by @Gunner about offline running and you might find some answers there, but TBH it’s about time that you abandoned this 13 year old technology and went for something more modern and with better functionality.


i know but didn’t know any mcu like mega, it have multiple SDA&SCL and TX/RX

any suggestion for esp based that have this many SDA&SCL and TX/RX ?

Bear in mind that you’ll need one less UART because you won’t be using one for the ESP-01.
Also, I’m not sure why you’d need so many I2C interfaces, as I2C is a bus system that allows multiple sensors to be attached to the same bus. Having said that, the ESP32 has 2 x I2C interfaces.


if one sensor is 5v and the second is 3.3v it cannot be in same bus, and my project can’t hold that many component

thank you for your time pete