Not autorised when trying to connect with cumulocity IoT with MQTT

Hi,

i’m currently testing the MQTT connection with Cumulocity IoT Cloud using the tutorial that can be found under:

cumulocity guides under device SDK → mqtt examples->hello-mqtt-python

However, when i added on_connect callback and started the script, everytime it gives me result code 5, which is “not authorised” :

  0%|                                                                                                                                                                         | 0/50 [00:00<?, ?it/s]
Connect result = 5
  2%|███▏                                                                                                                                                             | 1/50 [00:01<00:49,  1.00s/it]
Connect result = 5
  6%|█████████▋                                                                                                                                                       | 3/50 [00:03<00:47,  1.00s/it]
Connect result = 5
 14%|██████████████████████▌                                                                                                                                          | 7/50 [00:07<00:43,  1.00s/it]
Connect result = 5
 30%|████████████████████████████████████████████████                                                                                                                | 15/50 [00:15<00:35,  1.00s/it]
Connect result = 5
 62%|███████████████████████████████████████████████████████████████████████████████████████████████████▏                                                            | 31/50 [00:31<00:19,  1.00s/it]
Connect result = 5
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:50<00:00,  1.00s/it]
Connection failed

and here is the setting for connection, except added an on_connect callback to prevent the program from stucking at loop and the tenant, username, password settings, all the rest code is just as same as the tutorial in above link.

mqtt_2

In Addition, for the field “serverUrl”, i have also tried the one for my cockipt, but it also not work.

Does anyone know how to solve it? It’s currently a free trial account btw.

Best regards

@lewei.he ,

Can you provide your full Tenant URL ?Just wanted to know if you are US or Eu-latest instance . Server URL can be different for different instance.

Regards
Gyan

@Gyan_Awasthi1 ,

Yes, im using Eu-latest instance, so the address is (sry, have to place it with picture since the forum don’t allow me to include links) :

Screenshot_20200909_105258

i also tried to use this address for serverUrl field, but it also don’t work.

PS: the account information used here is the one that i uses to login to the web application (the one that registered on softwareag for the free trial)

Regards
Lewei

@lewei.he,
I tried to create a MQTT device using MQTT box . It was successful. I used host as tyker.eu-latest.cumulocity.com

Can you try to do a simple test using MQTTbox first and see if you are able to create devices .
If it works fine. It means there is some issue with Python sample.

@Gyan_Awasthi1,

I tried to use MQTTbox and it not work. After searching in internet and reading the REST API docs, I find out that the username and password i used to login to cumulocity cannot be used to create new device, also has no right of using any MQTT or REST API functions. Although it has the role “admins”, it can’t even create a simulated device via the cumulocity web application.

What finally found out was that i should use
management/devicebootstrap as username
and Fhdt1bb1f as password

if i want to register a device or say require new device credentials and i have to use this credentials. Why it is not clearly pointed out (at least, not that misleading) on the tutorial page here MQTT client examples - Cumulocity IoT Guides