der arduino ide esp8266 json Dekodieren von URL

Ich Programm esp8266 mit der Arduino-IDE. Ich schließe mich mit dem lokalen Netzwerk über WLAN. Schließlich möchte ich für den download der Inhalte JSON generiert, die auf dem lokalen server. Ich bin mit dem code:

 #include <ESP8266WiFi.h>
    #include <ArduinoJson.h>

    const char* ssid     = "NeoRaf";
    const char* password = "password";
    const char* host = "192.168.1.8";

    void setup() {
      Serial.begin(115200);
      delay(100);

      //We start by connecting to a WiFi network

      Serial.println();
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);

      WiFi.begin(ssid, password);

      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }

      Serial.println("");
      Serial.println("WiFi connected");  
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());

      //-----------------------
      delay(5000);

      Serial.print("connecting to ");
      Serial.println(host);

      //Use WiFiClient class to create TCP connections
      WiFiClient client;
      const int httpPort = 8095;
      if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
      }

      //We now create a URI for the request
      String url = "/api";
      Serial.print("Requesting URL: ");
      Serial.println(url);

      //This will send the request to the server
      client.print("GET " + url + " HTTP/1.1\r\n" +
                   "Host: " + host + "\r\n" +
                   "ApiCode: 8273\r\n" +
                   "Content-Type: application/json\r\n" + 
                   "Connection: close\r\n\r\n");
      delay(500);
       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);

     Serial.print(c);
     }
       StaticJsonBuffer<200> jsonBuffer;
       JsonObject& root = jsonBuffer.parseObject(c);
      int data = root["lowVersion"];  
      Serial.println();
         Serial.print(data);

      Serial.println();
      Serial.println("closing connection");  
    }

    void loop()
    {}

Das Ergebnis ist dieses:

    Connecting to NeoRaf
    ......
    WiFi connected
    IP address: 
    192.168.1.21
    connecting to 192.168.1.8
    Requesting URL: /api
    HTTP/1.1 200 OK
    Content-Length: 32
    Content-Type: application/json
    Server: Microsoft-HTTPAPI/2.0
    Access-Control-Allow-Origin: *
    Date: Mon, 06 Jun 2016 16:50:48 GMT
    Connection: close

{"lowVersion":1,"highVersion":3}
0
closing connection

Diese Zeile JSON:

{"lowVersion":1,"highVersion":3}

Also er sollte anzeigen 1 und zeigt 0 an.
Ich weiß nicht, wie, um loszuwerden, der header:

HTTP/1.1 200 OK
Content-Length: 32
Content-Type: application/json
Server: Microsoft-HTTPAPI/2.0
Access-Control-Allow-Origin: *
Date: Mon, 06 Jun 2016 16:50:48 GMT

und, wie zu Lesen, den Inhalt des JSON ( lowVersion oder highVersion)?

InformationsquelleAutor Rafik73 | 2016-06-06
Schreibe einen Kommentar