-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample05.html
51 lines (40 loc) · 1.43 KB
/
example05.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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Example with physical button</title>
</head>
<body>
<div>Server conected, board is ready.</div>
<div>Press HW pushbutton</div>
<div>
<canvas id="canvas1" width ="200" height = "100" style="border: 1px dashed #00c3c3;"></canvas>
</div>
<div id="print1"></div>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
"use strict";
var divElement = document.getElementById("print1"); // variable for div object where the values will be printed (logged)
var socket = io.connect("192.168.1.134:8080");
function log(msg) {
divElement.innerHTML += "<div>" + msg + "</div>"; // we print it to div
}
socket.on("messageToClient", function (msg){
var canvas1 = document.getElementById("canvas1");
var ctx1 = canvas1.getContext("2d");
if (msg == "Value = 1"){
ctx1.fillStyle = "red";
ctx1.fillRect(0, 0, canvas1.width, canvas1.height);
}
else {
ctx1.fillStyle = "green";
ctx1.fillRect(0, 0, canvas1.width, canvas1.height);
}
log(msg); // add msg
});
socket.on("disconnect", function(){
log("Disconnected from the server"); // we print status of disconn. to div
});
</script>
</body>
</html>