#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
#define BLYNK_DEBUG
#include <DNSServer.h>
//thư viện thêm khai báo khi sử dụng cảm biến
#include "DHTesp.h"
#ifdef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!)
#error Select ESP8266 board.
#endif
DHTesp dht;
char auth[] = "d8917f987d8d45c8838ee3bcc5a36b95";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "AUTO CNC";
char pass[] = "hoilamgi";
//char ssid[] = "Phong dong co";
//char pass[] = "phongdongco";
//char ssid[] = "Control auto";
//char pass[] = "66668888";
int wifi; // Biến của cường độ sóng Wifi
long rssi; // Biến đọc cường độ
char NhietDo[5]; //Tạo mảng nhớ cho giá trị nhiệt độ khi lấy 1 số sau dấy chấm phẩy
char DoAm[6]; //Tạo mảng nhớ cho giá trị độ ẩm khi lấy 1 số sau dấy chấm phẩy
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); //insert here your SSID and password
Serial.println();
Serial.println("Status\tHumidity (%)\tTemperature (C)");
String thisBoard= ARDUINO_BOARD;
Serial.println(thisBoard);
// KHAI BÁO LOẠI CẢM BIẾN VÀ KHỞI ĐỘNG
dht.setup(0, DHTesp::DHT22); // KHAI BÁO DÙNG CHÂN GPIO 0
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
// BẮT ĐẦU ĐỌC DỮ LIỆU TRÊN CẢM BIẾM
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
Serial.print("ĐỘ ẨM: ");
Serial.print(humidity);
Serial.println("%");
Serial.print("NHIỆT ĐỘ: ");
Serial.print(temperature);
Serial.println(" *C");
dtostrf(humidity,5, 1, DoAm); // Lưu giá trị chuyển đổi lấy 1 số sau dấy phẩy
Blynk.virtualWrite(V21, DoAm); // Xuất độ ẩm ra cho blynk
dtostrf(temperature,5, 1, NhietDo); // Lưu giá trị chuyển đổi lấy 1 số sau dấy phẩy
Blynk.virtualWrite(V20, NhietDo); //Xuất nhiệt độ ra cho blynk
// ĐO CƯỜNG ĐỘ SÓNG WIFI KHI ĐÃ KẾT NỐI
rssi = WiFi.RSSI();
Serial.print("SÓNG WIFI: ");
Serial.print(rssi);
Serial.println("dBm");
wifi = map(WiFi.RSSI(), -105, -40, 0, 100); // Xuất cường độ sóng Wifi ra cho blynk
Blynk.virtualWrite(V23, rssi); // Xuất cường độ sóng Wifi ra cho blynk
Blynk.virtualWrite(V22, wifi); // Xuất cường độ sóng Wifi ra cho blynk
}
need help
When connecting blynk, running for a while is ESP07 lost connection with blynk
Need read… I fixed your first post
Then read more…
1 Like