Display only one sensor (of several) attached to one device

Well, you still have lots of Blynk stuff in your take_a_reading function, which obviously need to be moved.

What does your serial monitor show when it’s time for Blynk to connect, send the data, then disconnect?

Some serial print statements in your send_to_blynk function will also help you to better understand the program flow.

Pete.

Hi Pete:
I commented out the notification lines of code and the sketch runs smoother. Doesn’t seem to go through the “0” . I added some serial print statements as you suggested. However I don’t see any of them showing up in the serial monitor. All I’m getting is the selected tank, actual reading and adjustment factor. All working fine. It’s as if the time isn’t working at all.

 * For this example you'll need the following library:
 *  * 
 * 1) Arduino-LiquidCrystal-I2C-library: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
 *
 * 2) Blynk Library: https://github.com/blynkkk/blynk-library
 *
 * Conncetions:
 * D1 -> SCL of I2C LCD 
 * D2 -> SDA of I2C LCD
 * D3 -> Out of DHT11/22
 *
 */
#include <LoRa.h>
#define BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define I2C_SDA D3 //redefining I2C pins as D1 is needed by LoRa unit
#define I2C_SCL D4

#define ss 15
#define rst 16
#define dio0 2

int adjustment;
int adjusted_reading;
int tank_to_read;

const int ledPin = D1; //warning light that water has dropped beyone preset level
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; //Enter the Auth code which was send by Blink
char ssid[] = "xxxxxxxxxxx";  //Enter your WIFI Name
char pass[] = "xxxxxxxxxxxx";  //Enter your WIFI Password

BlynkTimer timer;

void setup()
{
timer.setInterval(1000L,take_a_reading); // Existing timer
timer.setInterval(300000L,send_to_blynk); // send data to Blynk every 5 minutes (30,000 m/s)
  
pinMode(ledPin,OUTPUT);
Wire.pins(D3, D4);
  
Serial.begin(9600);

lcd.begin();   // iInit the LCD for 16 chars 2 lines
lcd.backlight();   // Turn on the backligt (try lcd.noBaklight() to turn it off)
delay (1000);
Blynk.begin(auth, ssid, pass);

Serial.println("LoRa Sender");
LoRa.setPins(ss, rst, dio0);
if (!LoRa.begin(433E6)) 
  {
Serial.println("Starting LoRa failed!");
delay(100);
while (1);
  }
Serial.println("LoRa Started");
lcd.clear();
lcd.print("Waiting");
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.crc(); 

}

void send_to_blynk()
{
  Blynk.connect();    
  Blynk.run();
  Serial.println ("Blynk run");
  Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
  Blynk.run();
  Blynk.disconnect();
  Serial.println ("blynk disconnect");
}

void take_a_reading()
{
  int packetSize = LoRa.parsePacket();
  int reading = LoRa.parseInt();
  adjusted_reading = (reading - adjustment);
  int warning_level = 25 - adjustment;
  
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
    Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 

//String notification_body = "";
//notification_body += "The water is down ";
//notification_body += String(adjusted_reading);
//notification_body += "  inches";
//Blynk.notify (notification_body); 
   } 
   
//Alarm LED on receiving unit for tank 3
   if (reading <= warning_level )
   {
      digitalWrite(ledPin,LOW);
   }
   else 
   {
      digitalWrite(ledPin,HIGH);
   }
}

void loop()
{
//Blynk.run(); // Initiates Blynk
timer.run();
  }
  
BLYNK_WRITE(V1)
{
 tank_to_read = param.asInt();
 switch (tank_to_read)
  {
    case 1:
   {   
     adjustment = 0;
     break;      
   }

    case 2:
   {   
     adjustment = 4;
     break;      
   }

    case 3:
   {   
     adjustment = 8;
     break;      
   }

    case 4:
   {   
     adjustment = 12;
     break;      
   }
}
 }
        

What does this mean?

You should add one at the very beginning of the send_to_Blynk function.

When you used your code in post #27, did it work successfully? Your use of Blynk.connect from that sketch (which I copied into my later suggestion about your code structure) isn’t a documented command when used with Blynk.begin, but as you said you’d used it earlier I assumed that it would work.

Pete.

