The index.js file we created contains functions that subscribe our HTML JavaScript client to the distance topic:
function subscribeDistanceData() {
client = new Paho.MQTT.Client("m10.cloudmqtt.com", 38215, "web_" + parseInt(Math.random() * 100, 10));
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
var options = {
useSSL: true,
userName: "vectydkb",
password: "ZpiPufitxnnT",
onSuccess: onsubsribeDistanceDataSuccess,
onFailure: doFail
}
// connect the client
client.connect(options);
}
function onsubsribeDistanceDataSuccess() {
client.subscribe("distance");
alert("Subscribed to distance data");
}
Similar to the code we wrote...