#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#inclue <http-server.ino>
int lcdRows=2;int lcdCols=16;
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, lcdCols, lcdRows);
const char* ssid="Wokwi-GUEST";
const char* password="";
void setup() {
Serial.begin(115200);
Serial.println("! ESP32 ! online");
LCD.init();
LCD.backlight();
initalize();
wifi_scan();
wifi_connect("Wokwi-GUEST", "");
}
void loop() {
delay(10);
}
void initalize(){
LCD.setCursor(3, 0);
LCD.print("LCD online");
delay(500);
LCD.clear();
LCD.print("Initializing");
LCD.setCursor(0,1);
for (int i=0; i<5; i++){
delay(200);
LCD.print('.');
}
LCD.clear();
LCD.setCursor(3,0);
LCD.print("..ONLINE..");
delay(500);
LCD.clear();
}
void wifi_scan(){
LCD.setCursor(2,0);
LCD.print("! WIFI MOD !");
LCD.setCursor(4,1);
LCD.print("Scanning");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
LCD.clear();
int n = WiFi.scanNetworks();
Serial.println("scan done");
LCD.setCursor(0,1);
LCD.print("Scan Done.");
delay(500);
LCD.clear();
if (n == 0) {
LCD.setCursor(3,1);
LCD.print("no networks");
Serial.println("no networks found");
} else {
Serial.print(n);
LCD.setCursor(2,1);
LCD.print(n);
LCD.setCursor(4,1);
LCD.print("wifi found");
Serial.println(" networks found");
for (int j = 0; j < n; ++j) {
Serial.print(j + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(j));
Serial.print(" (");
Serial.print(WiFi.RSSI(j));
Serial.print(")");
Serial.println((WiFi.encryptionType(j) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}delay(200);
}
Serial.println("");
delay(5000);
}
void wifi_connect(String wifi_ssid,String wifi_pswd){
WiFi.begin(wifi_ssid, wifi_pswd);
LCD.clear();
LCD.setCursor(0,0);
LCD.print("Connected to");
delay(500);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
LCD.clear();
LCD.setCursor(0,0);
delay(500);
LCD.print(wifi_ssid);
// LCD.setCursor(0,1);
LCD.setCursor(0,0);
// delay(500);
LCD.print(wifi_ssid);
LCD.setCursor(0,1);
LCD.print("[IP] ");
LCD.setCursor(5,1);
LCD.print(WiFi.localIP());
delay(1000);
LCD.clear();
}