Hi Pete:
Regarding “0” The reading would go from the actual depth read (eg 50) then show 0 for a few minutes, then it would show the new depth (eg 20). That went away when I commented out the notification lines of code.
The sketch in 27 did work, but it was a bit balky (see post). Your improved code in post #31 worked the best - very smooth.
The Blynk.connect line of code has been in all versions. I commented it out just now to see if it makes a difference. The sketch compiles and seems to run fine without it. Still no sign of any of the serial print lines in inserted into the void sen_to_blynk() showing up in the serial monitor.

Sorry, I don’t understand any of this.

Without Blynk.connect it will never connect to the Blynk server.

Seeing your updated version of send_to_blynk would be useful.

Pete.

Okay, here’s the latest version of the sketch.
After a period of time the select tank function ceases to work. both on the ap and in the serial monitor.

I’m also attaching a screen capture of the serial monitor. No sign of anything on it from the send_to_blynk

/*
 * For this example you'll need the following library:
 *  * 
 * 1) Arduino-LiquidCrystal-I2C-library: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
 *
 * 2) Blynk Library: https://github.com/blynkkk/blynk-library
 *
 * Conncetions:
 * D1 -> SCL of I2C LCD 
 * D2 -> SDA of I2C LCD
 * D3 -> Out of DHT11/22
 *
 */
#include <LoRa.h>
#define BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define I2C_SDA D3 //redefining I2C pins as D1 is needed by LoRa unit
#define I2C_SCL D4

#define ss 15
#define rst 16
#define dio0 2

int adjustment;
int adjusted_reading;
int tank_to_read;

const int ledPin = D1; //warning light that water has dropped beyone preset level
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; //Enter the Auth code which was send by Blink
char ssid[] = "xxxxxxxxxxxx";  //Enter your WIFI Name
char pass[] = "xxxxxxxxxxxxx";  //Enter your WIFI Password

BlynkTimer timer;

void setup()
{
timer.setInterval(1000L,take_a_reading); // Existing timer
timer.setInterval(300000L,send_to_blynk); // send data to Blynk every 5 minutes (30,000 m/s)
  
pinMode(ledPin,OUTPUT);
Wire.pins(D3, D4);
  
Serial.begin(9600);

lcd.begin();   // iInit the LCD for 16 chars 2 lines
lcd.backlight();   // Turn on the backligt (try lcd.noBaklight() to turn it off)
delay (1000);
Blynk.begin(auth, ssid, pass);

Serial.println("LoRa Sender");
LoRa.setPins(ss, rst, dio0);
if (!LoRa.begin(433E6)) 
  {
Serial.println("Starting LoRa failed!");
delay(100);
while (1);
  }
Serial.println("LoRa Started");
lcd.clear();
lcd.print("Waiting");
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.crc(); 

}

void send_to_blynk()
{
  Serial.println ("connecting to blynk");
 Blynk.connect(); 
  Serial.println ("connected");   
  Blynk.run();
  Serial.println ("Blynk run");
  Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
  Blynk.run();
  Blynk.disconnect();
  Serial.println ("blynk disconnect");
}

void take_a_reading()
{
  int packetSize = LoRa.parsePacket();
  int reading = LoRa.parseInt();
  adjusted_reading = (reading - adjustment);
  int warning_level = 25 - adjustment;
  
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
    Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 

//String notification_body = "";
//notification_body += "The water is down ";
//notification_body += String(adjusted_reading);
//notification_body += "  inches";
//Blynk.notify (notification_body); 
   } 
   
//Alarm LED on receiving unit for tank 3
   if (reading <= warning_level )
   {
      digitalWrite(ledPin,LOW);
   }
   else 
   {
      digitalWrite(ledPin,HIGH);
   }
}

void loop()
{
//Blynk.run(); // Initiates Blynk
timer.run();
  }
  
BLYNK_WRITE(V1)
{
 tank_to_read = param.asInt();
 switch (tank_to_read)
  {
    case 1:
   {   
     adjustment = 0;
     break;      
   }

    case 2:
   {   
     adjustment = 4;
     break;      
   }

    case 3:
   {   
     adjustment = 8;
     break;      
   }

    case 4:
   {   
     adjustment = 12;
     break;      
   }
}
 }
        

You still have this in take_a_reading

It’s far better if you copy/paste the data, and use triple backticks. It’s also useful to turn on the timestamp in the serial monitor.

Pete.

Hi Pete:
Sorry this is taking so long to trouble shoot. As to your question regarding
Blynk.virtualWrite(V0, adjusted_reading); // To Display Widget
Yes, it’s still in the
Blynk.virtualWrite(V0, adjusted_reading); // To Display Widget.

