lundi 27 mars 2017

Can not get full and right data from web through esp8266

I use Arduino mego 2560 and esp8266 follow this http://ift.tt/2maYGhD and write this code:

void setup() {
 Serial.begin(9600);
 Serial1.begin(115200);  
}

void loop() { 
    Serial1.println("AT");  
    delay(1000);    

    Serial1.println("AT+CWMODE=1");
    delay(1000);

    Serial1.println("AT+CWJAP=\"SSSD\",\"PASSWORD\"");
    delay(5000);

    Serial1.println("AT+CIPSTART=\"TCP\",\"www.mywebsite.com\",80");
    delay(1000);

    Serial1.print("AT+CIPSEND=");
    String postRequest ="GET /nhap.php HTTP/1.1\r\n\r\nHost:http://www.mywebsite.com\r\n\r\nConnection:close\r\n\r\n";

    Serial1.println(postRequest.length());
    delay(5000);

    Serial1.println("GET /nhap.php HTTP/1.1");
    Serial1.println("Host: www.mywebsite.com");
    Serial1.println("Connection:close");
    Serial1.println();

    int check_down = 0;
    String content = "";
    while(Serial1.available()!=0)
    {  
        check_down++;
        content = content + String(char (Serial1.read()));
    } 
    Serial.println(check_down);
    //Serial.println(content);
    Serial.println(content.substring(10,50));
    delay(3000);

    Serial1.println("AT+CIPCLOSE");
    ShowSerialData();
    delay(1000);
}    
void ShowSerialData()
{
    while(Serial1.available())
        Serial.write(Serial1.read());
    while (Serial.available())
        Serial1.write(Serial.read());
}

My website:

<html>
<head></head>
<body>HELLO</body>
</html>

I want to get "HELLO" on serial monitor from arduino IDE but I got this:

AT+CIPCLOSE busy s...

SEND OK

+IPD,156:HTTP/1.1 200 OK SGET /nhap.php HTTP/1.1 Host: www.mywebsite.com Connectio:le

??? @@ so something wrong between mega2560(9600) and esp8266(115200) ?




Aucun commentaire:

Enregistrer un commentaire