0
votes

I have deployed the Bluemix GeoSpatial starter application in Bluemix.

It works fine until I want to connect to the Watson IoT Platform instead of the demo MQTT server.

I changed mqtt1.m2m4connectedlife.com to dzqml6.messaging.internetofthings.ibmcloud.com and added mqtt_uid and mqtt_pw to the start parameters jsonObject.

I created an API key in the Watson IoT Platform Dashboard and used these values for mqtt_uid and mqtt_pw.

Then I get an "Error: Connection refused: Not authorized" in the log when starting the application.

Then I also tried the apiKey and apiToken form the Watson IoT Platform environment variables for mqtt_uid and mqtt_pw but still got the same error.

I also tried different values for clientid and notify/input topics but without success.

I read a couple of other posts with similar errors that were resolved after some time because of a delay between when an organization is created and is distributed to all servers.

https://developer.ibm.com/answers/questions/163862/iot-cloud-error-not-authorized.html

So I waited a day but still have the same error.

I also added myself as a permanent member to the organization as suggested in this post: Refused: not authorized error occurs with IBM IoT Foundation on Bluemix

I would be very gratefull for any assistance on this!

2

2 Answers

2
votes

There's a part of the Node.js code in the starter app that directly subscribes to the notify topic. Is the auth error coming from that subscription attempt? If so, did you modify that part of the code to pass credentials?

Here are the lines of code in the app.js that I'm referring to.

var clientId = 'geo-quickstart:' + port;
//create the MQTT client and subscribe
client = mqtt.createClient(1883,"mqtt1.m2m4connectedlife.com", { "clientId": clientId } );
console.log("Subscribing to topic: " + notify_topic_string + "\n");
client.subscribe(notify_topic_string);

If you aren't passing the credentials on the createClient call, try adding a parameter {username: "user", password: "pass"} to the list of arguments.

0
votes

When you make an MQTT connection by using an API key, ensure that the following points apply:

The MQTT client ID is in the format: a:orgId:appId
The MQTT user name is the API key: such as a-orgId-a84ps90Ajs
The MQTT password is the authentication token: such as MP$08VKz!8rXwnR-Q*

See the documentation for more details. If you still experience errors, let us know your 6 character org ID for the IoT service and we can check logs to troubleshoot why you are getting authorization error.