- 积分
- 243
- 金钱
- 209
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
中级会员
- 积分
- 243
- 金钱
- 209
- HASS币
- 0
|
设备:海尔小管家吸顶灯
和之前发的帖子探讨的问题一样,在大佬的指引下用fiddler抓了官方网页控制端的包,发现疑似连接到www.doketled.net:8083/mqtt,但直接访问失败(bad request),请问实质上海尔智控是连接到他们的官方MQTT服务器进行统一调控吗?
代码如下,跪求大佬分析:
client = new Paho.MQTT.Client('www.dotekled.net', 8083, "user" + "oM_VjuB0oZKPuR9bINoLQBTo3sqo");
client.onMessageArrived = onMessageArrived;
client.connect({
onSuccess: onConnect,
onFailure: onFail,
cleanSession: true
});
function onConnect() {
console.log("onConnect");
$(".content ul li").each(function (i) {
var deviceID = $(this).attr("id");
console.log(deviceID);
var topicOut = 'device/' + deviceID + '/out';
var topicOnline = 'device/' + deviceID + '/online';
var controllerUnbind = 'control/unbind';
client.subscribe(topicOnline);
client.subscribe(topicOut);
client.subscribe(controllerUnbind);
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message("query");
message.destinationName = topicIn;
client.send(message);
});
}
function onFail() {
console.log('连接异常');
}
function onMessageArrived(message) {
console.log("onMessageArrived:" + message.payloadString + '-------' + message.destinationName);
var t = message.destinationName.split("/");
var dID = t[1];
var state = t[2];
var tID = "#" + dID;
if (state == 'online') {
$(".content ul").find(tID).each(function (i) {
var olPl = message.payloadString;
if (olPl == 1) {
$(this).find('.item-subtitle span').text('设备在线');
$(this).find('.item-title span').css("color", '#43F0FE');
$(this).find('.item-subtitle span').css("color", '#43F0FE');
$(this).find('.secIcon').attr('src','img/secureLog.png');
var topicIn = 'device/' + dID + '/in';
message = new Paho.MQTT.Message("query");
message.destinationName = topicIn;
client.send(message);
} else {
$(this).find('.item-subtitle span').text('设备离线');
$(this).find('.item-title span').css("color", 'black');
$(this).find('.item-subtitle span').css("color", 'black');
$(this).find(".item-content").find(".item-media").find("img").attr("src", "img/lightOff.png");
$(this).css("background-color", "white");
$(this).find('.secIcon').attr('src','img/secureLogDark.png');
}
});
}
if (state == 'out') {
$(".content ul").find(tID).each(function (i) {
var switchState = message.payloadString.substring(1, 2);
if (switchState == '0') {
$(this).find(".item-content").find(".item-media").find("img").attr("src", "img/lightOff.png");
$(this).css("background-color", "white");
} else {
$(this).find(".item-content").find(".item-media").find("img").attr("src", "img/lightOn.png");
$(this).css("background-color", "lightcyan");
}
});
}
if (message.destinationName == 'control/unbind' && message.payloadString) {
window.location.href = updateUrl("http://dotekled.net/deviceList");
}
}
// 0 点灯状态 , 1 编辑状态
var editStatue = 0;
$(".content ul li .item-inner").each(function (i) {
$(this).click(function () {
var olState = $(this).find('.item-subtitle span').text();
var deviceID = $(this).parent().parent().attr("id");
if (editStatue == 0) {
var lightImg = $(this).parent().find('.item-media').find('img').attr("src");
console.log("list " + i + " deviceID" + deviceID);
console.log(lightImg);
if(olState == '设备在线'){
var order = "";
if (lightImg == "img/lightOn.png") {
order = "10";
$(this).parent().find('.item-media').find('img').attr("src", "img/lightOff.png");
$(this).parent().parent().css("background-color", "white");
} else {
order = '11';
$(this).parent().find('.item-media').find('img').attr("src", "img/lightOn.png");
$(this).parent().parent().css("background-color", "lightcyan");
}
var deviceID = $(this).parent().parent().attr("id");
console.log("id");
console.log(deviceID);
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message(order);
message.destinationName = topicIn;
client.send(message);
}
} else {
var buttons1 = [
{
text: '修改名称',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.prompt('请修改名称', function (value) {
// $.alert('Your name is "' + value + '". You clicked Ok button');
$.get("http://dotekled.net/api/changeDeviceName",
{deviceID: deviceID, deviceName: value},
function (data) {
if (data == 'succ') {
$.alert('修改名称成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert('修改名称失败');
}
});
});
}
},
{
text: '分享控制权',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/shareDevice/" + deviceID;
location.href = url;
}
},
{
text: '用户信息',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/userMng/" + deviceID;
location.href = url;
}
},
{
text: '设备详情',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var t1 = deviceID.replace('deviceid', '');
var t2 = '设备MAC:' + t1;
$.alert(t2);
}
},
{
text: '设备解绑',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.get("http://dotekled.net/api/unbindDevice",
{ID: deviceID},
function (data) {
if (data == 'OK') {
$.alert('解绑成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert(data);
window.location.href = updateUrl("http://dotekled.net/deviceList");
}
});
}
},
// {
// text: '取消',
// color: "danger",
// onClick: function () {
// editStatue = 0;
//
// var delBtn = $(".delBtn");
// delBtn.css("display", "none");
// }
// }
];
var buttons2 = [
{
text: '取消',
// color: "danger",
onClick: function () {
editStatue = 0;
var delBtn = $(".delBtn");
delBtn.css("display", "none");
}
}
];
var groups = [buttons1,buttons2];
$.actions(groups);
}
})
});
$(".content ul li .item-media").each(function (i) {
$(this).click(function () {
var olState = $(this).parent().find('.item-subtitle span').text();
var deviceID = $(this).parent().parent().attr("id");
if (editStatue == 0) {
var lightImg = $(this).attr("src");
console.log("list " + i + " deviceID" + deviceID);
console.log(lightImg);
if(olState == '设备在线'){
var order = "";
if (lightImg == "img/lightOn.png") {
order = "10";
$(this).attr("src", "img/lightOff.png");
$(this).parent().parent().css("background-color", "white");
} else {
order = '11';
$(this).attr("src", "img/lightOn.png");
$(this).parent().parent().css("background-color", "lightcyan");
}
var deviceID = $(this).parent().parent().attr("id");
console.log("id");
console.log(deviceID);
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message(order);
message.destinationName = topicIn;
client.send(message);
}
} else {
var buttons1 = [
{
text: '修改名称',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.prompt('请修改名称', function (value) {
// $.alert('Your name is "' + value + '". You clicked Ok button');
$.get("http://dotekled.net/api/changeDeviceName",
{deviceID: deviceID, deviceName: value},
function (data) {
if (data == 'succ') {
$.alert('修改名称成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert('修改名称失败');
}
});
});
}
},
{
text: '分享控制权',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/shareDevice/" + deviceID;
location.href = url;
}
},
{
text: '用户信息',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/userMng/" + deviceID;
location.href = url;
}
},
{
text: '设备详情',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var t1 = deviceID.replace('deviceid', '');
var t2 = '设备MAC:' + t1;
$.alert(t2);
}
},
{
text: '设备解绑',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.get("http://dotekled.net/api/unbindDevice",
{ID: deviceID},
function (data) {
if (data == 'OK') {
$.alert('解绑成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert(data);
window.location.href = updateUrl("http://dotekled.net/deviceList");
}
});
}
},
// {
// text: '取消',
// color: "danger",
// onClick: function () {
// editStatue = 0;
//
// var delBtn = $(".delBtn");
// delBtn.css("display", "none");
// }
// }
];
var buttons2 = [
{
text: '取消',
// color: "danger",
onClick: function () {
editStatue = 0;
var delBtn = $(".delBtn");
delBtn.css("display", "none");
}
}
];
var groups = [buttons1,buttons2];
$.actions(groups);
}
})
});
$(".content ul li .scIC").each(function (i) {
$(this).click(function () {
var olState = $(this).parent().find('.item-inner .item-subtitle span').text();
var deviceID = $(this).parent().parent().attr("id");
if (editStatue == 0) {
var lightImg = $(this).attr("src");
console.log("list " + i + " deviceID" + deviceID);
console.log(lightImg);
if(olState == '设备在线'){
var order = "";
if (lightImg == "img/lightOn.png") {
order = "10";
$(this).attr("src", "img/lightOff.png");
$(this).parent().parent().css("background-color", "white");
} else {
order = '11';
$(this).attr("src", "img/lightOn.png");
$(this).parent().parent().css("background-color", "lightcyan");
}
var deviceID = $(this).parent().parent().attr("id");
console.log("id");
console.log(deviceID);
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message(order);
message.destinationName = topicIn;
client.send(message);
}
} else {
var buttons1 = [
{
text: '修改名称',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.prompt('请修改名称', function (value) {
// $.alert('Your name is "' + value + '". You clicked Ok button');
$.get("http://dotekled.net/api/changeDeviceName",
{deviceID: deviceID, deviceName: value},
function (data) {
if (data == 'succ') {
$.alert('修改名称成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert('修改名称失败');
}
});
});
}
},
{
text: '分享控制权',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/shareDevice/" + deviceID;
location.href = url;
}
},
{
text: '用户信息',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/userMng/" + deviceID;
location.href = url;
}
},
{
text: '设备详情',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var t1 = deviceID.replace('deviceid', '');
var t2 = '设备MAC:' + t1;
$.alert(t2);
}
},
{
text: '设备解绑',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.get("http://dotekled.net/api/unbindDevice",
{ID: deviceID},
function (data) {
if (data == '解绑成功') {
$.alert(data, 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert(data);
window.location.href = updateUrl("http://dotekled.net/deviceList");
}
});
}
},
// {
// text: '取消',
// color: "danger",
// onClick: function () {
//
//
// }
// }
];
var buttons2 = [
{
text: '取消',
// color: "danger",
onClick: function () {
editStatue = 0;
var delBtn = $(".delBtn");
delBtn.css("display", "none");
}
}
];
var groups = [buttons1,buttons2];
$.actions(groups);
}
})
});
////////////////\\\\\\\\\\\\\\\\\\
$(".content ul li .delBtn").each(function (i) {
$(this).click(function () {
var olState = $(this).children().find('.item-inner .item-subtitle span').text();
var deviceID = $(this).parent().parent().attr("id");
if (editStatue == 0) {
var lightImg = $(this).attr("src");
console.log("list " + i + " deviceID" + deviceID);
console.log(lightImg);
if(olState == '设备在线'){
var order = "";
if (lightImg == "img/lightOn.png") {
order = "10";
$(this).attr("src", "img/lightOff.png");
$(this).parent().parent().css("background-color", "white");
} else {
order = '11';
$(this).attr("src", "img/lightOn.png");
$(this).parent().parent().css("background-color", "lightcyan");
}
var deviceID = $(this).parent().parent().attr("id");
console.log("id");
console.log(deviceID);
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message(order);
message.destinationName = topicIn;
client.send(message);
}
} else {
var buttons1 = [
{
text: '修改名称',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.prompt('请修改名称', function (value) {
// $.alert('Your name is "' + value + '". You clicked Ok button');
$.get("http://dotekled.net/api/changeDeviceName",
{deviceID: deviceID, deviceName: value},
function (data) {
if (data == 'succ') {
$.alert('修改名称成功', 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert('修改名称失败');
}
});
});
}
},
{
text: '分享控制权',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/shareDevice/" + deviceID;
location.href = url;
}
},
{
text: '用户信息',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var url = "/userMng/" + deviceID;
location.href = url;
}
},
{
text: '设备详情',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
var t1 = deviceID.replace('deviceid', '');
var t2 = '设备MAC:' + t1;
$.alert(t2);
}
},
{
text: '设备解绑',
onClick: function () {
var delBtn = $(".delBtn");
delBtn.css("display", "none");
$.get("http://dotekled.net/api/unbindDevice",
{ID: deviceID},
function (data) {
if (data == '解绑成功') {
$.alert(data, 'G+智能', function () {
window.location.href = updateUrl("http://dotekled.net/deviceList");
});
} else {
$.alert(data);
window.location.href = updateUrl("http://dotekled.net/deviceList");
}
});
}
},
// {
// text: '取消',
// color: "danger",
// onClick: function () {
//
//
// }
// }
];
var buttons2 = [
{
text: '取消',
// color: "danger",
onClick: function () {
editStatue = 0;
var delBtn = $(".delBtn");
delBtn.css("display", "none");
}
}
];
var groups = [buttons1,buttons2];
$.actions(groups);
}
})
});
// 编辑点击
$(document).on('click', '#hBtn', function () {
var btnTitle;
// if (editStatue == 0){
// btnTitle = '编辑设备';
// }else {
// btnTitle = '退出编辑';
// }
var delBtn = $(".delBtn");
if (delBtn.css("display") == "none") {
btnTitle = '编辑设备';
}
else {
btnTitle = '退出编辑';
}
var buttons1 = [
{
text: '请选择',
label: true
},
{
text: '添加设备',
onClick: function () {
location.href = "/addDevice";
}
},
{
text: btnTitle,
onClick: function () {
var delBtn = $(".delBtn");
if (delBtn.css("display") == "none") {
delBtn.css("display", "block");
editStatue = 1;
}
else {
delBtn.css("display", "none");
editStatue = 0;
}
}
},
{
text: '一键全关',
onClick:function () {
$(".content ul li .item-media").each(function (i) {
var deviceID = $(this).parent().parent().attr("id");
var topicIn = 'device/' + deviceID + '/in';
message = new Paho.MQTT.Message('10');
message.destinationName = topicIn;
client.send(message);
});
}
}
];
var buttons2 = [
{
text: '取消',
// bg: 'danger'
onClick: function () {
console.log("取消");
}
}
];
var groups = [buttons1, buttons2];
$.actions(groups);
});
function updateUrl(url,key){
var key= (key || 't') +'='; //默认key是"t",可以传入key自定义
var reg=new RegExp(key+'\\d+'); //正则:t=1472286066028
var timestamp=+new Date();
if(url.indexOf(key)>-1){ //有时间戳,直接更新
return url.replace(reg,key+timestamp);
}else{ //没有时间戳,加上时间戳
if(url.indexOf('\?')>-1){
var urlArr=url.split('\?');
if(urlArr[1]){
return urlArr[0]+'?'+key+timestamp+'&'+urlArr[1];
}else{
return urlArr[0]+'?'+key+timestamp;
}
}else{
if(url.indexOf('#')>-1){
return url.split('#')[0]+'?'+key+timestamp+location.hash;
}else{
return url+'?'+key+timestamp;
}
}
}
}
</script>
</body>
</html>
|
|