How I can send data information without work WiFi?

331 Views Asked by At

Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have code and but I have question How I can get the information data from dht to lcd without open the WiFi. Now I get information ( Temp and humidity ) on LCD when WiFi on only. How I can make Temp and humidity display on LCD with and without WiFi.

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxx";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 8         
#define DHTTYPE DHT11    
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void setup()
{
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  dht.begin();
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
}
void loop()
{
  Blynk.run();
  timer.run();
}
void sendSensor()
{
   float h = dht.readHumidity();
  float t = dht.readTemperature();
  lcd.backlight();
    lcd.setCursor(0,0);
  lcd.print("Humidity: ");
    lcd.print(h);
    lcd.print(" %");
      lcd.setCursor(0,2);
    lcd.print("Temperature: ");
        lcd.print(t);
   lcd.print(" C ");
  Serial.print("Humidity: ");
  Serial.print(h);
    Serial.println (" % ");
  Serial.print("Temperature: ");
  Serial.print(t);
      Serial.println (" C ");
  if (isnan(h) || isnan(t)) {
     lcd.backlight();
   lcd.setCursor(0,0);
  lcd.print("Temperature: ");
    lcd.print(t);
  lcd.print(" C ");
   lcd.setCursor(0,2);
    lcd.print("Humidity:  ");
      lcd.print(h);
      lcd.print(" % ");
   Serial.print("Humidity: ");
  Serial.print(h);
    Serial.println (" % ");
  Serial.print("Temperature: ");
  Serial.print(t);
      Serial.println (" C ");
  }
  Blynk.virtualWrite(V6, h);
  Blynk.virtualWrite(V2, t);
   Serial.print("Humidity: ");
  Serial.print(h);
    Serial.println (" % ");
  Serial.print("Temperature: ");
  Serial.print(t);
      Serial.println (" C ");
}
1

There are 1 best solutions below

0
On

If you have no wifi module connected or your module can't connect, your Blynk.begin(auth, wifi, ssid, pass); function should fail already to be executed.

Make sure that each part of your code that is passing data to another device is only executed if your device is responding. Try catching a missing connection with:

if (!Blynk.connected()){

   do someting....

}