I’ve had the program running for a few hours and have been monitoring it. Some times it will run for an hour before freezing up and display “The water is down 0 inches.” on the android device. The serial monitor and LCD do not freeze, and display the accurate depth.

When things are running well here is how the program runs when the timer is set for 5 minuts

  1. For the first 5 minutes the program behaves nicely, just as if there were not timer. It will display distances, continually. The different tank buttons behave properly.
  2. At five minutes the displayed depth freezes on the android device. I think this is okay, as it means that blynk has been disconnected as programmed. What isn’t right is that the depth displayed is locked to the tank to what was programmed before it disconnected. The buttons don’t work.
  3. After five minutes the program unlocks and the current depth is diplayed. But only the tank that was initially chosen in step 1. From that point on you can’t change the tanks unless you restart the program and choose a tank in the first five minutes.

If the program only had one tank it would probably behave normally. It seems mixing multiple tanks and timers is the program. At least that’s how it appears to me.
Jeff

It wasn’t really a question, it was a statement.
As I’d said before…

and this line of code seemed to have been missed.

Obviously the segmented switch in the app won’t have any effect on the operation of the device until the device successfully re-connects to the Blynk server and gets the updated switch value. You can’t have the best of both worlds - either you have a constant connection between the device and the server, and the associated internet traffic useage, or you have a system that only responds to widget button presses every 5 minutes (or every hour in the finished project).

At this stage, I don’t understand why the send_to_Blynk function doesn’t appear to be called, but until you remove the unwanted Blynk code from take_a_reading` it’s very difficult to follow what’s happening.

Pete.

Hi Pete:
Here is the stripped down take a reading. With the exception of the serial.print lines you suggested, I believe it’s identical to the one you suggested in post 31.
I still aren’t seeing any the above added serial.println I added in the serial monitor.

I see what you mean. I have no contact with the device during the ten minutes that it is disconnected from the internet. As it stands there it appears there is only one second when it is connected to change tanks (the brief time the sensor data is transmitted). Is that correct? My understanding is the device is connected for one minute :
timer.setInterval(1000L,take_a_reading); // Existing timer
then it will disconnect for 5 minutes:
timer.setInterval(300000L,send_to_blynk); // send data to Blynk every 5 minutes (30,000 m/s)
so, the time to change tanks would only be during that one minute window.
Correct?

void take_a_reading()
{
int packetSize = LoRa.parsePacket();
int reading = LoRa.parseInt();
  
   adjusted_reading = (reading - adjustment);
 
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
   Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 
   } 
  }

Okay, I’m now seeing it connect and disconnect. However he connect time be only a second!

23:39:33.883 -> Selected tank = 2
23:39:33.930 -> Actual reading = 0
23:39:33.930 -> Adjustment factor = 4
23:39:33.930 -> Adjusted reading = -4
**23:39:33.976 -> connecting to blynk**
**23:39:33.976 -> [240068] Connecting to blynk-cloud.com:80**
**23:39:34.253 -> [240453] Ready (ping: 203ms).**
**23:39:34.345 -> connected**
**23:39:34.345 -> Blynk run**
**23:39:34.669 -> [240863] Disconnected**
23:39:34.716 -> blynk disconnect
23:39:34.902 -> Selected tank = 2
23:39:34.902 -> Actual reading = 0

I’m very confused by your last two posts.
Your “stripped down take_a_reading” still contains this line of code:

I don’t know if you’ve posted the wrong code, or what else has changed to enable the send_to_blynk function to start being called, but I will say again, this line of code must be removed.

Once we have the send_to_blynk function being called consistently, and I understand the changes that you’ve made to make this work, then I’ll explain how to overcome the issue offline tank selection via the segmented switch.

Pete.

Thanks for your patience Pete. Removing that line has improved things greatly. It seems to operate fine except if I try and change tanks. WHen I do that the display on the app freezes at the last number sent. The lcd on the device and the serial monitor keep operating fine. So it’s just the problem of things freezing when I try and change tanks.
Jeff

/*
 * For this example you'll need the following library:
 *  * 
 * 1) Arduino-LiquidCrystal-I2C-library: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
 *
 * 2) Blynk Library: https://github.com/blynkkk/blynk-library
 *
 * Conncetions:
 * D1 -> SCL of I2C LCD 
 * D2 -> SDA of I2C LCD
 * D3 -> Out of DHT11/22
 *
 */
#include <LoRa.h>
#define BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define I2C_SDA D3 //redefining I2C pins as D1 is needed by LoRa unit
#define I2C_SCL D4

#define ss 15
#define rst 16
#define dio0 2

int adjustment;
int adjusted_reading;
int tank_to_read;

const int ledPin = D1; //warning light that water has dropped beyone preset level
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx"; //Enter the Auth code which was send by Blink
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";  //Enter your WIFI Name
char pass[] = "xxxxxxxxxxxx";  //Enter your WIFI Password

BlynkTimer timer;

void setup()
{
timer.setInterval(10000L,take_a_reading); // Existing timer
timer.setInterval(300000L,send_to_blynk); // send data to Blynk every 5 minutes (30,000 m/s)
  
pinMode(ledPin,OUTPUT);
Wire.pins(D3, D4);
  
Serial.begin(9600);

lcd.begin();   // iInit the LCD for 16 chars 2 lines
lcd.backlight();   // Turn on the backligt (try lcd.noBaklight() to turn it off)
delay (1000);
Blynk.begin(auth, ssid, pass);

Serial.println("LoRa Sender");
LoRa.setPins(ss, rst, dio0);
if (!LoRa.begin(433E6)) 
  {
Serial.println("Starting LoRa failed!");
delay(100);
while (1);
  }
Serial.println("LoRa Started");
lcd.clear();
lcd.print("Waiting");
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.crc(); 

}

void send_to_blynk()
{
  Serial.println ("connecting to blynk");
 Blynk.connect(); 
  Serial.println ("connected");   
  Blynk.run();
  Serial.println ("Blynk run");
  //Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
  Blynk.run();
  Blynk.disconnect();
  Serial.println ("blynk disconnect");
}



void take_a_reading()
{
int packetSize = LoRa.parsePacket();
int reading = LoRa.parseInt();
  
   adjusted_reading = (reading - adjustment);
 
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
   Blynk.virtualWrite(V0, adjusted_reading);  // To Display Widget
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 
   } 
  }

void loop()
{
timer.run();
  }
  
BLYNK_WRITE(V1)
{
 tank_to_read = param.asInt();
 switch (tank_to_read)
  {
    case 1:
   {   
     adjustment = 0;
     break;      
   }

    case 2:
   {   
     adjustment = 4;
     break;      
   }

    case 3:
   {   
     adjustment = 8;
     break;      
   }

    case 4:
   {   
     adjustment = 12;
     break;      
   }
}
 }
        

@Bundolo1 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:
```

