I am new to Cayenne and am having problems connecting my ESP32 to the dashboard. I have followed the steps and downloaded the code and put in the correct MQTTusername, MQTTpassword, and clientID for connecting to the broker. The wifi does connect from my ESP32 but I just get a loading screen on the dashboard after the code is uploaded. Attached is my code, serial monitor, and dashboard.
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
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");
}
I tried to connect my esp32 , esp8266 and both connected successfully. can you try connecting to cayenne using telnet mqtt.mydevices.com 1883 in your pc terminal. some firewall maybe be blocking.
/*
Cayenne Light Switch Example
This sketch shows how to set up a Light Switch with Cayenne.
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. In the Cayenne Dashboard add a new Light Switch Widget.
2. Select a virtual channel number for the widget.
3. Set the VIRTUAL_CHANNEL value below to virtual channel you selected.
4. Attach the negative leg of an LED to ground and the other leg to the selected digital pin.
Schematic:
[Ground] -- [LED] -- [Resistor] -- [Digital Pin]
5. Set the ACTUATOR_PIN value below to the pin number you used when connecting your LED.
6. Set the Cayenne authentication info to match the authentication info from the Dashboard.
7. Compile and upload this sketch.
8. Once the Arduino connects to the Dashboard you can use the widget button to turn the LED on and off.
*/
#include <CayenneMQTTESP8266.h>
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define CAYENNE_DEBUG
// WiFi network info.
char ssid[] = "XXX";
char wifiPassword[] = "XXX";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL 1
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
void setup()
{
Serial.begin(115200);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
}
#include <CayenneMQTTESP8266.h>
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define CAYENNE_DEBUG
// WiFi network info.
char ssid[] = "XXX";
char wifiPassword[] = "XXX";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
#define VIRTUAL_CHANNEL 1
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
void setup()
{
Serial.begin(115200);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
}
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);
}
Strange thing is that yesterday with another weemos D1 It worked well (and still working well with this D1) but it seems impossible to connect a new one