ESP32 won't connect to cayenne


#1

Hi,
I downloaded the cayenne esp32 library off github and my esp32 is running other code fine. I ran the sample wifi code to ensure it was connecting to the internet, all fine.
I selected the sparkfun esp8266 thing on the my devices part, then in the code I changed the username password and client ID to match the cayenne website, and typed in my wifi details, when I uploaded the code there are no errors looks like it is working, but then on the cayenne webite it is waiting for board to connect. The board never connects, so I don’t know what to do next. Please help ASAP.


#2

add #define CAYENNE_DEBUG in your code and check serial monitor for any error.


#3

I done this, there is nothing printing to my serial monitor and it is at the correct baud-rate.


#4

can you share the link of the device you are using.


#5

https://learn.sparkfun.com/tutorials/esp32-thing-hookup-guide/introduction

Thank you for your help!


#6

have you installed the ESP32 Board Package https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions ??


#7

Yes there are all installed, board is working fine apart from not being able to connect to cayenne.


#8
#include <WiFi.h>
 
const char* ssid = "yourNetworkName";
const char* password =  "yourNetworkPass";
 
void setup() {
 
  Serial.begin(115200);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
 
}
 
void loop() {
 
}

this is the code i used to connect my wifi connection. Everything was ok. Then below is the code i used to send to cayenne. Please anyone help!

// This example shows how to connect to Cayenne using an ESP32 and send/receive sample data.
// Make sure you install the ESP32 Board Package and select the correct ESP32 board before compiling.
// To install the ESP32 Board Package follow the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.

#define CAYENNE_DEBUG 
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

unsigned long lastMillis = 0;

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();

}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
	// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
	Cayenne.virtualWrite(0, millis());
	// Some examples of other functions you can use to send data.
	//Cayenne.celsiusWrite(1, 22.0);
	//Cayenne.luxWrite(2, 700);
	//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

#10

/*
This example shows how to connect to Cayenne using an ESP32 and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. If you have not already installed the ESP32 Board Package install it using the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.
  2. Select your ESP32 board from the Tools menu.
  3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  4. Set the network name and password.
  5. Compile and upload the sketch.
  6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    */

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>

// WiFi network info.
char ssid[] = “vodafone-3C65”;
char wifiPassword[] = “xxxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “6xxxxxx”;
char password[] = “4cxxxxxxx”;
char clientID[] = “2xxxxxxx”;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

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

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g
//CAYENNE_IN(1)
//for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
getValue.setError(“Error message”); // uncomment this line
}

I have added getValue.setError(“Error message”); and got the error [532] WiFi not present.
Ran it a few times and the error message is intermittent?

any ideas??


#11

hey got it working,

for anyone with the same issue this is the code i got to work.

/*
This example shows how to connect to Cayenne using an ESP32 and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. If you have not already installed the ESP32 Board Package install it using the instructions here: https://github.com/espressif/arduino-esp32/blob/master/README.md#installation-instructions.
  2. Select your ESP32 board from the Tools menu.
  3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  4. Set the network name and password.
  5. Compile and upload the sketch.
  6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    */

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#define EspSerial Serial
#include <CayenneMQTTESP32.h>
#include <WiFi.h>

// WiFi network info.
const char* ssid = “xxxxxxxxxxxxxxx”;
const char* password = “xxxxxxxxxxxxxxx”;

char ssidc[] = “vxxxxxxxxxxxxxxx”;
char passwordc[] = “xxxxxxxxxxxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “xxxxxxxxxxxxxxx”;
char wifipassword[] = “xxxxxxxxxxxxxxx”;
char clientID[] = “2xxxxxxxxxxxxxxx”;

void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(“Connecting to WiFi…”);
}

Serial.println(“Connected to the WiFi network”);
Cayenne.begin(username, wifipassword, clientID, ssidc, passwordc);

}

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

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
Cayenne.celsiusWrite(1, 22.0);
Cayenne.luxWrite(2, 700);
Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g
//CAYENNE_IN(1)
//for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
getValue.setError(“Error message”);
//getValue.setError();
}


#12

Thank you!!!

I thought I was going crazy. Your solution helped get the Adafruit HUZZAH32 Feather to run the sample!

Hopefully Cayenne update the library or sample code so it works first time out the box.