首先BIOS设置程序将Power On by PCIE devices 与 Power On by Onboard Lan 项目设为 [Enabled]
然后记下此PC的MAC地址,在另一台电脑安装win10应用“wake on lan”测试能否开机。
UDP唤醒电脑的方法是发送16进制的:
FFFFFFFFFFFF+16遍MAC地址
如果不想记IP,也可以广播给255
serialudp.js
// npm i cordova-plugin-chrome-apps-sockets-udp
var serialudp = function (callback, _port) {
var socketId;
// Handle the "onReceive" event.
var onReceive = function (info) {
// console.log('收到:' + buf2hex(info.data, ' '));
// $('#msg').prepend(btntitle + ' | IP:' + info.remoteAddress + ' Port:' + info.remotePort + '<br>' + info.data + '<br>')
callback && callback(info.data,info);
};
// Create the Socket
chrome.sockets.udp.create({}, function (socketInfo) {
socketId = socketInfo.socketId;
// Setup event handler and bind socket.
chrome.sockets.udp.onReceive.addListener(onReceive);
chrome.sockets.udp.bind(socketId, "0.0.0.0", _port||10101, function (result) {
if (result < 0) {
console.log("Error binding socket..................");
return;
}
});
});
return {
send: function (str, ip, port) {
chrome.sockets.udp.send(socketId, Buffer.from(str.replace(/-+|\s+/g, ""), "hex"),
ip, port, function (sendInfo) {
console.log("sent " + sendInfo.bytesSent);
});
}
}
}
index.html
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta charset="UTF-8">
<title></title>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/layer.js"></script>
<script src="js/serialudp.js"></script>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background: black;
font-size: 1.2rem;
}
video{width: 100%;height: 100%;}
.config{position: absolute;left: 0;top: 0;width: 100%;height: 100%;overflow: auto;background: rgba(255, 255, 255, 0.9);}
div{margin: 1rem auto;}
input,button{font-size: 1.2rem;}
#openbtn{background: seagreen;color: white;font-size: 1.5rem;}
</style>
</head>
<body>
<iframe id="main" src="" width="100%" height="100%" border="0" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<div class="config">
<div><span>主机IP</span><input id="thisip" type="text" placeholder="填写主机IP" value="192.168.60.27"/></div>
<div><span>MAC地址</span><input id="thismac" type="text" placeholder="填写主机MAC地址" value="3C-7C-3F-12-F8-FE"/></div>
<div><button onclick="savejson()" id="savebtn">保存</button></div>
<div><button onclick="openpc()" id="openbtn">主机开机</button></div>
</div>
<script>
var ip;
var myjson;
console.log('flashmeJson:'+window.localStorage.getItem('flashmeJson'));
if(!window.localStorage.getItem('flashmeJson')){
// layer.open({
// content: `<input id="thisip" type="text" placeholder="填写主机IP" value="192.168.1.*"/><br><button onclick="savejson()">确定</button>`
// });
$('.config').show();
$('#openbtn').hide();
}else{
myjson=JSON.parse(window.localStorage.getItem('flashmeJson'))
ip="http://"+myjson.ip+":3000";
}
function savejson() {
var config={
ip:$('#thisip').val(),
mac:$('#thismac').val()
}
window.localStorage.setItem('flashmeJson', JSON.stringify(config));
location.reload();
}
var main = document.getElementById("main");
var errstate;
function loadajax(){
$.ajax({
type: "GET",
url: ip+"/json",
timeout: 6000,
success: function (result) {
if(result.state){
clearInterval(timer);
main.src=ip;
$('.config').hide();
}
},
error: function (err) {
if(errstate){
return;
}
layer.open({
content: '主机程序未运行!' + err.status
, time: 5
, skin: 'msg'
});
$('.config').show();
errstate=true;
}
})
}
var timer;
if(myjson){
loadajax();
$('#thisip').val(myjson.ip)
$('#thismac').val(myjson.mac)
timer=setInterval(function() {
loadajax();
}, 3000)
}
var udp = new serialudp()
function openpc() {
layer.open({
content: '等待主机响应...'
, time: 8
, skin: 'msg'
});
var mac=myjson.mac.replace(/-+|\s+/g, "");
var hex="FFFFFFFFFFFF";
for(var i=0;i<16;i++){
hex+=mac;
}
udp.send(hex,myjson.ip,80)
}
</script>
</body>
</html>
这里是一直监听服务器端3000端口的/json路径,访问不到就出现配置界面及开机唤醒按钮
Comments | NOTHING