Hola Ega. Gracias por compartir tu conocimiento.
No consigo ver el valor de payload por el monitor serie. Estoy seguro que estoy haciendo algo mal, soy bastante nuevo programando. Te dejo el código a ver si tienes un rato y puedes decirme que estoy haciendo mal.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ThingerESP8266.h>
//Datos Thinger.io
#define USERNAME "EstacionMeteo"
#define DEVICE_ID "NodeMCU_Light"
#define DEVICE_CREDENTIAL "MYDEVICECREDENTIAL"
#define _DEBUG_
String link = "http://api.thinger.io/v1/users/EstacionMeteo/buckets/Prueba_bucket/data?items=1&max_ts=0&sort=desc&authorization=[MITOKEN]";
const char* ssid = "MIRED";
const char* ssid_PASSWORD = "MIPASSWORD";
HTTPClient http; //Cliente web
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void configWifi () {
#ifdef _DEBUG_
//Conexión con la red wifi
Serial.print ("Conectando con ");
Serial.println (ssid);
#endif
//Configuración en modo cliente
WiFi.mode (WIFI_STA);
//Iniciar conexión con la red wifi
WiFi.begin (ssid, ssid_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
#ifdef _DEBUG_
Serial.print (".");
#endif
}
#ifdef _DEBUG_
Serial.println ("");
Serial.print ("Conectado a la red ");
Serial.println (ssid);
#endif
}
String httpRequest(String link){
String payload;
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin(link); //Specify request destination
int httpCode = http.GET(); //Send the request
Serial.println (httpCode); //No muestra nada por el monitor serie
if (httpCode > 0) { //Check the returning code
payload = http.getString(); //Get the request response payload
// Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
return payload;
}
void setup() {
Serial.begin (9600);
configWifi();
thing.add_wifi(ssid, ssid_PASSWORD);
}
void loop() {
httpRequest (link);
}
Con este código debería ver el valor de payload por el monitor serie.
Igual que en el mensaje
How to take data from Api ans watch it in monitor serial in Arduino IDE? - How-To - The Internet of Thinger
que la respuesta obtenida con http.GET era -1 en el código que he pegado aquí, con
Serial.println (httpCode);
No muestra nada por el monitor serie.
¿Tienes idea que estoy haciendo mal?
Saludos!