You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.8 KiB
85 lines
2.8 KiB
|
|
function startMqttServer(xxx) {
|
|
if (!window.WebSocket) {
|
|
$("#connect").html("\
|
|
<h1>Get a new Web Browser!</h1>\
|
|
<p>\
|
|
Your browser does not support WebSockets. This example will not work properly.<br>\
|
|
Please use a Web Browser with WebSockets support (WebKit or Google Chrome).\
|
|
</p>\
|
|
");
|
|
} 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 += "<div class='ssbj-list " + msg.DEVICE_ID + " " + msg.EVENT_TYPE + "' dvcid='" + msg.DEVICE_ID + "' >";
|
|
strHtml += "<div class='bj-number'>" + bjno + "</div>";
|
|
strHtml += "<div class='ssbj-list-tit'>" + msg.EVENT_TYPE_NAME + "<span style='background: #ab4649;'>预警</span></div>";
|
|
strHtml += "<div class='ssbj-list-con'><p>设备:" + msg.DEVICE_SN + "</p>"
|
|
+ "<p>设备名称:" + INFO.DEVICE_NAME + "</p>"
|
|
+ "<p>类型名称:" + INFO.DEVICE_TYPE_NAME + "</p>"
|
|
+ "<p>报警原因:" + msg.ALARM_REASONNAME + "</p>"
|
|
+ "<p>位置:" + msg.ADDR + "</p>"
|
|
+ "<p>时间:" + msg.ALARM_TIME +"</p>"
|
|
+ "<p>描述:" + msg.DESCRIBE + "</p>"
|
|
+"</div>";
|
|
strHtml += "</div>";
|
|
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"));
|
|
// });
|
|
|
|
}
|
|
|