The sensor don't work when the internet loses

I used this code, but the problem is that the internet is cut off the sensors do not work. Is there a solution to this problem? I use an Arduino Uno and a modem esp8266.

#define BLYNK_TEMPLATE_NAME         "....."
#define BLYNK_AUTH_TOKEN            "...."
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char ssid[] = "S";
char pass[] = "0000000000";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9);
#define ESP8266_BAUD 38400
ESP8266 wifi(&EspSerial);
#include <Servo.h>
const int trigPinWA = 10;
const int echoPinWA = 11;
Servo servoMotor;
const int relayPin = 3;
#include <SPI.h>
#define LOG_PERIOD 15000
#define MAX_PERIOD 60000
unsigned long counts;
unsigned long cpm;
unsigned int multiplier;
unsigned long previousMillis;
void tube_impulse(){
const int trigPin = 4;
const int echoPin = 5;
void setup()
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass, "", 80);
pinMode(trigPinWA, OUTPUT);
pinMode(echoPinWA, INPUT);
pinMode(relayPin, OUTPUT);
counts = 0;
cpm = 0;
multiplier = MAX_PERIOD / LOG_PERIOD;      //calculating multiplier, depend on your log period
attachInterrupt(0, tube_impulse, FALLING); //define external interrupts 
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
long durationW, distanceW;
digitalWrite(trigPinWA, LOW);
digitalWrite(trigPinWA, HIGH);
digitalWrite(trigPinWA, LOW);
durationW = pulseIn(echoPinWA, HIGH);
distanceW = durationW * 0.034 / 2;
Serial.print("DistanceW: ");
Serial.println(" cm");
if (distanceW != 0) {
if (distanceW <50) 
digitalWrite(relayPin, HIGH);
else {
digitalWrite(relayPin, LOW);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > LOG_PERIOD) {
previousMillis = currentMillis;
cpm = counts * multiplier;
counts = 0;
long duration, distance;
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;;
Blynk.virtualWrite(V2, distance);
Blynk.virtualWrite(V1, cpm);

@sjad Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:

Copy and paste these if you can’t find the correct symbol on your keyboard.


I have corrected it

Blynk.begin() is a blocking command, and will halt all code execution if the device can’t connect to either WiFi or the Blynk server.

The solution Is to manually manage your WiFi connection and use Blynk.config() and Blynk.connect() - maybe with an optional timeout value in milliseconds, as well as making some other changes to your code.

Unfortunately, you can’t do that with your existing hardware, but if you were to switch to a NodeMCU or preferably an ESP32 then you could achieve offline operation.