Help with 1st Cayenee connected device

I can’t figure out what I am missed here but I bought my 1st NODEMCU Amica ESP8266 and I am trying to connect to it using Cayenne.
Here is the code(credentials x’ed out) I am using which uploads fine to the device and I can see its on my wifi network but it does not show up in my devices in my app or online. It shows its still looking for it. Any ideas?

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

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

// WiFi network info.
char ssid = “gggggggg”;
char wifiPassword = “tmih8iy51e2tn”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxxxxx-xxxxxxx-1xxxxxx-axxxx-5xxxxxxxxxxxxxxxxxxx”;
char password = “4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
char clientID = “4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9”;

unsigned long lastMillis = 0;

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

void loop() {
Cayenne.loop();

//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
	lastMillis = millis();
	//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
	Cayenne.virtualWrite(0, lastMillis);
	//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(“CAYENNE_IN_DEFAULT(%u) - %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

Your sketch looks ok. Can you get the log/debug info and post that? You need to uncomment #define CAYENNE_DEBUG and CAYENNE_PRINT which you already have I see. Connect to the ESP8266 serial, reset the ESP and see what the log says and post that here. It should give some clue as to where its getting hung up.

Forgive my ignorance Mitch but can you explain or point me in the right direction on how to log/debug please

Sure, no problem! At the top of your sketch, there is the following code:

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

Uncomment the #define CAYENNE_DEBUG by removing the two “//” in front of it and upload the sketch. Now what you want to do is open your serial monitor in the Arduino IDE under the Tools menu that the ESP is connected to and you should see some information printing out with what it is doing. It will tell you if it connected or not and other connection/status info. if it doesn’t say “Connection ok”, its having a problem somewhere. Post what its saying here.

Let me know if you run into issues or have more questions. :slight_smile:

1 Like

Thanks for taking the time to explain how to debug. Here is what I found.
It looks good to me but its not showing up in my cayenne account so I am
not sure what I am missing here. Let me know your thoughts.
Thanks again,
Sam

[86891] Connection ok
[86892] Publish: topic 1, channel 0, value 86891, subkey , key
[87005] Publish: topic 1, channel 1, value 22.000, subkey c, key temp
[87075] Publish: topic 1, channel 2, value 700.000, subkey lux, key lum
[87136] Publish: topic 1, channel 3, value 50, subkey cm, key prox
I €¤=1üÿ[265] Connecting to Cheese
[1268] Connected to WiFi
[1268] IP: 172.20.10.2
[1268] Connecting to mqtt.mydevices.com:1883
[1491] Connected
[1656] Publish: topic 5, channel 65534, value NodeMCU, subkey , key
[1766] Publish: topic 7, channel 65534, value Xtensa32, subkey , key
[1869] Publish: topic 8, channel 65534, value 80000000, subkey , key
[1940] Publish: topic 6, channel 65534, value v1, subkey , key
[10037] Publish: topic 1, channel 0, value 10037, subkey , key
[10116] Publish: topic 1, channel 1, value 22.000, subkey c, key temp
[10180] Publish: topic 1, channel 2, value 700.000, subkey lux, key lum
[10251] Publish: topic 1, channel 3, value 50, subkey cm, key prox
[13327] Connection ok
[20346] Publish: topic 1, channel 0, value 20346, subkey , key
[21237] Publish: topic 1, channel 1, value 22.000, subkey c, key temp
[21399] Publish: topic 1, channel 2, value 700.000, subkey lux, key lum
[21475] Publish: topic 1, channel 3, value 50, subkey cm, key prox
[23533] Connection ok

It looks like its getting connected to the server just fine & its sending values so thats good. Lets try re-adding the board to your dashboard. I’ll go through it so you can be sure its correct :slight_smile:

On your dashboard on the left above your device list select “Add New…” then select “Device/Widget”. On the right side now select “Generic ESP8266”. You will see the info populate in the fields on the new page. Double check that the username & password are the same as your sketch, & then copy/paste the new Client ID into your sketch. You can put in a name for the board now below the MQTT server field or you can do this after, doesn’t matter. Below that you should see a spinning disk & “waiting for board to connect.”

Now, with the new client ID in your sketch, upload it to your device and see if it recognizes the device on the dashboard. Check your serial output and see if its connected. Once the device connects the webpage should change to a almost blank page & then some boxes with your channels (0,1,2,3) will appear.

It should be all good then. Let us know how it goes.

1 Like

My man!!! Thanks Mitch, it works like a charm. Now for step two which is
making it report back a sensor status which is a digital input that tells
me when a float switch is lifted. I may have more question lol, but I will
try this on my own 1st. Thanks again
Regards,
Sam

1 Like