Now that we have our HTML and CSS files, let's create the JavaScript file that will make the magic of MQTT happen:
- Inside the scripts folder, create a file called index.js using an HTML editor.
- Type the following into the index.js file and save it:
function moveForward() { client = new Paho.MQTT.Client("m10.cloudmqtt.com", 38215, "web_" + parseInt(Math.random() * 100, 10)); // set callback handlers client.onConnectionLost = onConnectionLost; var options = { useSSL: true, userName: "vectydkb", password: "ZpiPufitxnnT", onSuccess: sendMoveForwardMessage, onFailure: doFail } // connect the client client.connect(options);}// called when the client connectsfunction sendMoveForwardMessage() ...