IdeaHub或Board的简单控制
本帖最后由 pidtfork 于 2021-6-17 16:04 编辑/**
* @description IdeaHub 和 Board 的简单控制,控制设备休眠/唤醒/关机/信号切换功能
* 使用此方法前必须设备WEB后台打开HTTP,知道api 用户名和密码
* 如果使用网络唤醒也需要在WEB页面打开(有些设备默认关闭网络唤醒)
* wakeUp 是休眠唤醒,设备关机时无法使用此方法唤醒设备
* 2021-6-17 16:02:54 新增 sleep2 方法,原 sleep 方法的api在 21.0.5 版本不起作用
* 可能在 21.0.0 版本即以后版本改了 休眠的 API
* @author pidtfork
* @date 2021-06-16
* @param {Object} conf 设备的信息项
* ip 设备IP 必须
* user API用户名 必须
* password API密码 必须
* mac 设备MAC地址 非必须
* @param {Function} callback
*/
function IdeaHub(conf, callback) {
this.conf = conf;
this.httpVCSession = HttpSession();
this.acCSRFToken = "";
this.httpPost = function (vAPI, vData) {
var header = { 'Content-Type': 'application/json' };
return HttpPost('http://' + this.conf.ip + '/action.cgi?ActionID=' + vAPI, JSON.stringify(vData), JSON.stringify(header), this.httpVCSession, 1);
}
this.login = function () {
try {
var receive = this.httpPost('WEB_RequestSessionIDAPI', '');
if (receive.indexOf("success") != -1) {
receive = this.httpPost('WEB_RequestCertificateAPI', '{"user":"' + this.conf.user + '","password":"' + this.conf.password + '"}');
if (receive.indexOf("success") != -1) {
var msg = JSON.parse(receive);
msg = JSON.parse(msg.data);
this.acCSRFToken = msg.acCSRFToken;
receive = this.httpPost('WEB_ChangeSessionIDAPI', '');
if (receive.indexOf("success") != -1) {
return true;
}
}
}
}
catch (err) {
}
if (typeof callback == 'function') {
callback("操作失败");
}
return false;
}
this.sleep = function () {
if (this.login()) {
this.httpPost('WEB_StartTermSleepAPI', '{"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.sleep2 = function () {
if (this.login()) {
this.httpPost('WEB_StartSystemSleepAPI', '{"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.wakeUp = function () {
if (this.login()) {
this.httpPost('WEB_SystemWakeUpAPI', '{"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.reboot = function () {
if (this.login()) {
this.httpPost('WEB_RequestRebootAPI', '{"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.powerDown = function () {
if (this.login()) {
this.httpPost('WEB_RequestPowerDownAPI', '{"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.switchOPS = function () {
if (this.login()) {
this.httpPost('WEB_SwitchPageForPcCam', '{"viewStatus":0,"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.switchAndroid = function () {
if (this.login()) {
this.httpPost('WEB_SwitchPageForPcCam', '{"viewStatus":1,"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.switchAUX = function () {
if (this.login()) {
this.httpPost('WEB_SwitchPageForPcCam', '{"viewStatus":2,"acCSRFToken":"' + this.acCSRFToken + '"}');
}
}
this.devWakeLan = new _UDP(46426, '255.255.255.255:7')
this.wakeLan = function () {
if (this.conf.mac) {
var magicPack = '\xFF\xFF\xFF\xFF\xFF\xFF';
for (var i = 0; i < 16; i++) {
magicPack = magicPack + this.conf.mac;
}
this.devWakeLan.sendCodeString(magicPack);
}
}
}
// 操作不成功时提示 例如连接失败,设备未上电等
function popupTip(msg) {
sendLog("ideHub message", msg);
setPageShow("提示");
}
// 实例化终端1
var ideaHub1 = new IdeaHub({
ip: "192.168.1.103",
user: "api",
password: "Change_Me",
mac: "\x01\x02\x03\x04\x05\x06"
}, popupTip)
// 主要的几个功能
// ideaHub1.sleep(); //休眠
// ideaHub1.sleep2(); //休眠 21.0.0 后版本使用此方法
// ideaHub1.reboot(); //重启
// ideaHub1.wakeUp(); //唤醒
// ideaHub1.powerDown(); //关机
// ideaHub1.switchOPS(); //切换到OPS
// ideaHub1.switchAndroid(); //切换到安卓
// ideaHub1.switchAUX(); //切换到辅流
// ideaHub1.wakeLan();//网络唤醒
// 实例化第二台不需要网络唤醒可以不传入 mac
var ideaHub2 = new IdeaHub({
ip: "192.168.1.104",
user: "api",
password: "Change_Me",
}, popupTip)
// 主要的几个功能
// ideaHub2.sleep(); //休眠
// ideaHub2.sleep2(); //休眠 21.0.0 后版本使用此方法
// ideaHub2.reboot(); //重启
// ideaHub2.wakeUp(); //唤醒
// ideaHub2.powerDown(); //关机
// ideaHub2.switchOPS(); //切换到OPS
// ideaHub2.switchAndroid(); //切换到安卓
// ideaHub2.switchAUX(); //切换到辅流
// 实例化第三台 ......
// 实例化第四台 ......
页:
[1]