Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By shawnleo
#56219 Hi Thanks for your code. It works great!

However before finding your code, I was trying to use the following url as http request to get data from thingspeak.

https://thingspeak.com/channels/channel/fields/1/last

As you can see this uses HTTPS but it skipped the ThingHTTP app step. I have been trying many many times but still did not get it working. Would you please advise how to do it? Sorry I am just a noob and thanks a lot for your help!

oeyhaga wrote:Seem I'v solved the problem. As easy as adding a longer delay after GET command.
Changed delay(10); to delay(500)

Finaly I can continue with the project after many hours scratching my head :P

Code: Select all#include <ESP8266WiFi.h>
 
const char* ssid     = "NAME";
const char* password = "PASSWORD";
 
const char* host = "api.thingspeak.com";
 
int value = 1;
 
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() {
  delay(5000);
   
  Serial.print("Connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient Client;
  const int httpPort = 80;
  if (!Client.connect(host, httpPort)) {
    Serial.println("Connection failed");
    return;
  }
 
  // We now create a URI for the request
  String url = "/apps/thinghttp/send_request?api_key=PAW43HX9QN9SVOW1";
  Serial.print("Requesting URL: ");
  Serial.println(host + url);
  Serial.println(String("TRY: ") + value + ".");
 
  // This will send the request to the server
 Client.print(String("GET ") + url + "&headers=false" + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  delay(500);
 
  // Read all the lines of the reply from server and print them to Serial
  while(Client.available()){
  String line = Client.readStringUntil('\r');
  Serial.println(line);
 }
  Serial.println("");
  Serial.println(String("Try nr. ") + value + " is finished.");
  Serial.println("Waiting for next try...");
  Serial.println("");
  value = value + 1;
  delay(20000);
}
User avatar
By Aish kagalkar
#64007 is this code only for esp8266???? i mean esp8266 as standalone.
i have used esp8266 with arduino uno to connect to thingspeak using AT commands. I am using Software Serial for communciation.
now i am trying to use get data from thinghttp , but not getting how.
the blog i refered is [url]
https://techwithabhi.wordpress.com/2015 ... speak-com/
https://techwithabhi.wordpress.com/2015 ... fi-module/