Pete.

Sorry about that, Pete, left off one back tick at the beginning.

Here’s as snipped of the monitor

12:45:00.610 -> Selected tank = 4
12:45:00.610 -> Actual reading = 50
12:45:00.656 -> Adjustment factor = 12
12:45:00.656 -> Adjusted reading = 38
12:45:10.587 -> Selected tank = 4
12:45:10.634 -> Actual reading = 0
12:45:10.634 -> Adjustment factor = 12
12:45:10.681 -> Adjusted reading = -12
12:45:10.681 -> connecting to blynk
12:45:10.728 -> [300065] Connecting to blynk-cloud.com:80
12:45:10.916 -> [300384] Ready (ping: 112ms).
12:45:11.008 -> connected
12:45:11.008 -> Blynk run
12:45:11.102 -> [300575] Disconnected
12:45:11.149 -> blynk disconnect
12:45:20.618 -> Selected tank = 4
12:45:20.618 -> Actual reading = 0

I have to say that I am now getting extremely frustrated by what you’re doing.

I have asked you 5 times to remove Blynk.virtualWrite(V0, adjusted_reading); // To Display Widget from your take_a_reading function, but it’s still there.

Instead, you’ve commented that line of code out from the send_to_blynk function.

I’ll try one last time. Please study these two pieces of code very carefully, then make the changes that are documented in the comments in capitals…

void take_a_reading()
{
int packetSize = LoRa.parsePacket();
int reading = LoRa.parseInt();
  
   adjusted_reading = (reading - adjustment);
 
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
   Blynk.virtualWrite(V0, adjusted_reading);  // <<<<< REMOVE THIS LINE OF CODE!!!!!
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 
   } 
}
void send_to_blynk()
{
  Serial.println ("connecting to blynk");
 Blynk.connect(); 
  Serial.println ("connected");   
  Blynk.run();
  Serial.println ("Blynk run");
  //Blynk.virtualWrite(V0, adjusted_reading);  // <<<<< ADD THIS LINE OF CODE BACK IN
  Blynk.run();
  Blynk.disconnect();
  Serial.println ("blynk disconnect");
}

