Arduino UNO WiFi to cayenne dash board

Hello Craig,
I haven’t worked on the issue for some time, but I gave it another try recently, using MQTT this time. unfortunately I got stuck very soon :frowning: Cayenne gives me a 32-characters MQTT Username. With the Arduino-with-built-in-WiFi, the MQTT settings (including MQTT Server, MQTT Username and MQTT password) are specified via a configuration webpage (e.g. opening a chrome webpage specifying the private IP address of the Arduino). Unfortunately the Arduino-with-built-in-WiFi accepts MQTT usernames of max 31 characters :frowning:

I have been told to perform a firmware upgrade of my arduino-with-built-in-wifi, but I’m quite reluctant to do so as it sounds like a very heavy operation for solving such a basic issue. Moreover, a Firmware Upgrade is a very risky operation…

Regards

The firmware upgrade is very painless and quick. It makes the UI a lot more friendly. However, the MQTT option you see there will only allow very basic operations. May or may not be what you’re looking for.

In related news, looks like people are successful in connecting to Blynk. Might be time for me to revisit this board again…

I don’t think anyone has been able to get Uno Wifi up on Cayenne yet in any
way.

I guess I ought to try.

Not much support from Arduino on this board.

Craig

Hello,
I have made some progresses using the PubSubClient library for MQTT from Nick O’Leary, available on Github : GitHub - knolleary/pubsubclient: A client library for the Arduino Ethernet Shield that provides support for MQTT..

My arduino gets rejected by the Cayenne server with an MQTT Return Code 2, i.e. “Connection refused, identifier rejected”.

I’m using the credentials provided on the cayenne webpage.

The sketch is below:

/*
Basic MQTT example

This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:

  • publishes “hello world” to the topic “outTopic”
  • subscribes to the topic “inTopic”, printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary

It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the ‘mqtt_reconnect_nonblocking’ example for how to
achieve the same result without blocking the main loop.

*/

#include <PubSubClient.h>
#include <WiFi.h>

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();
}
const char* mqtt_server = “mqtt.mydevices.com”;

WiFiClient ethClient;
PubSubClient client(ethClient);

void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);
// Attempt to connect
//Client ID, MQTT Username, MQTT Password
if (client.connect(“a5a72834-3244-11e7-85a7-c34806d4e04d”,“ae8d97b0-f7680-11e6-81d7-ad79ee868075”,“f6fb0e6176dbb2527617a2333f14859b3e9fdaf8”)) {
Serial.println(“connected”);
// Once connected, publish an announcement…
client.publish(“outTopic”,“hello world”);
// … and resubscribe
client.subscribe(“inTopic”);
} else {
Serial.print(“failed, rc=”);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup()
{
Serial.begin(9600);

client.setServer(mqtt_server, 1883);
client.setCallback(callback);

// Allow the hardware to sort itself out
delay(1500);
}

void loop()
{
if (!client.connected()) {
reconnect();
}
client.loop();
}

I get the following error:
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds

Any help identifying why my device gets rejected would be appreciated :wink:

Thanks

Can you post the full output from the serial monitor?

there is nothing more than what I posted :

Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds

etc…

Do you have port 1883 open on your router/firewall?

One of the first things I tried. Couldn’t get Nick’s PubSub working with Cayenne.

It’s on my list of things to look at.

Cheers,

Craig

Duh…this is for the uno wifi, I didn’t scroll up. Yes that library will not work unless you flash the WiFi Link firmware.

Hello, yes the port is open. The Cayenne MQTT Server rejects the connection request, hence it receives the request

Not sure why you say “it will not work”. My sketch based on Nick’s pubSub library definitely compiles on the Arduino with built-in WiFi. According to Nick, his library is not built for a specific hardware.

The Cayenne MQTT Server receives the connection request, and rejects it. I’m trying to figure out why. One of the ways to debug would be to attempts an MQTT connection to another MQTT Server. But I could not find any “online test” MQTT server : any advise would be appreciated.
Thanks

1 Like

I found this video as a problem solver, This may help you. All MQTT Errors explained very well and Suggester Different troubleshooting techniques [Solved] Attempting MQTT connection... Failed. rc=-1 or rc=-2 or rc=-4, try again in 5 seconds - YouTube