Код: Выделить всё
#include
SoftwareSerial ESP8266(4, 2); // RX, TX
unsigned char check_connection = 0;
unsigned char attempts = 0;
void setup() {
Serial.begin(9600); // Serial Monitor for debugging
ESP8266.begin(9600); // Common default baud rate for ESP-01
delay(1000);
ESP8266.println("AT+RST"); // Reset the module
delay(2000); // Give it some time to reset
// Set to station mode (client)
ESP8266.println("AT+CWMODE=1");
delay(2000);
}
void loop() {
if (check_connection == 0) {
Serial.println("Attempting to connect to WiFi...");
ESP8266.print("AT+CWJAP=\"HUAWEI-2.4G-d32V\",\"qpalzmwsxokn29\"\r\n");
ESP8266.setTimeout(15000); // 15 seconds to allow connection
// Check if the ESP responds with "OK" or "WIFI CONNECTED"
if (ESP8266.find("OK") || ESP8266.find("WIFI CONNECTED")) {
Serial.println("Connected to WiFi!");
check_connection = 1;
} else {
// Read and print the response for debugging
while (ESP8266.available()) {
String response = ESP8266.readString();
Serial.println("ESP8266 Response: " + response);
}
attempts++;
if (attempts > 3) {
attempts = 0;
Serial.println("Failed to connect. Retrying in 5 seconds...");
delay(5000); // Wait 5 seconds before retrying
} else {
Serial.println("Retrying connection...");
}
}
} else {
// Once connected, stop looping
Serial.println("Module is connected to WiFi.");
while (true);
}
}
Я пробовал использовать точки доступа и другой Wi-Fi... Я не знаю, что теперь делать, я только начинаю работать в arduino uno
Подробнее здесь: https://stackoverflow.com/questions/791 ... to-my-wifi