Arduino UNO WiFi to cayenne dash board


#21

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


#22

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…


#23

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


#24

Hello,
I have made some progresses using the PubSubClient library for MQTT from Nick O’Leary, available on Github : https://github.com/knolleary/pubsubclient/.

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


#25

Can you post the full output from the serial monitor?


Please make support for Arudino Uno WiFi
#26

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…


#27

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


#28

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


#29

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.


#30

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


#31

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