B
B
blackgrom2021-11-02 14:55:32
Arduino
blackgrom, 2021-11-02 14:55:32

How to fetch data from ThingHTTP using nodemcu v3(esp8266)?

using the ThingSpeak site in the ThingHTTP section, I receive data from one site, when checking the api, everything is fine, the data comes without errors, and now I need to receive the same data from this api and store it in a variable in nodemcu v3 (esp8266).

#include <ESP8266WiFi.h>
 
const char* ssid     = "KBTU_wireless";
const char* password = "KBTUwireless!";
 
const char* host = "api.thingspeak.com";
 

 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
 
}//end setup
 
void loop() {

WiFiClient Client;

const int httpsPort = 80;

if (!Client.connect(host, httpsPort)) {

Serial.println("connection failed");

}

String url = "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=967QSN6K892SR33T";

Client.print(String("GET ") + url + " HTTP/1.1\r\n" +

"Host: " + host = "\r\n" );

String line = Client.readStringUntil('\r');

Serial.println(line);



}


the code seems to be correct, but I get only spaces and nothing else
here api https://api.thingspeak.com/apps/thinghttp/send_req...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question