Hi!
I show reading the sensors in the dashboard of Thinger.io, now I would like to recover that reading on a different NodeMCU.
I’ve see the Json file in
https://api.thinger.io/v1/users/EstacionMeteo/buckets/Prueba_bucket/data?items=1&max_ts=0&sort=desc&authorization=([TOKENDEVICE])
[{"ts":1607192420867.0,"val":{"Humedad_DHT11":null,"Humedad_DHT22":null,"Luminosidad":80.0,"Temperatura_DHT11":null,"Temperatura_DHT22":null}}]
(I’ve desconected DHT11 and DHT22 sensor)
I’ve used ArduinoJson assistant
Expression
SON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(5)
and Postman for see “pretty” code:
[
{ "ts": 1607193260952.0, "val": { "Humedad_DHT11": null, "Humedad_DHT22": null, "Luminosidad": 72.0, "Temperatura_DHT11": null, "Temperatura_DHT22": null } }
]
In Arduino IDE I wrote this code
//Dirección de la API de ThingerIO
clienteHttp.begin(“https://api.thinger.io/v1/users/EstacionMeteo/buckets/Prueba_bucket/data?items=1&max_ts=0&sort=desc&authorization=([TOKENDEVICE])”); //Specify request destinationint codigoHttp = clienteHttp.GET(); //Envío y petición HTTP al servidor
#ifdef DEBUG
Serial.print ("Código HTTP: ");
Serial.println (codigoHttp);
#endif//Si todo ha ido bien, devolverá un número positivo mayor que cero
if (codigoHttp > 0) {
//Si ha encontrado el recurso en el servidor
if (codigoHttp == HTTP_CODE_OK) {
#ifdef DEBUG
Serial.print ("Archivo JSON: ");
Serial.println (clienteHttp.getString());
#endif//Parsear archivo Json //Para obtener el tamaño del buffer visitar https://arduinojson.org/v6/assistant/ const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(5) + 100; DynamicJsonDocument doc(capacity);
//Parsear objeto JSON
DeserializationError error = deserializeJson(doc, clienteHttp.getString());
if (error) {
//Si hay error no continua
#ifdef DEBUG
Serial.print ("Fallo al parsear JSON. Error: ");
Serial.println (error.c_str());
#endif
return;
}
//Luminosidad
float lumi = doc[“val”][“Luminosidad”];
char Luminosidad [7];
Serial.println (Luminosidad);}
}
In monitor serial I can see
([codigoHttp]) is = a -1
I don’t know why the answer is -1 if I can see the Json with Postman and web navigator.
Can anyone helpme?
Sorry for writting mistakes, I don’t write very well in english.