08-02-2018 9:40 AM - edited 02-04-2024 4:11 AM
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
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.