When you’ve done that, please test the sketch and provide meaningful, understandable feedback, and post an updated copy of your amended sketch (correctly formatted with triple backticks this time).

Pete.

Hi Pete:
Thank you for responding. I’m sorry you’re getting frustrated. It certainly isn’t my intent. I couldn’t have got as far as I have with this project without your help and support. I will try and read your instructions more carefully. A couple of things might help me lower your frustration level. I don’t understand what the difference is between commenting out a line of code or deleting it. I have generally commented the lines out until I’m sure that the sketch is working correctly. It allows me to put the code back in or move it, if I have to (without worrying about typos) as well as letting someone know what I’ve done. If there’s a reason not to do that please let me know.
I’ve tried to give you empirical and actual feedback, but obviously it’s not what you expect. Can you let me know what kind of feedback would be useful to you.
Again thanks for your time.
Best
Jeff

You’re better deleting the offending line completely from take_a_reading
It will only cause problems if you comment it out then later reinstate it.

Feedback like…

is nonsensical to me, and the process of getting you to clarify and expand on the meaning is extremely long-winded.

Pete.

Hi Pete:

Okay, I’ve inserted your code, removed the line where indicated and added the line where indicated. The only other change I’ve made is reducing the time down from 5 minutes to 3 minutes, so I can see results quicker.

I have attached the sketch below along with some of the results. I edited the data from the serial monitor down to just before and after the timing events to make the data more manageable. It covers a little over six minutes. I can provide the unedited data if it is more useful.

It appears that the app receives the first data from the device at the 3 minute mark and displays it fine. The problem is at the next 3 minute mark (6 minutes). At that point the app display (see pic) shows 0 and stays there even though the serial monitor is showing the correct depth.

So there seems to be a communication problem after the first acquisition. You’ll also note on the serial data it shows the tank as tank 0. There is no tank 0. Just tanks 1,2,3,4. Pressing buttons at any time (even when the device is connected to Blynk) doesn’t change anything on the display.

Serial Monitor Data

17:19:22.444 -> [2138] Connecting to kuggle's_condo_2
17:19:22.491 -> [2139] Connected to WiFi
17:19:22.491 -> [2139] IP: 192.168.0.37
17:19:22.538 -> [2139] 
17:19:22.538 ->     ___  __          __
17:19:22.584 ->    / _ )/ /_ _____  / /__
17:19:22.584 ->   / _  / / // / _ \/  '_/
17:19:22.631 ->  /____/_/\_, /_//_/_/\_\
17:19:22.678 ->         /___/ v1.0.0 on NodeMCU
17:19:22.678 -> 
17:19:22.678 -> [2255] Connecting to blynk-cloud.com:80              	APP SHOWING PREVIOUS 
17:19:22.865 -> [2535] Ready (ping: 113ms).				READING OF 0 INCHES
17:19:22.911 -> LoRa Sender
17:19:22.911 -> LoRa Started
17:19:22.958 -> Selected tank = 0
17:19:22.958 -> Actual reading = 0					SENSOR MOVED TO 7 INCHES
17:19:23.005 -> Adjustment factor = 0
17:19:23.005 -> Adjusted reading = 0
17:19:23.377 -> Selected tank = 0
17:19:23.377 -> Actual reading = 0
17:19:23.424 -> Adjustment factor = 0
17:19:23.424 -> Adjusted reading = 0
17:19:24.353 -> Selected tank = 0


………………………………………………………………….

