jsスレーブアクセスlot hub mqttws 31からデータを取得
1428 ワード
var hostname = '',
port = ,
clientId = '',
timeout = ,
keepAlive = ,
cleanSession = true,
ssl = true,
userName = '',
password = '',
topic = '';
client = new Paho.MQTT.Client(hostname, port, clientId);
//
var options = {
invocationContext: {
host : hostname,
port: port,
path: client.path,
clientId: clientId
},
timeout: timeout,
keepAliveInterval: keepAlive,
cleanSession: cleanSession,
useSSL: ssl,
userName: userName,
password: password,
onSuccess: onConnect,
onFailure: function(){
console.log(12112);
}
};
client.connect(options);
//
function onConnect() {
console.log("onConnected");
client.subscribe(topic);
//
//
message = new Paho.MQTT.Message("");
message.destinationName = topic;
// client.send(message);
}
client.onConnectionLost = onConnectionLost;
//
client.onMessageArrived = onMessageArrived;
//
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
console.log(" ");
}
}
function onMessageArrived(message) {
console.log(" :"+message.payloadString);
}