0% found this document useful (0 votes)
27 views1 page

Esp32 Connect Wifi

This code is an Arduino sketch for connecting to a WiFi network using the ESP32. It initializes the WiFi connection with specified credentials and attempts to reconnect every 30 seconds if the connection is lost. The sketch also prints the local IP address and the Received Signal Strength Indicator (RSSI) to the serial monitor.

Uploaded by

robycah17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Esp32 Connect Wifi

This code is an Arduino sketch for connecting to a WiFi network using the ESP32. It initializes the WiFi connection with specified credentials and attempts to reconnect every 30 seconds if the connection is lost. The sketch also prints the local IP address and the Received Signal Strength Indicator (RSSI) to the serial monitor.

Uploaded by

robycah17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <WiFi.

h>

// Replace with your network credentials (STATION)


const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

unsigned long previousMillis = 0;


unsigned long interval = 30000;

void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}

void setup() {
Serial.begin(115200);
initWiFi();
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
}

void loop() {
unsigned long currentMillis = millis();
// if WiFi is down, try reconnecting every CHECK_WIFI_TIME seconds
if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis
>=interval)) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.reconnect();
previousMillis = currentMillis;
}
}

You might also like