I am integrating thingspeak and arduino plus Esp8266 mean making a simple project which contain my android app to update the thingspeak channel and then want to read the data of that channel via arduino uno. the android parts works fine but at the arduino side i got stuck and unable to read the channel data via esp8266(attached to my arduino uno). Here is my code.any help would be appreciated. it shows in serial monitor connecting to thingspeak.com and show nothing next.

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX

char ssid[] = "M T G";            // your network SSID (name)
char pass[] = "androidGUII";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "arduino.cc";

// Initialize the Ethernet client object
WiFiEspClient client;
static const char* host = "api.thingspeak.com";
static const char* apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
void setup()
  // initialize serial for debugging
  // initialize serial for ESP module
  // initialize ESP module

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  // you're connected now, so print out the data
  Serial.println("You're connected to the network");

void loop()
      const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
  client.println("GET /channels/xxxxxxx/feeds.json?api_key=xxxxxxxxxx&results=2 HTTP/1.1");
  while (client.available() == 0);  // wait till something comes in; you may want to add a timeout here
  client.stop();  // close socket
void printWifiStatus()
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.println(" dBm");
  • 1
  • dear this is my question which is not answered yet there too..thats' why i posted it here.thank for your time – mtg Mar 16 '18 at 19:16
  • @mtg client.read() reads a single byte. I doubt that's what you want. – gre_gor Mar 16 '18 at 19:40

HTTP GET request needs to end with an empty line and HTTP 1.1 requires a Host header.

Add an empty line and eiher change the HTTP version to 1.0

client.print("GET /channels/421932/feeds.json?api_key=");
client.println("&results=2 HTTP/1.0");
client.println(); // empty line

or add the Host header

client.print("GET /channels/421932/feeds.json?api_key=");
client.println("&results=2 HTTP/1.1");
client.println(); // empty line
| improve this answer | |
  • the empty line is only for requests with body like POST request, to mark the start of the request body – Juraj Mar 16 '18 at 19:28
  • @Juraj I tested it in Python by sending it over TCP with only a single pair of "\r\n" and the server didn't respond. Had to be "\r\n\r\n". – gre_gor Mar 16 '18 at 19:31
  • I looked up the protocol. It requires the empty line after the header for all requests – Juraj Mar 16 '18 at 19:43
  • WiFiEsp] Connecting to api.thingspeak.com 13 [WiFiEsp] Disconnecting 3 //now it shows this in serial monitor – mtg Mar 17 '18 at 6:26
  • use the library github.com/mathworks/thingspeak-arduino – Juraj Mar 17 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.