Connecting to Cayenne with Sparkfun ESP8266

I am having trouble connecting to Cayenne with my Arduino Uno via a sparkfun ESP8266 shield. I have verified that I get a connection with the shield yet when I run the script given by Cayenne to connect with their dashboard, nothing happens.


Hello and Welcome to Cayenne community,

Which script you are running? Can you post it here? Also did you get some errors ? Can you post them also here?

Thank you :slight_smile:

Hello. I should preface this reply by saying that I am new to coding as I just got my first Arduino… Anyways I followed this code giving my sparkfun to get my wifi shield online (first posted script). I then tried to connect my device to cayene with the second script that I posted but nothing happen. No error message, no response on serial monitor. I guess I need to somehow combine the two scripts or change the board connection #include but I am not sure.

// Library Includes //
// SoftwareSerial is required (even you don't intend on
// using it).
#include <SoftwareSerial.h> 
#include <SparkFunESP8266WiFi.h>

// WiFi Network Definitions //
// Replace these two character strings with the name and
// password of your WiFi network.
const char mySSID[] = "yourSSIDhere";
const char myPSK[] = "yourPWDhere";

// ESP8266Server definition //
// server object used towards the end of the demo.
// (This is only global because it's called in both setup()
// and loop()).
ESP8266Server server = ESP8266Server(80);

// HTTP Strings //
const char destServer[] = "";
const String htmlHeader = "HTTP/1.1 200 OK\r\n"
                          "Content-Type: text/html\r\n"
                          "Connection: close\r\n\r\n"
                          "<!DOCTYPE HTML>\r\n"

const String httpRequest = "GET / HTTP/1.1\n"
                           "Connection: close\n\n";

// All functions called from setup() are defined below the
// loop() function. They modularized to make it easier to
// copy/paste into sketches of your own.
void setup() 
  // Serial Monitor is used to control the demo and view
  // debug information.
  serialTrigger(F("Press any key to begin."));

  // initializeESP8266() verifies communication with the WiFi
  // shield, and sets it up.

  // connectESP8266() connects to the defined WiFi network.

  // displayConnectInfo prints the Shield's local IP
  // and the network it's connected to.

  serialTrigger(F("Press any key to connect client."));
  serialTrigger(F("Press any key to test server."));

void loop() 

void initializeESP8266()
  // esp8266.begin() verifies that the ESP8266 is operational
  // and sets it up for the rest of the sketch.
  // It returns either true or false -- indicating whether
  // communication was successul or not.
  // true
  int test = esp8266.begin();
  if (test != true)
    Serial.println(F("Error talking to ESP8266."));
  Serial.println(F("ESP8266 Shield Present"));

