简体   繁体   English

如何在没有工作 WiFi 的情况下发送数据信息?

[英]How I can send data information without work WiFi?

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.我有一个小项目,我使用Arduino unoesp8266dht11lcd I2C并在我的项目中使用blynk应用程序 我有代码,但我有疑问如何在不打开 WiFi 的情况下从dht获取信息数据到lcd Now I get information ( Temp and humidity ) on LCD when WiFi on only.现在我只在 WiFi 打开时在 LCD 上获得信息(温度和湿度)。 How I can make Temp and humidity display on LCD with and without WiFi.如何在有和没有 WiFi 的情况下在 LCD 上显示温度和湿度。

#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 ");
}

If you have no wifi module connected or your module can't connect, your Blynk.begin(auth, wifi, ssid, pass);如果您没有连接 wifi 模块或您的模块无法连接,您的 Blynk.begin(auth, wifi, ssid, pass); function should fail already to be executed. function 应该已经无法执行。

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....

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM