forked from ejeklint/ArduinoWebsocketServer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
websocket.html
executable file
·54 lines (51 loc) · 2.15 KB
/
websocket.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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebSockets test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
function debug(str) {
$("#debug").append("<p>"+str+"<p>");
}
// WebSocket needs to be set to IP of arduino.
try {
window.console.log("Setting up socket");
//ws = new WebSocket("ws://109.228.139.253:8383/");
ws = new WebSocket("ws://10.0.1.83:8383/");
ws.onmessage = function(evt) {
window.console.log(evt.data);
$("#msg").append("<p>"+evt.data+"<p>");
};
ws.onerror = function(evt) {
window.console.log(evt.data);
$("#msg").append("<p> ERROR: "+evt.data+"<p>");
};
ws.onclose = function() {
window.console.log("onclose called");
debug("socket closed");
};
ws.onopen = function() {
window.console.log("onopen called");
debug("connected...");
ws.send("Hello, Ardunio");
};
} catch(exception) {
window.console.log('<p>Error'+exception);
}
});
$(document).mousedown(function() {
ws.send("0");
});
$(document).mouseup(function() {
ws.send("1");
});
</script>
</head>
<body>
<div id="debug"></div>
<div id="msg"></div>
</body>
</html>