Blame view

appWeb/js/script.js 1.4 KB
ab869558   aknockae   La com série entr...
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
  window.WebSocket=(window.WebSocket||window.MozWebSocket);
  var websocket=new WebSocket('ws://192.168.1.111:9000','myprotocol');
  
  websocket.onopen=function(){ $('h3 .connecOn').css('color','green'); };
  
  websocket.onerror=function(){ $('h3 .connecOff').css('color','red'); };
   //on crée des tableaux de Buffer, ces tableaux permettent de "découper" la chaine de bits, en différents octets
  var bufferReponse = new ArrayBuffer(3);
  var bufferRequete = new ArrayBuffer(3);
  
  //DataView permet de traiter un ArrayBuffer
  var requeteView = new DataView(bufferRequete);
  var reponseView = new DataView(bufferReponse);
  
  //on remplie le buffer de requete via requeteView
  requeteView.setInt8(0,'G'.charCodeAt(0));
  requeteView.setInt8(1,'E'.charCodeAt(0));
  requeteView.setInt8(2,'T'.charCodeAt(0));
  
  //affiche le contenu du tableau dans une alert
  alert(String.fromCharCode(requeteView.getInt8(0))+String.fromCharCode(requeteView.getInt8(1))+String.fromCharCode(requeteView.getInt8(2)));
  
  
  websocket.onmessage=function(message){ //Evenement surveillant la reception de message
  
  	console.log(message.data);
  	/*$('#relevesMeteo .temperature').text(message.data);
  	$('#relevesMeteo .humidite').text(message.data);
  	$('#relevesMeteo .pression').text(message.data);
  	$('#relevesMeteo .luminosite').text(message.data);*/
  
  };
  
  function requeteEnvoi(){
  	websocket.send(bufferReponse);
  	console.log(bufferReponse);
  }
  
  
  
  //setInterval(requeteEnvoi,1000);