I am using blynk 2.0 and want to make a http request to get some data.
I have to use WIFI client as http.begin in <ESP8266HTTPClient.h> needs it. (Makes no sense as my NODE8266 is already connected to internet.
My code
void getDataFromHTTP() {
String url = "https://blynk.cloud/external/api/get?token=xxx&v2";
resp = http.begin(wifiClient,url);
Serial.println("Resp: "+resp);
Serial.println("WIFI: "+WiFi.status());
httpResponseCode = http.GET();
Serial.println("httpResponseCode");
Serial.println(httpResponseCode);
httpData = http.getString();
Serial.println("httpData");
Serial.println(httpData)
}
the http response is code is -5. (Not able to establish connection)
Is there a simple way in blynk 2.0 to make a http call and store the value in a variable.
my setup method
void setup() {
Serial.begin(115200);
delay(100);
pinMode(LED1, OUTPUT); // Initialize the LED1 pin as an output
pinMode(LED2, OUTPUT); // Initialize the LED1 pin as an output
pinMode(relay, OUTPUT); // Initialize the Relay Pin D1 pin as an output
WiFi.mode(WIFI_STA);
WiFi.begin(BLYNK_WIFI_SSID, BLYNK_WIFI_PASS);
BlynkEdgent.begin();
Blynk.syncAll();
// Timers to call functions every x intervals (16 availabe, 0th is a sacrificial timer due to blynk bug)
timer.setTimeout(3600000L, [] () {} ); // sacrificial Function - not used anywhere in logic.
loggerTimerID = timer.setInterval(1L*60L*60L*1000L, resetIsWriteToTermial); // Once every 1 hour
controllerTimerID = timer.setInterval(delayTime, getDataFromHTTP); // Setting Timer with Default Values to run every 15 secs, Check BLYNK_WRITE(VPIN_CHECKINTERVAL) for overridding
}
and loop
void loop() {
BlynkEdgent.run();
timer.run();
OUTPUT:
esp:
I:
httpResponseCode
-5
httpData