forked from ThomasBarth/WebSockets-on-the-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP32_WS.html
69 lines (52 loc) · 1.71 KB
/
ESP32_WS.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ESP32 WebSocket Test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var WebSocket_connection;
if (!"WebSocket" in window){
alert("WebSocket NOT supported by your Browser!");
$('#WebSocket_State').text("WebSocket NOT supported by your Browser!");
}
window.onbeforeunload = function() {
websocket.onclose = function () {}; // disable onclose handler first
websocket.close()
};
function connect(){
WebSocket_connection = new WebSocket($('#websocket_address').val());
$('#WebSocket_State').text("Connecting");
WebSocket_connection.onopen = function(){
$('#WebSocket_State').html('<input type="text" id="websocket_message" value="Data to be send"/><a href=\"javascript:WebSocketSend()\">send WebSocket</a>');
};
WebSocket_connection.onmessage = function (evt) {
//read data and append it to output_div
$( "#output_div" ).append( evt.data + "<br>" );
};
WebSocket_connection.onerror = function()
{
$('#WebSocket_State').text("Error,... connection closed");
};
WebSocket_connection.onclose = function()
{
$('#WebSocket_State').text("Disconnected");
};
}
function WebSocketSend(){
WebSocket_connection.send($('#websocket_message').val());
}
</script>
</head>
<body>
<div id="WebSocket_State">
WebSocket Server:
<input type="text" id="websocket_address" value="ws://192.168.4.1:9998"/>
<a href="javascript:connect()">Connect</a>
</div>
<br>
<div id="output_div">
Received WebSocket Messages:<br>
</div>
</body>
</html>