ESP8266 with Cayenne

Dear All,

I would like to use my plenty stock of EPS8266 with Caynne under Arduino. I have a prepared Arduino IDE and can work with ESP8266 well.

But I can’t understand how to set-up (initialize) Cayenne when I already have WiFi connection. Could some one drom me a code?

The problem is that any examples are with WiFi initialization by Cayenne. And this is not a good option.

I am using this code.

Cayenne-ESP8266.txt (573 Bytes)

But again, you pass SSD and pass directly to constructor of Cayenne:

Cayenne.begin(token, ssid, password);

I need something like:


You could try Cayenne.config(auth) in setup, but I don’t know if it will find your WiFi handle.


Which Lib shoud I include then?

I’d try this. Note that it relies on having WiFi setup already, externally. Cayenne is just overloading Blynk, so you can reference this: External ESP8266 Configuration - #6 by schmorrison - Hardware and Blynk Libraries - Blynk Community

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"

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

void setup()
//  Cayenne.begin(token, ssid, password);
  Cayenne.config(token); //If this doesn't work, try Blynk.config(token);

void loop()

The first option:
Doesn’t work. There is no such a constructor.

The second option:

Returns infinitely:
Connecting to

Maybe try this, make a new file called CayenneESP8266WiFiClient.h and use
it instead of CayenneWifiClient.h. I added config to the public calls and directed it to use the Cayenne domain and port. I still think the problem is that the Cayenne functions do not have a handle. Hard to really help you since you haven’t shared your current sketch.


#include "CayenneClient.h"

class CayenneWiFiClient : public CayenneClient
 * Begins Cayenne session
 * @param token Authentication token from Cayenne site
 * @param ssid WiFi network id
 * @param pass WiFi network password
 void begin(const char* token, const char* ssid, const char* pass)
 Blynk.begin(token, ssid, pass, CAYENNE_DOMAIN, CAYENNE_PORT);

 void config(const char* auth,
 const char* domain = CAYENNE_DOMAIN,
 uint16_t    port   = CAYENNE_PORT)
        this->conn.begin(domain, port);


CayenneWiFiClient Cayenne;


The sketch is pretty simple:

#include <ESP8266WiFi.h>
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneESP8266WiFiClient.h"
char token[] = "";
const char* ssid = "";
const char* password = "";
void setup() {
  // put your setup code here, to run once:
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
  //  Cayenne.begin(token, ssid, password);
  Cayenne.config(token); //If this doesn't work, try Blynk.config(token);

void loop() {
  // put your main code here, to run repeatedly:;

And the solution doesn’t help:

C:\Users\vkrav\AppData\Local\Temp\build1af443b1e6fff8ae03707f8515d69806.tmp\sketch\CayenneESP8266WiFiClient.h:24:9: error: ‘Base’ has not been declared



C:\Users\vkrav\AppData\Local\Temp\build1af443b1e6fff8ae03707f8515d69806.tmp\sketch\CayenneESP8266WiFiClient.h:25:15: error: ‘class CayenneWiFiClient’ has no member named ‘conn’

     this->conn.begin(domain, port);

Why do you need the WiFi seperate anyway? I’m sure we can come up with a solution,but I see no reason based on your sketch.


This sketch is an example. I don’t want to amend the main sketch that consist is more than 12 separate files and a hundred of routines.

The idea not to use Wi-Fi connection made by Cayenne is in the following: there is a number of WiFi managers that can provide you with connection setup in a case of non-connected. It is obvious that it is not possible to use them if the sketch uses Cayenne WiFi connection. That’s the reason.

Try replacing the config function in CayennneESP8266WiFiClient.h with this:

void config(const char* auth)
    Blynk.config(auth, CAYENNE_DOMAIN, CAYENNE_PORT);

Compiles for me anyway. I have no unit here to test with.


I had a problem while connecting with ESP8266 to Cayenne. The problem was in my router. Try enabling port 8442 pot on your router. Than it may connect to the Cayenne with ESP device.

I tested the code with Blynk.config(token) and WiFi connection with ESP libraries rather than Cayenne libraries. It works fine.

Nice, so if we add the following to CayenneWifiClient.h, we can use it as Cayenne.config(auth); after WiFi has already been configured.

void config(const char* auth)
    Blynk.config(auth, CAYENNE_DOMAIN, CAYENNE_PORT);

@bestes, please consider this. I think it is useful for allowing other WiFi things as well as Cayenne.



1 Like

Yes, that works very well! Thank you. Now I can turn On and Off the onboard LED via my computer!

But, could you please tell me why Cayenne uses Blynk routines? Aren’t they two different solutions?


Blynk is open source, and I love that Cayenne has adopted it and instead focused on a comprehensive dashboard solution with solid cloud services.

MQTT support is also based on another open source initiative called Paho.

I know the development team is currently focussing on getting LoRa devices on Cayenne.

IMHO, we can achieve more greatness if our creative juices are used to create novel solutions instead of re-inventing the wheel.

I wish government would embrace the open source movement too instead of battling over the best way to skin a cat. Where did that idiom come from anyway? :stuck_out_tongue:



1 Like