WebSockets Interface

The deviceWISE Cloud provides a WebSockets interface to enable the use of the MQTT protocol to interact with the platform from within a browser.

MQTT over Websockets

  • Supports WebSockets as defined by RFC 6455.
  • Must use "mqttv3.1" as the WebSocket protocol name.
  • Client connects HTTP and HTTPS endpoints defined on the API Endpoints page in the Portal.
    • MQTT: ws://<open server>/mqtt
    • MQTT with TLS/SSL encryption: wss://<open server>/mqtt-ssl
  • Allows usage of all the normal MQTT interface functionality including the TR50 commands and additional Server Topics.

Paho Javascript Client

Example connecting to the WebSockets interface over MQTT with SSL:
var client = new Paho.MQTT.Client('api.devicewise.com', 443, '/mqtt-ssl', 'clientId-or-appId');
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({
  userName : 'username-or-thingKey',
  password : 'password-or-appToken',
  useSSL: true,
  mqttVersion : 3,
  onSuccess : onConnect,
  onFailure : onFailure
});
 
function onConnect() {
  console.log('Connected.');
  client.subscribe('reply');
 
  var cmd = JSON.stringify({
    "cmd": {
      "command": "diag.ping"
    }
  });
  
  var message = new Paho.MQTT.Message(cmd);
  message.destinationName = 'api';
  client.send(message);
}

function onFailure(responseObject) {
  console.log('Failed to connect: ' + responseObject.errorMessage);
}
function onConnectionLost(responseObject) {
  console.log('Connection lost: ' + responseObject.errorMessage);
}
function onMessageArrived(message) {
  console.log(message.destinationName + ': ' + message.payloadString);
}