Could you help me out on how exactly to parse the response of the API notation to get the last value of a variable
GET /api/v1.6/variables/{variable_id}/values/?token={token}&page_size=1
Hi @fusdorah just saw your message while looking through the forums. I’m not familiar with the ESP but here a standard pseudocode (arduino-like) to parse a JSON from Ubidots:
// Build HTTP GET request
c.print(F("GET /api/v1.6/variables/"VARID1"/values/?page_size=1&token="));
c.print(TOKEN);
c.println(F(" HTTP/1.1"));
c.println(F("Content-Type: application/json"));
c.print(F("Host: "));
c.println(URL);
c.println();
int v;
while(c.available()){
v = c.read();
if(v < 0){
Serial.println("No response.");
break;
}
response.concat((char)v); // Response is an empty string where you allocate all incoming chars from server.
}
Serial.println("Printing response:");
value_index = response.indexOf("\"value\": "); // Here you get the index to split the response string right where it says "value"
value_string = response.substring(value_index);
value = value_string.substring(9, value_string.indexOf(",")); // Here you ignore the first nine characters of the substring ("-v-a-l-u-e-"-: ), then get the value, then ignore the rest of the string after the comma.
Serial.println(value);