2017-05-13 11 views
0

私はESP8266で気象情報を取得してOLEDディスプレイに表示しようとしていました。ESP8266 Arduino IDE JSON HTTPリクエスト

if (!client.connect("api.apixu.com", 80)) { 
    Serial.println("connection failed"); 
    return;} 

    client.print("GET " + url + " HTTP/1.1\r\n" + 
    "Host: " + host + "\r\n" + 
    "Content-Type: application/json\r\n" + 
    "Connection: close\r\n\r\n"); 

    char c[1024]; 
    // Read all the lines of the reply from server and print them to Serial 
    while(client.available()){ 
     c[0] = client.read();Serial.print(c);} 

これは、JSONコンテンツをリクエストして読み取るためのコードです。しかし、私が試してみると、コードはwhileループに入りません。

誰かが間違いを見つけられますか?

ありがとうございます! :D

答えて

0

私はこのコードはavailable()は常に0

client.print(String("GET ") + url + " HTTP/1.1\r\n" + 
       "Host: " + host + "\r\n" + 
       "Connection: close\r\n\r\n"); 
    unsigned long timeout = millis(); 
    while (client.available() == 0) { 
    if (millis() - timeout > 5000) { 
     Serial.println(">>> Client Timeout !"); 
     client.stop(); 
     return; 
    } 
たのと同じエラーが発生したすべての人のために働く何とかそれを修正