Help me to get data from ubidots


#1

float getValue(char* id){
float num;
String response;
uint8_t bodyPosinit;
uint8_t bodyPosend;
if (client.connect(“things.ubidots.com”, 80)){
Serial.println(F(“Geting your variable”));
// Make a HTTP request:
client.print(F(“GET /api/v1.6/variables/”));
client.print(id);
client.println(F("/values?page_size=1 HTTP/1.1"));
client.println(F(“Host: things.ubidots.com”));
client.println(F(“User-Agent: NodeMCU/1.0”));
client.print(F(“X-Auth-Token: “));
client.println(TOKEN);
client.println(F(“Connection: close”));
client.println();
}
int timeout = 0;
while (!client.available() && timeout < 5000) {
timeout++;
}
while (client.available()){
response = client.readString();
}
Serial.println(response);
bodyPosinit = 4 + response.indexOf(”\r\n\r\n”);
response = response.substring(bodyPosinit);
Serial.println(response);
bodyPosinit = 9 + response.indexOf("“value”:");
bodyPosend = response.indexOf(", “timestamp”");
num = response.substring(bodyPosinit,bodyPosend).toFloat();
client.flush();
client.stop();
return num;
}

by using this code i get only 0.00, not returning the actual value, any one please help me.


#2

Hello, which hardware board are you using?


#3

Arduino MKR1000,

please solve my problem.


#4

Actually we don’t have a library for that board, but as you would see at this post you can modify Ubidots’ actual wifi shield library for the MKR1000 in order to make it work properly:

Ubidots’ wifi shield library has some examples for getting data, please take a look at them.

Regards