ESP8266 with Cayenne


#1

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.


#2

I am using this code.

Cayenne-ESP8266.txt (573 Bytes)


#3

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

Cayenne.begin(token, ssid, password);

I need something like:

Cayenne.begin(token)


#4

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

Craig


#5

Which Lib shoud I include then?


#6

I’d try this. Note that it relies on having WiFi setup already, externally. Cayenne is just overloading Blynk, so you can reference this: http://community.blynk.cc/t/external-esp8266-configuration/1820/6

//#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()
{
  Serial.begin(9600);
//  Cayenne.begin(token, ssid, password);
  Cayenne.config(token); //If this doesn't work, try Blynk.config(token);
}

void loop()
{
  Cayenne.run();
}

#7

The first option:
Cayenne.config(token);
Doesn’t work. There is no such a constructor.

The second option:
Blynk.config(token);

Returns infinitely:
Connecting to cloud.blynk.cc:8442


#8

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.

#ifndef _CAYENNEESP8266WIFICLIENT_h
#define _CAYENNEESP8266WIFICLIENT_h

#include "CayenneClient.h"

class CayenneWiFiClient : public CayenneClient
{
public:
 /**
 * 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)
    {
        Base::begin(auth);
        this->conn.begin(domain, port);
    }


};

CayenneWiFiClient Cayenne;

#endif

#9

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:
  Serial.begin(115200);
  Serial.println("YaHoo...");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }
  //  Cayenne.begin(token, ssid, password);
  Cayenne.config(token); //If this doesn't work, try Blynk.config(token);
  //Blynk.config(token);
}

void loop() {
  // put your main code here, to run repeatedly:
  Cayenne.run();
  delay(100);
  Serial.print(".");
}

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

     Base::begin(auth);

     ^

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);

#10

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.

Craig


#11

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.


#12

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.

Craig


#13

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.


#14

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.

Thx,

Craig


#15

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?


#16

@vkravchenko,

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:

Cheers,

Craig