SHARE
TWEET

Untitled

a guest Sep 13th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.print(String("GET ") + path + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: keep-alive\r\n\r\n");
  2.   delay(500); // wait for server to respond
  3.  
  4.   // read response  
  5.   String section = "header";
  6.  
  7.   while(client.available()) {
  8.     String line = client.readStringUntil('\r');
  9.     Serial.print(line);    // we’ll parse the HTML body here
  10.    
  11.     if (section=="header") { // headers..
  12.       Serial.print(".");
  13.      
  14.       if (line=="\n") { // skips the empty space at the beginning
  15.          section="json";
  16.       }
  17.     }
  18.    
  19.     else if (section=="json") {  // print the good stuff
  20.      
  21.       section = "ignore";
  22.       String result = line.substring(1);      // Parse JSON
  23.       int size = result.length() + 1;
  24.       char json[size];
  25.       result.toCharArray(json, size);
  26.       StaticJsonBuffer<200> jsonBuffer;
  27.       JsonObject& json_parsed = jsonBuffer.parseObject(json);
  28.      
  29.       if (!json_parsed.success()){
  30.         Serial.println("parseObject() failed");
  31.         return;
  32.       }
RAW Paste Data
Top