Cayenne Esp8266 + Arduino [Confused]


#1

I know there are a lot of topics about this, i already read all of them, but i don´t understand which code goes on arduino and what code on ESP

As i understand being wrong or correct, i need to upload a code to the ESP to connect the arduino and cayenne via serial wifi (RX TX), also i need a code to make the arduino read the serial wifi, the codes i got are meant to used on the arduino but why it asks for wifi SSID and pasword, that sounds as a ESP2866 code, so i´m confused, which code do i use on arduino and wich on ESP, or i have to program only the arduino?.

I got this from other topics

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

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "<your_token>";
// Your network name and password.
char ssid[] = "<your_ssid>";
char password[] = "<your_pwd>";

void setup()
{
  // initialize digital pin 2 as an output.
  pinMode(2, OUTPUT);
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
}

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

// This function will be called every time a Dashboard widget writes a value to Virtual Pin 2.
CAYENNE_IN(V2)
{
  CAYENNE_LOG("Got a value: %s", getValue.asStr());
  int i = getValue.asInt();
  
  if (i == 0)
  {
    digitalWrite(2, LOW);
  }
  else
  {
    digitalWrite(2, HIGH);
  }  
}

And this:

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

    // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
    char token[] = "AuthenticationToken";
    // Your network name and password.
    char ssid[] = "";
    char password[] = "";
    // Set ESP8266 Serial object
    #define EspSerial Serial1
    ESP8266 wifi(EspSerial);

    void setup()
    {
      Serial.begin(9600);
      delay(10);
      // Set ESP8266 baud rate

      EspSerial.begin(115200);
      delay(10);

      Cayenne.begin(token, wifi, ssid, password);
    }

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

#2

so which one are you trying to run it on? Are you using a Arduino with a ESP as your wifi connection, or no arduino and running just the esp?


#3

i want to use Esp (Esp8266 12E) as wifi shield for the arduino Mega


#4

You want to use your second example… Which serial port are you using for the esp on the mega? You need to make sure if you enable prints or debug that it doesn’t print to the same port as the esp or you will drop your connection.

    #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
    #include <CayenneESP8266Shield.h>

    // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
    char token[] = "AuthenticationToken";
    // Your network name and password.
    char ssid[] = "";
    char password[] = "";
    // Set ESP8266 Serial object
    #define EspSerial Serial1
    ESP8266 wifi(EspSerial);

    void setup()
    {
      Serial.begin(9600);
      delay(10);
      // Set ESP8266 baud rate

      EspSerial.begin(115200);
      delay(10);

      Cayenne.begin(token, wifi, ssid, password);
    }

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

#5

so this code is it for arduino or ESP? and if it is for arduino what do i put on ESP


#6

arduino. you need to flash the esp with AT firmware. Checkout this post with how to install the AT firmware


#7

so, when using the esp as wifi shield, it has to be programed with AT commands, but if you want to use as microcontroler it needs to be programed with arduino idle. then i need to reflash AT Firmware on ESP


#8

wow, that was helpfull, thnks


#9

yup you got it correct. Basically the arduino and the esp communicate over a serial connection using AT commands. Here is a PDF of the AT commands for reference. Once you flash the esp with the AT firmware, you need to go in to your serial monitor and run a couple AT commands yourself to set it up to talk correctly, ex AT+CWMODE_DEF=0, AT+CWAUTOCONN=0, and i run at 9600 baud so AT+UART_DEF=9600,8,1,0,0.

https://github.com/vapor83/ESPfiles/blob/master/Esp8266_at_instruction_set_en_v1.5.4_0.pdf


#10

so, the other code is meant to use the esp as microcontroler via cayenne?


#11

If i understand you correctly, yes. It would just be the ESP, no arduino counterpart. Then you flash that code onto the ESP rather than the AT firmware.

Arduino + ESP = AT Firmware
ESP only = cayenne program firmware

You are less likely to have connectivity problems if you just run the ESP by itself. My simple programs like controlling 1 relay I use the ESP by itself. For the complicated stuff I use the arduino because it supports more libraries.


#12

Yeah i am also making a kind of complex project, wich needs lots of in/outs,wifi and also an extra pair of RX TX for bluethoot, that´s why mega 2560 fits really well,
And now because of the info you gave me, i can continue working
THREAD CLOSED.


#13

Bumping this old thread to share that we’ve just provided support in our MQTT Arduino library for using ESP8266 as a shield :slight_smile: We’ve done basic testing and works well. Give it a try for your project and let us know how it works out for you !

Here is the updated library on our github:

and the code can be found here: