Your device couldn't connect to the network used esp8266 node mcu

  1. Configuring wifi √
  2. Reconnecting back to cloud √
  3. Waiting for device online ×

my code :

#define BLYNK_TEMPLATE_ID "TMPLOnFp5b7j"
#define BLYNK_DEVICE_NAME "BLYnk"

//#include <DHT.h>
#include "DHTesp.h"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#define den D1
#include "BlynkEdgent.h"

DHTesp dht;

float t,h;
int button; 

BlynkTimer timer;
WidgetLED led(V0);
WidgetLED appled(V4);
boolean blynkState=0;

void setup(){
  Serial.begin(115200);
  delay(100);
  Wire.begin(14,12);         
  lcd.init();               
  lcd.clear();              
  lcd.backlight();           

  lcd.setCursor(4,0);        
  lcd.print("He thong");    
  lcd.setCursor(0,1);       
  lcd.print("canh bao nhiet!");
  delay(2000);
  lcd.clear();
  lcd.setCursor(1,0);        
  lcd.print("Dang thiet lap");    
  lcd.setCursor(2,1);        
  lcd.print("cau hinh...!");
  
  BlynkEdgent.begin();
    dht.setup(13, DHTesp::DHT11);
  timer.setInterval(3000,readSensor);
  timer.setInterval(1000,updateBlynk);
    pinMode(D1,OUTPUT);
    digitalWrite(D1,LOW);
}
BLYNK_WRITE(V3)
{
   button = param.asInt(); 
  if (button == 1){
    digitalWrite(den, HIGH); 
    appled.on();
  }
  else { 
    digitalWrite(den, LOW);
    appled.off();
  }
}
void loop(){
  BlynkEdgent.run();
  timer.run();
  if(Blynk.connected()){
    if(blynkState==0){
      blynkState=1;
      lcd.clear();
      lcd.setCursor(0,0);        
      lcd.print("Nhiet do: ");  
      lcd.setCursor(0,1);        
      lcd.print("Do am   : ");
    }
  }
  Blynk.run();
}

void readSensor(){
 
  float h = dht.getHumidity();
  float t = dht.getTemperature();
 
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    
  }else{
    
    if(blynkState==1){
      lcd.setCursor(9,0);
      lcd.print(t,1);
      lcd.print("*C ");
      lcd.setCursor(10,1);
      lcd.print(h,0);
      lcd.print("%");
    }
    Serial.print("Nhiệt độ: "); 
    Serial.println(t);
    Serial.print("Độ ẩm: ");
    Serial.println(h);
  }
}
void updateBlynk(){
  if (led.getValue()) {
    led.off();
  } else {
    led.on();
  }
  Blynk.virtualWrite(V1,t);
  Blynk.virtualWrite(V2,h);
  Blynk.virtualWrite(V3,button);
  } 

do not care about dht sensor because i did not connect pin with dht sensor
anybody help me please

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

   ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on ESP8266

[3569] --------------------------
[3572] Product:  BLYnk
[3574] Firmware: 0.1.0 (build May 18 2022 21:54:21)
[3579] Device:   ESP8266 @ 80MHz
[3582] MAC:      98:CD:AC:30:1A:0D
[3585] Flash:    4096K
[3587] ESP core: 3.0.2
[3589] ESP SDK:  2.2.2-dev(38a443e)
[3592] Boot Ver: 6
[3594] Boot Mode:1
[3596] FW info:  474576/1622016, MD5:ad92fc1c7052f2081f0ae2a96a20d7af
[3806] Free mem: 29960
[3806] --------------------------
[3806] INIT => WAIT_CONFIG
[4417] AP SSID: Blynk BLYnk-C6052
[4417] AP IP:   192.168.4.1
[4418] AP URL:  blynk.setup
[41630] WAIT_CONFIG => CONFIGURING
[46288] Sending board info...
[46778] Scanning networks...
[48965] Found networks: 22
[57724] Scanning networks...
[59912] Found networks: 14
[64584] Scanning networks...
[66790] Found networks: 18
[71109] Scanning networks...
[73298] Found networks: 15
[80920] Applying configuration...
[80920] WiFi SSID: TINHPC Pass: 111111111
[80920] Blynk cloud: u8u1xA7v4HlUV_uvcM6qF33exdwCx_Xc @ blynk.cloud:443
[80924] CONFIGURING => SWITCH_TO_STA
Nhiệt độ: 30.80
Độ ẩm: 81.00

it is done sir

You should always keep your void loop clean, read this

also, you don’t have to use Blynk.run with edgent sketch, you should use BlynkEdgent.run only.

I’d suggest that you start with a simple sketch first.

1 Like