Esp8266


#101

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


#102

Hi @vivekgs27,

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

Cheers,

Craig


NodeMCU ESP8266 - Not posible to connect WIFI
#103

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


#104

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


#105

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?


#106

Take a look at this post WifiShield with arduino uno compiling error


#107

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…


#108

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


#109

Not a coading guy that’s why having trouble


#110

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


#111

What about mqtt code you mentioned to try earlier


#112

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

#113

Thnx will try it soon and then report u


#114


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


#115

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.


#116

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


#117

Hi @vapor83,

It is very confusing. Doesn’t help that there are multiple ways to program, multiple softwares, and multiple ESP devices and boards based on those devices.

I prefer to tell people to just program the ESP directly with Cayenne, and use an I/O expander if you need more I/O.

So I don’t have an answer for you. What we need to do is try, and let us know what works. Then we can create a detailed procedure and a table showing what works.

Cheers,

Craig


#118

I’ve been using mainly the .22 which seems to work good. Just starting to use the 1.1 and that seems to work fine too. Just a fyi


#119

Don’t think it matters as long as it works.

What ESP, and how are you programming them?

Can you share a rough procedure for us?

Cheers,

Craig


#120

So I’ve been using the ESP8266-01 & the new ESP8266-01S. I take a proto shield and mount the ESP to it or use a breadboard adapter if you want to be able to remove it (see pics). I basically make a ESP shield that goes to the Serial RX/TX with a switch on it for easy uploading to the arduino.

First you need to upload the AT firmware for the ESP so the arduino/cayenne can talk to it using AT commands. You need the following: ESP_download_tool_v2.4 & the ESP_IOT_SDK 1.0.0. I included just the files you need here for simplicity. Open the download tool and setup the files and addresses(ADDR) exactly as shown.

blank.bin --> 0xFE000
boot_v1.5.bin --> 0x00000
user1.1024.new.2.bin --> 0x1000
blank.bin --> 0x7E000
esp_init_data_default.bin --> 0xFC000

  1. Connect ESP and put into firmware upload mode by grounding GPIO0 and then powering on the ESP.
  2. Make sure SpiAutoSet is checked & select your correct com port. Baud usually works at 230400 but try lower if you have troubles.
  3. Click Start.

Now you should have AT command set firmware! Unground GPIO0 and reboot the ESP. Open up a serial terminal and test with come commands.

Set Baud at 115200 and try typing AT. It should send back “ok” if everything worked.

Now we need to set it to station mode. Type AT+CWMODE_DEF? and it will probably return the number 2… we want it to say 1. Now type AT+CWMODE_DEF=1 and it should say ok. Verify with the first command AT+CWMODE_DEF? and it should return 1 now. Now enter AT+RST and it will reboot and say ready. Now were ready to connect it to our sketch/cayenne.

You need to include this library : #include <CayenneESP8266Shield.h>
In the header of your sketch you need to define which serial were using which is usually the first Serial (pins 0 &1):
#define EspSerial Serial
ESP8266 wifi(EspSerial);

Then in setup you need to tell it to start by:
EspSerial.begin(1115200);
delay(10);

So when were done it looks like this:

#include <CayenneESP8266Shield.h>

char token[] = "blah";
char ssid[] = "devices";
char password[] = "password";

#define EspSerial Serial
ESP8266 wifi(EspSerial);

void setup()
{
	EspSerial.begin(115200);
	delay(10);

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

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

Thats it!


Connecting to Cayenne with Sparkfun ESP8266
Cayenne Esp8266 + Arduino [Confused]
Add directions for connecting device to internet
Need help connecting to Cayenne with ESP8266