I need to filter the response that I currently get and save it to a variable.
#include <ESP8266WiFi.h>
const char* ssid = "Wi-Fi Network";
const char* password = "Password";
const char* host = "data.sparkfun.com";
const char* streamId = "EJ4x0azK3pcOAbpxAMjM";
void setup() {
Serial.begin(115200);
delay(10);
// 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());
}
void loop() {
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/output/";
url += streamId;
url += ".json?limit=1";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
// Read all the lines of the reply from server and print them to Serial
// Response is shown between the lines
Serial.println("_____________________________");
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println("_____________________________");
Serial.println();
Serial.println("closing connection");
// Wait 5 seconds, then repeat
delay(5000);
}
This will give me the following response:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sun, 28 Aug 2016 08:00:00 GMT
Connection: close
Set-Cookie: SERVERID=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/
Cache-control: private
56
[{"tanklevel_cm":"68","tanklevel_percent":"90","timestamp":"2016-08-28T07:59:33.751Z"}
1
]
0
All I need is the information within the brackets { }. Specifically all I want is the "tanklevel_percent" value. Can anyone give me any ideas on how to accomplish this?