function startMqttServer(xxx) {
if (!window.WebSocket) {
$("#connect").html("\
Get a new Web Browser!
\
\
Your browser does not support WebSockets. This example will not work properly.
\
Please use a Web Browser with WebSockets support (WebKit or Google Chrome).\
\
");
} else {
if (xxx != undefined) {
UNIT_ID = xxx;
initmqtt(UNIT_ID);
}
}
}
function initmqtt(UNIT_ID) {
var destination = ["044A58B5F3E74B6CBBAD9EC33A339C22/" + UNIT_ID + "/PC/ALL"]; //订阅主题
var iotpush = CreateIOTPushObject();
//iotpush.clientId = iotpush.guid().replace(/\-/g, "");
iotpush.clientId = iotpush.uuid(16, 16);
iotpush.destination = destination;
iotpush.setClient();
iotpush.client.onMessageArrived = onMessageArrived; //信息接收
iotpush.setConnect();
}
//信息接收
function onMessageArrived(message) {
//console.log(message);
var objMsg = JSON.parse(message.payloadString);
if (objMsg.TYPE == "WARN"){//报警信息推送
setRealWarnList(objMsg);
}
else if (objMsg.TYPE == "INFO"){
}
}
function setRealWarnList(objMsg) {
var strHtml = "";
var msg = objMsg.WARNINFO;
var INFO = objMsg.DVCINFO;
console.log(JSON.stringify(objMsg));
var snbj = $(".ssbj-list." + msg.DEVICE_ID + "." + msg.EVENT_TYPE);
var bjno = 0;
if (snbj != null && snbj.length>0) {
var text = snbj.find(".bj-number").text();
if (text != "") {
bjno = text;
}
snbj.remove();
}
bjno++;
strHtml += "";
strHtml += "
" + bjno + "
";
strHtml += "
" + msg.EVENT_TYPE_NAME + "预警
";
strHtml += "
设备:" + msg.DEVICE_SN + "
"
+ "
设备名称:" + INFO.DEVICE_NAME + "
"
+ "
类型名称:" + INFO.DEVICE_TYPE_NAME + "
"
+ "
报警原因:" + msg.ALARM_REASONNAME + "
"
+ "
位置:" + msg.ADDR + "
"
+ "
时间:" + msg.ALARM_TIME +"
"
+ "
描述:" + msg.DESCRIBE + "
"
+"
";
strHtml += "
";
if(msg.TYPE == '3' && msg.SYS_ID=='05'){
paly1();
}else{
paly();
}
tk(strHtml,msg.DEVICE_SN,msg.ALARM_REASONNAME,msg.ADDR,msg.ALARM_TIME);
// $("#divWarnReal").prepend(strHtml);
// $('#divWarnReal .ssbj-list').unbind('dblclick');
// $("#divWarnReal .ssbj-list").dblclick(function () {
// dvc_position($(this).attr("dvcid"));
// });
}