#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "PubSubClient.h"
const char* MQTTServer = "broker.emqx.io";
const char* MQTT_Topic = "bangthongbao";
WiFiClient espClient;
PubSubClient client(espClient);
const char* MQTT_ID = "c535f5b1-c608-4dc1-8fd4-28728b946269";
int Port = 1883;
// Khởi tạo LCD với địa chỉ I2C (thường là 0x27 hoặc 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void WIFIConnect() {
Serial.println("Connecting to SSID: Wokwi-GUEST");
WiFi.begin("Wokwi-GUEST", "");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected");
Serial.print(", IP address: ");
Serial.println(WiFi.localIP());
}
void MQTT_Reconnect() {
while (!client.connected()) {
if (client.connect(MQTT_ID)) {
Serial.print("Connected to MQTT, Topic: ");
Serial.println(MQTT_Topic);
} else {
Serial.print("Failed to connect, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void setup() {
// Khởi động LCD
lcd.init();
lcd.backlight(); // Bật đèn nền
// Hiển thị văn bản lên LCD
lcd.setCursor(0, 0); // Vị trí hàng 1, cột 1
lcd.print("ESP32 - LCD 16x2");
lcd.setCursor(0, 1); // Vị trí hàng 2, cột 1
lcd.print("Hello, World!");
}
void loop() {
// Không làm gì trong loop
}