2016-04-07 2 views
0

Я подключаюсь к ESP8266 в Arduino. Я хочу подключить модуль Wi-Fi к Arduino. Я хочу найти IP-адрес, используя AT + CIFSR. Как распечатать IP-адрес с помощью AT-команды в последовательном мониторе? Чтобы подключиться к приложению telnet, IP-адрес необходимо вставить в телефон Android.Как отображать IP-адрес в последовательном мониторе с помощью команды AT с ESP8266 в Arduino?

#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

Ваш вопрос, как прочитать серийный ответ от ESP? В команде AT нет ничего особенного, кроме чтения любых других последовательных данных. Документация Arduino Serial показывает, как делать то, что вы хотите. –

ответ

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(""); 
Смежные вопросы