Connection Refused - Bad Username or Password

Manfred Kreidl on 27 Oct 2021
Latest activity Reply by Alain Kuchta on 4 Nov 2021

Hello, I try to publish to an already working channel. I have created an device and using the credentials shown in the image. I would like connect via TCP and port 1883 to mqtt3.thingspeak.com My Library always returns "Connection Refused - Bad Username or Password". This means it already has got a CONNACK reply. I have already successfully published an item to another server. So, the Lib basically works and I am using it correctly. I do not have mistyped the credentials. Could there be something on the Thingspeak side? Could you please help me with that? Thank you in advance.

Alain Kuchta
Alain Kuchta on 27 Oct 2021 (Edited on 27 Oct 2021)

Can you confirm that the Client Identifer (a.k.a "ClientId" or "client_id") has been set in the device code to match exactly the value provided by ThingSpeak in the picture you shared?

This is a requirement of ThingSpeak's MQTT broker that is not typical of public test brokers; the username, password, and ClientId must all match exactly the values given.

For background, this answer talks about why the ClientID is important:

https://www.mathworks.com/matlabcentral/discussions/thingspeak/710834-new-websocket-software-example/2395769#reply_2395769

Manfred Kreidl
Manfred Kreidl on 27 Oct 2021

I used another test client. There also only username and password is required. The connection is also refused. - Please see the attached screenshot.

Manfred Kreidl
Manfred Kreidl on 27 Oct 2021

Found the possibility to set the client ID in this test client. - Now connection and publish works.

Is there a way of connecting via TCP port 1883 without giving the Client ID?

Vinod
Vinod on 27 Oct 2021

The triplet of ClientID, Username and Password are required to connect to mqtt3.thingspeak.com

Manfred Kreidl
Manfred Kreidl on 27 Oct 2021

In the Library I use there it is only possible to set username and password. I cannot set a parameter "Client ID". Must the client ID be present when connecting to ThingSpeak?

Alain Kuchta
Alain Kuchta on 28 Oct 2021

Can you share a link to the library?

Yes, sending client ID is a requirement when connecting to ThingSpeak.

Manfred Kreidl
Manfred Kreidl on 29 Oct 2021 (Edited on 29 Oct 2021)

http://codesys-mqtt-library.sourceforge.net/

It is a library for the PLC development system CoDeSys 3

The developer of the lib tells that a random value is generated for the client ID. He also give the information that he will add a new parameter to set the client ID. So, hopefully it will then work with ThingSpeak soon.

Is there the possibility to connect via TCP port 1883 to mqtt.thingspeak.com without giving the client ID?

Alain Kuchta
Alain Kuchta on 4 Nov 2021

I agree that the library doesn't provide an option to set client ID, which is unfortunate.

It is not possible to connect to our broker at mqtt3.thingspeak.com without providing a client ID.

Manfred Kreidl
Manfred Kreidl on 4 Nov 2021

In the meantime a new version of the library allows to set also the client ID. So, now I can connect an publish to ThingSpeak. What I observe is that a successful connection to ThingSpeak takes several retries until a CONNACK is received. This also depends on the network to publish values from. From home connects after a few replies. At work it takes a lot of retries until the connection works. Do you have an idea why?

Alain Kuchta
Alain Kuchta on 4 Nov 2021

Glad to hear you were able to get a connection established!

There can be approximately 1-2 seconds between your client sending a CONNECT packet and a CONNACK being received from the broker. We're currently looking into ways to improve this. I suspect this is why it appears to take multiple tries to connect in both situations; only one CONNECT packet is needed, but it takes some time for the reply to arrive.

I'm not sure why the time to connect varies between work and home.

Manfred Kreidl
Manfred Kreidl on 27 Oct 2021

I would like to add something to this topic: I can login to this test broker an publish an item: maqiatto.com For test reasons I have set the password to the one in my ThingSpeak device online. - It is still possible to connect and publish. So, I think the issue is located on the ThingSpeak side. It is not possible to establish a TCP connection (port 1883) because the devices username and/or password is not recognized to be correct.

Tags

No tags entered yet.