17:22:18.358 -> Selected tank = 0
17:22:18.405 -> Actual reading = 7
17:22:18.405 -> Adjustment factor = 0
17:22:18.451 -> Adjusted reading = 7
17:22:19.378 -> Selected tank = 0
17:22:19.378 -> Actual reading = 0
17:22:19.425 -> Adjustment factor = 0
17:22:19.425 -> Adjusted reading = 0
17:22:20.399 -> Selected tank = 0
17:22:20.399 -> Actual reading = 7
17:22:20.399 -> Adjustment factor = 0
17:22:20.446 -> Adjusted reading = 7
17:22:20.446 -> connecting to blynk
17:22:20.493 -> [180097] Connecting to blynk-cloud.com:80
17:22:20.865 -> [180536] Ready (ping: 241ms).
17:22:20.911 -> connected
17:22:20.911 -> Blynk run
17:22:21.282 -> [180948] Disconnected
17:22:21.282 -> blynk disconnect
17:22:21.376 -> Selected tank = 0					APP CHANGES TO 7 INCHES
17:22:21.376 -> Actual reading = 0
17:22:21.423 -> Adjustment factor = 0
17:22:21.423 -> Adjusted reading = 0
17:22:22.394 -> Selected tank = 0
17:22:22.394 -> Actual reading = 0
17:22:22.441 -> Adjustment factor = 0
17:22:22.441 -> Adjusted reading = 0
17:22:23.368 -> Selected tank = 0
17:22:23.416 -> Actual reading = 7


………………………………………………………………………………………………………………………

17:24:02.410 -> Adjustment factor = 0
17:24:02.457 -> Adjusted reading = 0
17:24:03.386 -> Selected tank = 0
17:24:03.386 -> Actual reading = 39				SENSOR CHANGED TO 39 INCHES
17:24:03.432 -> Adjustment factor = 0				APP  STILL SHOWING  7 INCHES
17:24:03.432 -> Adjusted reading = 39
17:24:04.359 -> Selected tank = 0
17:24:04.406 -> Actual reading = 0
17:24:04.406 -> Adjustment factor = 0
17:24:04.452 -> Adjusted reading = 0
17:24:05.379 -> Selected tank = 0

………………………………………………………………………………………………………………………….
17:25:18.432 -> Adjusted reading = 0
17:25:19.405 -> Selected tank = 0
17:25:19.405 -> Actual reading = 39
17:25:19.405 -> Adjustment factor = 0
17:25:19.452 -> Adjusted reading = 39
17:25:20.381 -> Selected tank = 0
17:25:20.427 -> Actual reading = 0
17:25:20.427 -> Adjustment factor = 0
17:25:20.427 -> Adjusted reading = 0
17:25:20.474 -> connecting to blynk
17:25:20.474 -> [360064] Connecting to blynk-cloud.com:80
17:25:20.845 -> [360510] Ready (ping: 201ms).
17:25:20.891 -> connected
17:25:20.891 -> Blynk run
17:25:21.217 -> [360919] Disconnected
17:25:21.263 -> blynk disconnect
17:25:21.404 -> Selected tank = 0
17:25:21.404 -> Actual reading = 39				APP CHANGES TO SHOW  0 INCHES
17:25:21.404 -> Adjustment factor = 0
17:25:21.451 -> Adjusted reading = 39
17:25:22.377 -> Selected tank = 0
17:25:22.423 -> Actual reading = 0
17:25:22.423 -> Adjustment factor = 0
17:25:22.471 -> Adjusted reading = 0
17:25:23.395 -> Selected tank = 0
17:25:54.431 -> Adjustment factor = 0
17:25:54.431 -> Adjusted reading = 0
17:25:55.402 -> Selected tank = 0
17:28:20.407 -> Selected tank = 0
17:28:20.407 -> Actual reading = 0
17:28:20.454 -> Adjustment factor = 0
17:28:20.454 -> Adjusted reading = 0
17:28:20.502 -> connecting to blynk
17:28:20.502 -> [540064] Connecting to blynk-cloud.com:80
17:28:20.733 -> [540420] Ready (ping: 196ms).
17:28:20.826 -> connected
17:28:20.826 -> Blynk run
17:28:21.152 -> [540829] Disconnected
17:28:21.198 -> blynk disconnect
17:28:21.385 -> Selected tank = 0
17:28:21.431 -> Actual reading = 0
17:28:21.431 -> Adjustment factor = 0
17:28:21.478 -> Adjusted reading = 0
17:28:22.406 -> Selected tank = 0
17:28:22.406 -> Actual reading = 0
17:28:22.453 -> Adjustment factor = 0
17:28:22.453 -> Adjusted reading = 0
17:28:23.380 -> Selected tank = 0
17:28:23.426 -> Actual reading = 9
17:28:23.426 -> Adjustment factor = 0

Here’s the program

/*
 * For this example you'll need the following library:
 *  * 
 * 1) Arduino-LiquidCrystal-I2C-library: https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
 *
 * 2) Blynk Library: https://github.com/blynkkk/blynk-library
 *
 * Conncetions:
 * D1 -> SCL of I2C LCD 
 * D2 -> SDA of I2C LCD
 * D3 -> Out of DHT11/22
 *
 */
