I'm using an Arduino Uno Rev3 with ESP8266 to connect into a network and send some data through TCP sockets. I'm using the following code to establish a connection
boolean connectWifi() {
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
Serial.flush();
Serial.println(cmd);
delay(5000);
if(Serial.find("OK")) {
Serial.println("Connected");
return true;
} else {
Serial.println("Not connected");
return false;
}
}
but everytime I call this function inside the arduino loop(), I receive "Not connected".
I have already tried to connect direct from serial monitor running an empty code on Arduino and this AT command worked very well. Someone have any idea about what is wrong?
Connections:
(Used when I need to send commands right from arduino code)
Arduino ------------ ESP8266
3.3v --------------------- vcc
gnd ---------------------- gnd
3.3v ------------------- CH_PD
TX ------------------------ RX
RX ------------------------ TX
(Used when I need to send commands right from arduino serial monitor)
Arduino ------------ ESP8266
3.3v --------------------- vcc
gnd ---------------------- gnd
3.3v ------------------- CH_PD
TX ------------------------ TX
RX ------------------------ RX