Getting started with MQTT connection to Cayenne


#1

I am new to Cayenne, but have some experience building my own sensor network within my home that communicates with the cloud via MQTT.

In looking to get my feet wet with Cayenne, I have tried to test out the Dashboard by connecting to it via MQTT and posting some made-up data. From https://cayenne.mydevices.com/cayenne/dashboard/first-visit/devices I click “Bring your own Thing” and then get a screen that provides my MQTT username, password, client ID, server address and port.

Transferring these to my desktop MQTT client, I can easily log into Cayenne’s MQTT broker with my Cayenne username and password. My understanding is that once I am connected to Cayenne’s MQTT broker, my Dashboard page should turn into an actual dashboard – instead I am stuck at https://cayenne.mydevices.com/cayenne/dashboard/first-visit/api/step-2 with a “Waiting for board to connect” message.

Posting actual test data using the topic format outlined at https://mydevices.com/cayenne/docs/bring-your-own-thing-api/#cayenne-mqtt-api-mqtt-messaging-topics doesn’t seem to help either. Still can’t get to an actual dashboard, still seeing “Waiting for board to connect”.

What am I doing wrong?


#2

Hi @jwosnick,

Welcome to the Cayenne community! Your understanding is correct, once your desktop mqtt client connects to Cayenne, your dashboard should appear. Is there a way to verify if your desktop is actually publishing to Cayenne or not?

~B


#3

A couple things to check:

Are you using mqttfx? The generated username/password/client ID are longer than what the standard allows so other programs may possibly have an issue with it. I know mqttfx works.

Try a copy/paste of the username/password if you didn’t already. It’s long and easy to make a typo.

The username/password to connect with mqtt is not your cayenne username/password. The mqtt login info will be displayed on the page you see after creating the device and can also be viewed on the settings page for the device.

After you connect with the username/password you dashboard will instantly change, you don’t have to send any data for that to happen.


#4

OK, after a bit of digging, I think I’ve figured out what is going on.

The standard MQTT implementation only requires MQTT brokers to accept client IDs of up to 23 characters. See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html#_Toc385349767 for details.

It turns out that the MQTT client program I was using (MQTT-Spy, for anyone interested) automatically truncates supplied Client IDs beyond 23 characters. I guess this isn’t strictly required, but it is based on the quasi-standard indicated above (i.e. that there are brokers out there that would not accept a Client ID longer than 23 characters).

As the Cayenne Client ID is longer than 23 characters, the Cayenne MQTT broker was apparently not “seeing” my MQTT client. When I tried with another MQTT client software app that does not truncate IDs, everything worked, I got my Cayenne dashboard, and was able to post “fake data” to it.


#5

Just saw your post. That’s exactly what the issue is – Cayenne’s MQTT ClientID is longer than the protocol specification, and my existing client silently truncated it. With MQTTfx everything worked fine.


#6

@bestes @rsiegel any news on getting the client ID length shortened? I think even just any new devices going forward should be fine so it doesn’t break current devices.


#7

I don’t know that it’s been a major priority on our side since the newest specification allows client IDs of the length that we use in Cayenne, but it’s certainly come up with a few of you here, as well as back in January in this thread. It seems that a lot of MQTT software on the web does not conform with the update in 3.1.1. I’ll log an issue internally to consider making this an option when adding a new MQTT device (or just shortening it across the board on new Client ID generation).


#8

Even a note in the documentation files (something to the effect of “some MQTT clients truncate Client IDs longer than 23 characters, please check yours”) would be helpful.


#9

We can definitely add a note for that!

@bmeriwether


#10

@bestes @jwosnick I have just added a TIP item in a bunch of places where Client ID is mentioned. Will go out in the next doc push. Thanks for the suggestion.