//var msgpack = require("msgpack-lite");

// Assuming paho mqtt library is included.
host = "172.16.13.128";
client = new Paho.MQTT.Client(host, port=1884, "2343");

client.onMessageArrived = onMessage;
client.onConnectionLost = onConnectionLost;
client.connect({onSuccess: onConnect});

function onConnect(){
    alert("Client Connected");
    client.subscribe("Demo");
    var buffer = msgpack.encode({"message": "Hello"});
    message = new Paho.MQTT.Message(buffer);
    message.destinationName = "Demo";

    // // Can use publish or send here.
    client.publish(message);
}

function onConnectionLost(responseObject){
    if(responseObject.errorCode !== 0){
        console.log("onConnectionLost:" + responseObject.errorMessage);
    }
}

function onMessage(message){
    messageb = message.payloadBytes;

    if(message.payloadBytes = 1){
        // Sent checking ready command.

    }
}