#include <LoRa.h>
#define BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define I2C_SDA D3 //redefining I2C pins as D1 is needed by LoRa unit
#define I2C_SCL D4

#define ss 15
#define rst 16
#define dio0 2

int adjustment;
int adjusted_reading;
int tank_to_read;

const int ledPin = D1; //warning light that water has dropped beyone preset level
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxx"; //Enter the Auth code which was send by Blink
char ssid[] = "xxxxxxxxxxxxxxxxxx";  //Enter your WIFI Name
char pass[] = "xxxxxxxxxxxxxxx";  //Enter your WIFI Password

BlynkTimer timer;

void setup()
{
timer.setInterval(1000L,take_a_reading); // Existing timer
timer.setInterval(180000L,send_to_blynk); // send data to Blynk every 3 minutes (180,000 m/s)
  
pinMode(ledPin,OUTPUT);
Wire.pins(D3, D4);
  
Serial.begin(9600);

lcd.begin();   // iInit the LCD for 16 chars 2 lines
lcd.backlight();   // Turn on the backligt (try lcd.noBaklight() to turn it off)
delay (1000);
Blynk.begin(auth, ssid, pass);

Serial.println("LoRa Sender");
LoRa.setPins(ss, rst, dio0);
if (!LoRa.begin(433E6)) 
  {
Serial.println("Starting LoRa failed!");
delay(100);
while (1);
  }
Serial.println("LoRa Started");
lcd.clear();
lcd.print("Waiting");
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.crc(); 

}
void take_a_reading()
{
int packetSize = LoRa.parsePacket();
int reading = LoRa.parseInt();
  
   adjusted_reading = (reading - adjustment);
 
  Serial.print("Selected tank = ");
  Serial.println(tank_to_read);
  Serial.print("Actual reading = ");
  Serial.println(reading);
  Serial.print("Adjustment factor = ");
  Serial.println(adjustment);
  Serial.print("Adjusted reading = ");
  Serial.println(adjusted_reading);
   
  if (packetSize)
  {
    lcd.setCursor(0,0); //First line
    lcd.print("water is down");
    lcd.setCursor(0,1); //Second line
    lcd.print(adjusted_reading);
    lcd.print(" inches"); 
   } 
}
void send_to_blynk()
{
  Serial.println ("connecting to blynk");
 Blynk.connect(); 
  Serial.println ("connected");   
  Blynk.run();
  Serial.println ("Blynk run");
  Blynk.virtualWrite(V0, adjusted_reading);  
  Blynk.run();
  Blynk.disconnect();
  Serial.println ("blynk disconnect");
}


void loop()
{
timer.run();
  }
  
BLYNK_WRITE(V1)
{
 tank_to_read = param.asInt();
 switch (tank_to_read)
  {
    case 1:
   {   
     adjustment = 0;
     break;      
   }

    case 2:
   {   
     adjustment = 4;
     break;      
   }

    case 3:
   {   
     adjustment = 8;
     break;      
   }

    case 4:
   {   
     adjustment = 12;
     break;      
   }
}
 }

Okay, can you replace the existing send_to_Blynk with this code…

void send_to_blynk()
{
  Serial.println ("Connecting to blynk");
  Blynk.connect();
  // the remainder of the processing should be done
  // in the BLYNK_CONNECTED function
}

BLYNK_CONNECTED()
{
  Serial.println ("connected");
  Blynk.syncVirtual(V1); // force the server to send the latest value for the segmented switch
  Blynk.run();
  Serial.println ("Blynk run 1");
  take_a_reading(); // take a reading from the tank indicated by the segmented switch
  Blynk.run();
  Serial.println ("Blynk run 2");   
  Blynk.virtualWrite(V0, adjusted_reading); // To Display Widget
  Blynk.run();
  Serial.println ("Blynk run 3"); 
  Blynk.disconnect();
  Serial.println ("blynk disconnected");  
}

BLYNK_CONNECTED() is a function which is called automatically each time the device connects to the Blynk server. It should fix the problem of the tank zero problem, and pick-up on any changes to the tank selected in the segmented switch while the device was offline.
What I don’t know is if there are enough Blynk.run() commands in there, and located in the correct places, to make this work correctly, so I need you to test it.

Pete.