Blame view

page_web/index.html 2.02 KB
4ed129b3   tcattela   Commit des fichie...
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
70
71
72
73
74
75
76
77
78
  <!DOCTYPE html>
  <html>
    <head>
      <meta charset="utf-8">
      <script src="jquery.js"></script>
      <script type="text/javascript">
  window.WebSocket=(window.WebSocket||window.MozWebSocket);
  
  var websocket=new WebSocket('ws://127.0.0.1:9000','myprotocol');
  
  websocket.onopen=function(){ $('h1').css('color','green'); };
  
  websocket.onerror=function(){ $('h1').css('color','red'); };
  
  websocket.onmessage=function(message){
  console.log(message.data);
  var recep = message.data;
  var instruction = recep-10*Math.trunc(recep/10);
  var donnee = Math.trunc(recep/10);
  if (instruction == 0){
  $('#messages').html(donnee);
  }
  else if (instruction == 1){
  $('#messages2').html(donnee);
  }
  else if (instruction == 2){
  var temperatureC = Math.round(((donnee*5/1024)-0.5)*10000) / 100
  $('#messages3').html(temperatureC);
  }
  else if (instruction == 3){
  	if(recep==3){
  	$('#messages4').html("Light OFF");
  	}
  	else{
  	$('#messages4').html("Light ON");
  	}
  }
  else if (instruction == 4){
  	if(recep==4){
  	$('#messages5').html("HEAT OFF");
  	}
  	else{
  	$('#messages5').html("HEAT ON");
  	}
  }
  /*else if (instruction == 4){
  $('#messages5').html(donnee);
  }
  */
  };
  
  function sendmessage(){
  websocket.send($('#message').val());
  $('#message').val('');
  }
  
  
  
  
  
  function autoSend0(){
  websocket.send('0');
  setTimeout('autoSend1();', 200);
  }
  function autoSend1(){
  websocket.send('1');
  setTimeout('autoSend2();', 200);
  }
  function autoSend2(){
  websocket.send('2');
  setTimeout('autoSend3();', 200);
  }
  function autoSend3(){
  websocket.send('3');
  setTimeout('autoSend4();', 200);
  }
  function autoSend4(){
  websocket.send('4');
4ed129b3   tcattela   Commit des fichie...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  }
  setInterval(autoSend0, 1000);
  
  
  
  
      </script>
    </head>
    <body>
      <h1>WebSockets test</h1>
      <input type="text" id="message"/>
      <button onclick="sendmessage();">Send</button>
      <h2>Potentiometre :</h2>
      <h2><span id="messages"></span></h2>
      <h2>Luminosite :</h2>
      <h2><span id="messages2"></span></h2>
      <h2>Temperature :</h2>
      <h2><span id="messages3"></span></h2>
      <h2><span id="messages4"></span></h2>
      <h2><span id="messages5"></span></h2>
    </body>
  </html>