void connectESP8266()
  // The ESP8266 can be set to one of three modes:
  //  1 - ESP8266_MODE_STA - Station only
  //  2 - ESP8266_MODE_AP - Access point only
  //  3 - ESP8266_MODE_STAAP - Station/AP combo
  // Use esp8266.getMode() to check which mode it's in:
  int retVal = esp8266.getMode();
  if (retVal != ESP8266_MODE_STA)
  { // If it's not in station mode.
    // Use esp8266.setMode([mode]) to set it to a specified
    // mode.
    retVal = esp8266.setMode(ESP8266_MODE_STA);
    if (retVal < 0)
      Serial.println(F("Error setting mode."));
  Serial.println(F("Mode set to station"));

  // esp8266.status() indicates the ESP8266's WiFi connect
  // status.
  // A return value of 1 indicates the device is already
  // connected. 0 indicates disconnected. (Negative values
  // equate to communication errors.)
  retVal = esp8266.status();
  if (retVal <= 0)
    Serial.print(F("Connecting to "));
    // esp8266.connect([ssid], [psk]) connects the ESP8266
    // to a network.
    // On success the connect function returns a value >0
    // On fail, the function will either return:
    //  -1: TIMEOUT - The library has a set 30s timeout
    //  -3: FAIL - Couldn't connect to network.
    retVal = esp8266.connect(mySSID, myPSK);
    if (retVal < 0)
      Serial.println(F("Error connecting"));

void displayConnectInfo()
  char connectedSSID[24];
  memset(connectedSSID, 0, 24);
  // esp8266.getAP() can be used to check which AP the
  // ESP8266 is connected to. It returns an error code.
  // The connected AP is returned by reference as a parameter.
  int retVal = esp8266.getAP(connectedSSID);
  if (retVal > 0)
    Serial.print(F("Connected to: "));

  // esp8266.localIP returns an IPAddress variable with the
  // ESP8266's current local IP address.
  IPAddress myIP = esp8266.localIP();
  Serial.print(F("My IP: ")); Serial.println(myIP);

void clientDemo()
  // To use the ESP8266 as a TCP client, use the 
  // ESP8266Client class. First, create an object:
  ESP8266Client client;

  // ESP8266Client connect([server], [port]) is used to 
  // connect to a server (const char * or IPAddress) on
  // a specified port.
  // Returns: 1 on success, 2 on already connected,
  // negative on fail (-1=TIMEOUT, -3=FAIL).
  int retVal = client.connect(destServer, 80);
  if (retVal <= 0)
    Serial.println(F("Failed to connect to server."));

  // print and write can be used to send data to a connected
  // client connection.

  // available() will return the number of characters
  // currently in the receive buffer.
  while (client.available())
    Serial.write(; // read() gets the FIFO char
  // connected() is a boolean return value - 1 if the 
  // connection is active, 0 if it's closed.
  if (client.connected())
    client.stop(); // stop() closes a TCP connection.

void serverSetup()
  // begin initializes a ESP8266Server object. It will
  // start a server on the port specified in the object's
  // constructor (in global area)
  Serial.print(F("Server started! Go to "));

void serverDemo()
  // available() is an ESP8266Server function which will
  // return an ESP8266Client object for printing and reading.
  // available() has one parameter -- a timeout value. This
  // is the number of milliseconds the function waits,
  // checking for a connection.
  ESP8266Client client = server.available(500);
  if (client) 
    Serial.println(F("Client Connected!"));
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
      if (client.available()) 
        char c =;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) 
          Serial.println(F("Sending HTML page"));
          // send a standard http response header:
          String htmlBody;
          // output the value of each analog input pin
          for (int a = 0; a < 6; a++)
            htmlBody += "A";
            htmlBody += String(a);
            htmlBody += ": ";
            htmlBody += String(analogRead(a));
            htmlBody += "<br>\n";
          htmlBody += "</html>\n";
        if (c == '\n') 
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') 
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println(F("Client disconnected"));

// errorLoop prints an error code, then loops forever.
void errorLoop(int error)
  Serial.print(F("Error: ")); Serial.println(error);
  Serial.println(F("Looping forever."));
  for (;;)

// serialTrigger prints a message, then waits for something
// to come in from the serial port.
void serialTrigger(String message)
  while (!Serial.available())
  while (Serial.available());

second script

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneWiFi.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "cfhiqovqw9";
// Your network name and password.
char ssid[] = "NetworkSSID";
char password[] = "NetworkPassword";

void setup()
	Cayenne.begin(token, ssid, password);

void loop()

What do you have running on your ESP? is it connected via UART Serial(i.e. Serial on a Uno, pins 0 & 1? You need to have AT firmware installed on it in order to use the shield with cayenne. See this post about installing AT firmware on your device if you need to.

I am following alone with this post by Sparkfun:

See this post for using the shield you linked.

Hi Adam,

I spent a few hours this morning trying to follow along with that post and was running into issues. I was able to zip the ESP8266HardwareSerial.log folder but itcontained no libraries and even though I was able to successfully convert the CayenneESP8266Shield.log file into a .h file, the arduino IDE sill sayed the file did not exist.


I just downloaded and changed the extension on the zip, and can confirm there are files in there.

Did you install the ESP library?
Did you install the Cayenne library?
Did you install the ESP9266HardwareSerial library from this zip?



Hi Craig,

Thanks for the prompt response. I have installed both the ESP and Cayenne libraries from the Arduino IDE. I then downloaded the ESP8266HArdwareSerial.log folder that you mentioned in a previous post and converted it to a .zip file. However when I go to “add .zip library” on the arduino IDE it says error “zip doesn’t contain a library”.

Now it is saying #include <CayenneESP8266Shield.h> yet when I go through my windows explorer files i can clearly see that file.


Ah, ok.

There is a note in the example sketch:

You should install the library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)

Give that a try.



That is what I have been trying. When I go that route it says

"Arduino: 1.8.3 (Windows 10), Board: “Arduino/Genuino Uno”

C:\Users\Matt\Documents\Arduino\libraries\learning_stuff\learning_stuff.ino\learning_stuff.ino.ino:24:34: fatal error: CayenneESP8266Shield.h: No such file or directory

#include <CayenneESP8266Shield.h>


compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno. Zip doesn’t contain a library
at javax.swing.AbstractButton.fireActionPerformed(
at javax.swing.AbstractButton$Handler.actionPerformed(
at javax.swing.DefaultButtonModel.fireActionPerformed(
at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.AbstractButton.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(
at java.awt.Component.processMouseEvent(
at javax.swing.JComponent.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEventImpl(
at java.awt.EventQueue.access$500(
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
Zip doesn’t contain a library

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.