esp32 code from arduino uno

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <WiFi.h>


// WiFi credentials

const char* ssid = "adharsh";

const char* password = "12345678";


// Initialize the LCD with I2C address 0x27 for a 16x2 display

LiquidCrystal_I2C lcd(0x27, 16, 2);


unsigned long previousMillis = 0;

unsigned long interval = 30000;


void setup() {

  // Start the serial communication

  Serial.begin(115200);


  // Initialize the LCD

  lcd.begin();

  lcd.backlight();

  

  // Initial message on LCD

  lcd.setCursor(0, 0);

  lcd.print("Waiting for data");


  // Connect to WiFi

  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);

  Serial.print("Connecting to ");

  Serial.println(ssid);

  delay(1000);

  while (WiFi.status() != WL_CONNECTED) {

    Serial.print('.');

    delay(500);

  }

  Serial.print("Connected to ");

  Serial.println(ssid);

  Serial.print("Your Local IP address is: ");

  Serial.println(WiFi.localIP());  // Print the Local IP

}


void loop() {

  unsigned long currentMillis = millis();


  // Check if WiFi is connected every 30 seconds

  if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >= interval)) {

    Serial.println("Reconnecting to WiFi...");

    WiFi.disconnect();

    WiFi.reconnect();   

    previousMillis = currentMillis;

  }


  // Check if data is available from Arduino Uno

  if (Serial.available()) {

    // Clear the LCD

    lcd.clear();

    

    // Read the incoming message from Arduino Uno

    String receivedData = "";

    while (Serial.available()) {

      receivedData += (char)Serial.read();  // Read each character

    }

    

    // Display the received data on the LCD

    lcd.setCursor(0, 0);  // Position at the top left

    lcd.print(receivedData);  // Print the received data


    delay(1000);  // Small delay to make the update visible

  }

}


Comments