YHGW/static/index.html

68 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
lang="zh-CN">
<meta http-equiv="content-type" content="txt/html; charset=utf-8" />
<head>
<script type="text/javascript"
src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<title>yunhorn-dev</title>
</head>
<body>
lorawan 数据调试
<div id="content"></div>
<!--
<button onclick="closeWebSocket()">测试添加内容</button>
-->
<script>
function closeWebSocket(){
$("#content").append("<p>测试</p>");
}
</script>
<script type="text/javascript">
var websocket = null;
//判断当前浏览器是否支持WebSocket
if ('WebSocket' in window) {
websocket = new WebSocket("wss://" + "smartoilets.cn/socketServer" + "/socket");
} else {
alert('当前浏览器 Not support websocket')
}
//连接发生错误的回调方法
websocket.onerror = function() {
console.log("onerror")
};
websocket.onopen = function() {
console.log("onopen")
websocket.send("{'code':131}")
console.log("sned code 131")
}
//接收到消息的回调方法
websocket.onmessage = function(event) {
// setMessageInnerHTML(event.data);
//console.log("websocket.message:",event.data)
console.log("websocket.message")
console.log(event.data)
var obj=eval("("+event.data+")");
console.log(obj.time)
$("#content").prepend("<p>"+event.data+"</p>");
//websocket.send("{'code':0111,'wcId':15}")
}
//连接关闭的回调方法
websocket.onclose = function() {
// setMessageInnerHTML("WebSocket连接关闭");
$("#content").prepend("<p>websocket已断开</p>");
console.log("onclose")
}
//监听窗口关闭事件当窗口关闭时主动去关闭websocket连接防止连接还没断开就关闭窗口server端会抛异常。
window.onbeforeunload = function() {
console.log("onbeforeunload")
}
</script>
</body>
</html>