I'm connecting to an ESP8266 in Arduino. I want to connect the wifi module with Arduino. I want to find the IP using AT+CIFSR. How to print the IP using an AT command in the serial monitor? To connect with a telnet app, the IP is needed to insert in Android phone.
#include "SoftwareSerial.h"
String ssid = "connectify-krish";
String password = "12345678";
SoftwareSerial esp(10, 11);
void setup() {
int len;
Serial.begin(9600);
esp.begin(9600);
reset();
esp.println("AT");
delay(1000);
if (esp.find("OK")) Serial.println("Module Reset");
esp.println("AT+RST");
delay(1000);
if (esp.find("OK")) Serial.println("Reset");
esp.println("AT+RST");
delay(1000);
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
Serial.println(cmd);
String site= "www.google.com";
String ping = "AT+PING=\"" + site + "\"";
esp.println(ping);
if (esp.find("OK")) Serial.println("CONNECTED WIFI");
String ip = "AT+CIFSR";
esp.println(ping);
if (esp.find("OK")) Serial.println("ip is");
}
void reset() {
if(esp.available()) {
// check if the esp is sending a message
while(esp.available()) {
// The esp has data so display its output to the serial window
char c = esp.read(); // read the next character.
Serial.write(c);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}
答案 0 :(得分:0)
您没有发送AT命令
String ip = "AT+CIFSR";
esp.println(ping);
if (esp.find("OK")) Serial.println("ip is");
应该是
String ip = "AT+CIFSR";
esp.println(ip);
Serial.print("ip is ");
// Loop through all the data returned
while(esp.available()) {
// The esp has data so display its output to the serial window
char c = esp.read(); // read the next character.
Serial.write(c);
}
Serial.println("");