Esp8266

How to connect my ESP8266 12-E to cayenne MQTT API dashboard. Even though I included cayenne MQTT libraries , there is no separate connection example in the IDE for other than Arduino devices like ESP8266.
By this I am unable to connect to cayenne dashboard? Please help me out

ESP is not currently supported. I am currently modifying the source code to
make it work, but having an issue with some overload casting in the
publishing bits.

This is the real reason ESPs are not supported as they aren’t Arduinos. It
is brilliant that some smart cookie made them work at all with the IDE.

Cheers,

Craif

1 Like

I’m working on a write up on how to get an ESP talking to Cayenne with MQTT. Should have it ready tomorrow or Monday.

3 Likes

Okay- I pointed my Arduino library loader to my Download/CayenneMQTT.zip file.
I can see the CayenneMQTT library files in Arduino IDE.

Hi,
I don’t have any shield in particular to connect my arduino to the cloud. what i have is a ESP8266-01 module so could anyone help me how to connect my ESP8266-01 module to cayenne please and if possible please do send me the code

Thanks
Vivek

Hi @vivekgs27,

Check out this HowTo, and let us know how you make out.

Cheers,

Craig

Hi @kreggly,
I’m sorry that i dont have ESP8266-07 module. The one which i have is ESP8266-01 module
If anyone could help me with the code with cayenne please

The howto and code works for all ESPs. You just need to set GPIO zero to gnd and toggle RST/PD to get into programming mode on the ESP-01.

The 07 and 12 boards just have more flash space and I/O.

Cheers,

Craig

I am using ESP8266-01 with Arduino Uno. I want to send data to cayenne dashboard from my sensor connected to arduino board. Is it possible to use cayenne for this type of connection and if it is possible can anyone upload some example code?

Take a look at this post WifiShield with arduino uno compiling error - #11 by kreggly

hi
Is it possible to work with the ethernet 5100 and esp8266 ?
Want to develop the algorithm having the possibilty to transmitt data when ehernet cable available otherwise Wifi…

Everything is possible.

It would have to be a new combined library though, and that is a lot of
work.

I wonder if you could run Cayenne on an ESP as well, then pass it data
through to the serial port. The ESP could be set to wake-up on pin change.
Just use the same dashboard ID on both.

Cheers,

Craig

1 Like

Not a coading guy that’s why having trouble

Want to develop a deviceby reading a digital input value use esp or Ethernet …

What about mqtt code you mentioned to try earlier

I have the Arduino code to use MQTT here Using Node-RED as a Local Fallback Server however it’s not a copy and paste. Try the code below and see if it works. I did not test it.

Change settings on the line “if (client.connect(clientID, username, password)) {” to match your MQTT info.

#include <PubSubClient.h>
#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* mqtt_server = "mqtt.mydevices.com";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup() {
  int timeoutcounter = 0;
  
  Serial.begin(9600);
  WiFi.begin(ssid, password);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  while (WiFi.status() != WL_CONNECTED) {
    timeoutcounter++;
    delay(500);
    Serial.print(".");
    if (timeoutcounter >= 30){
      Serial.println("Failed to connect to wireless - sleeping for 5 minutes");
      delay(100);
      ESP.deepSleep(300000000, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
  
  Serial.println("");
  Serial.println("WiFi connected");

  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(clientID, username, password)) {
      Serial.println("connected");
      client.subscribe("CayenneInput");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Sleep for 5 minutes before retrying
      Serial.println("Failed to connect to MQTT server - sleeping for 5 minutes");
      delay(100);
      ESP.deepSleep(300000000, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  float t = 20.2;
  float h = 30.3;
  float hif = 40.4;
  
  String mqtt_message = "temp,f=" + String(t) + ",channel=10";
  mqtt_message.toCharArray(msg, 50);

  Serial.print("Publish message: ");
  Serial.println(msg);
  client.publish("arduino_1_data", msg, true);

  mqtt_message = "rel_hum,rel_hum=" + String(h) + ",channel=11";
  mqtt_message.toCharArray(msg, 50);

  Serial.print("Publish message: ");
  Serial.println(msg);
  client.publish("arduino_1_data", msg, true);

  mqtt_message = "temp,f=" + String(hif) + ",channel=12";
  mqtt_message.toCharArray(msg, 50);

  Serial.print("Publish message: ");
  Serial.println(msg);
  client.publish("arduino_1_data", msg, true);
  delay(5000);
}
1 Like

Thnx will try it soon and then report u

in this video they have connected esp8266 to cayyene .
does it work?

Hi @priyaranjan391 and welcome to the Cayenne Community.

Yes, we have many users on this forum who have successfully connected ESP8266 microcontrollers to Cayenne and used them in projects using the code in post #20 of this thread. Give it a shot and let us know if you run into any questions or trouble.

What is the prefered version of AT commands with cayenne? 0.22 or the new 1.1?