cancel
Showing results for 
Search instead for 
Did you mean: 

IoT: failed to connect MQTT client

0 Kudos

Hi Expert,

I tried to connect the MQTT end point by Paho Client via javascript.

here is my code:

jQuery.sap.require( 'MOTT_WS/testMQTT_WS/libs/paho-v101' );
/* global Paho:true */
sap.ui.define([
	"sap/ui/core/mvc/Controller"
], function (Controller) {
	"use strict";


	return Controller.extend("MOTT_WS.testMQTT_WS.controller.View1", {
		publish_message: function () {
			debugger;
			this.createPahoClient();
		},


		/**
		 * Creates a new Paho client
		 */
		createPahoClient: function () {
			var sBaseUrl = 'wss://iotmmsACCOUNT.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/ws/mqtt';
			this._oPahoClient = new Paho.MQTT.Client(sBaseUrl,'device ID');
			var that = this;
			var oOptions = {
				timeout: 5,
				mqttVersion: 3
			};
			this._oPahoClient.connect(oOptions);
		}


	});
});


and I got following error message:

WebSocket connection to 'wss://iotmmsp1909990701trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/ws/mqtt' failed: Error during WebSocket handshake: Unexpected response code: 200

did I missing something when I tried to connect the client?

Could you please give me some advice?

Thanks and regards,

Shujian

Accepted Solutions (1)

Accepted Solutions (1)

anton_levin
Advisor
Advisor
0 Kudos

Please, re-check with documentation [1]

URL ends with "../com.sap.iotservices.mms/v1/api/ws/mqtt", whereas yours is "../com.sap.iotservices.mms/v1/ws/mqtt"

[1] https://help.sap.com/viewer/7436c3125dd5491f939689f18954b1e9/Cloud/en-US/56d02092904346c1a605713021d...

0 Kudos

Hi Anton,

after the adjustment, the error was gone, but the stats is 101:

and then I tried to send message by Paho client with code:

var oMessage = new Paho.MQTT.Message( sMessage );
				oMessage.qos = 0;
				oMessage.destinationName = 'iot/data/40f95ff7-53b4-4363-a327-6324907775f1';
				this._oPahoClient.send( oMessage );

and I got following error:

could you please so kindly give me some advice?

anton_levin
Advisor
Advisor
0 Kudos

I would suggest checking the documentation of the Paho library (for JS) and maybe also try to make it work with a different language first (Python, for example). Code snippet could be found in the StarterKit https://github.com/SAP/iot-starterkit/tree/master/neo/examples/python/mqtt-over-wss

Answers (0)