index.html 7.78 KB
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pôt connecté</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

	<style>
		a:link {
		    text-decoration: none;
		}

		a:visited {
		    text-decoration: none;
		}
	</style>

    	<script type="text/javascript">

		var consigne_temp_inf = 0;
		var consigne_temp_sup = 0;
		var consigne_moisture = 0;

		window.WebSocket=(window.WebSocket||window.MozWebSocket);

		var websocket=new WebSocket('ws://localhost:9000','myprotocol');

		websocket.onopen=function(){ 
			document.getElementById("onoff").innerHTML = "Connecté";
			document.getElementById("onoff").className = "label label-success";
				 
		};

		websocket.onerror=function(){ 
			document.getElementById("onoff").innerHTML = "Non connecté";
			document.getElementById("onoff").className = "label label-danger";

		};

		websocket.onmessage=function(message){

		console.log(message.data);
		if((message.data)[0] == 'N')		
		{
			if((message.data).length == 1){return;}
			var value = parseInt((message.data).substring(1));
			if(value < 200)
			{
				document.getElementById("water_alert").style.background = "#F2DEDE"; 
				document.getElementById("water").innerHTML = "Il est temps de rajouter de l'eau";
				document.getElementById("niv_ok").className = "glyphicon glyphicon-remove";
			}
			else
			{
				document.getElementById("water_alert").style.background = "#DFF0D8"; 
				document.getElementById("water").innerHTML = "Niveau d'eau correct";
				document.getElementById("niv_ok").className = "glyphicon glyphicon-ok";
			}
		}
		
		if((message.data)[0] == 'T')		
		{
			if((message.data).length <= 2){return;}
			var value = (message.data).substring(1) * (5.0 / 1023.0 * 100.0);
			value = Math.round(value*100)/100;
			document.getElementById("temp").innerHTML = value;
			document.getElementById("temp_lvl").style.width = value +"%"; 
			if(value < consigne_temp_inf || value > consigne_temp_sup)
			{
				document.getElementById("temp_ok").className = "glyphicon glyphicon-remove";
				document.getElementById("temp_lvl").style.backgroundColor = "#e74c3c"; 

			} 
			else
			{
				document.getElementById("temp_ok").className = "glyphicon glyphicon-ok";
				document.getElementById("temp_lvl").style.backgroundColor = "#2ecc71";
			}
		}

		if((message.data)[0] == 'H')		
		{
			if((message.data).length == 1){return;}
			var value = (message.data).substring(1);
			document.getElementById("moisture").innerHTML = value;
			document.getElementById("moisture_lvl").style.width = value +"%"; 
			if(parseInt(value) < consigne_moisture )
			{
				document.getElementById("hum_ok").className = "glyphicon glyphicon-remove";
			} 
			else
			{
				document.getElementById("hum_ok").className = "glyphicon glyphicon-ok";
			}
		}

		if((message.data)[0] == 'M')		
		{
			var value = (message.data).substring(1);
			consigne_moisture = parseInt(value);
			document.getElementById("consigne_moisture").innerHTML = value+"%";
		}

		};

		function sendMoisture()
		{
			var consigne = document.getElementById("consigne_moisture_change").value;
			if(consigne == ""){return;}
			document.getElementById("consigne_moisture_change").value = '';
			if (parseInt(consigne) > 100)
			{
				consigne = "100";
			}

			websocket.send("M"+consigne);

		}

		function sendTemp()
		{
			var consigne1 = document.getElementById("consigne1_temp_change").value;
			var consigne2 = document.getElementById("consigne2_temp_change").value;
			if(consigne1 == "" || consigne2 == ""){return;}
			var temp_bornes = [parseInt(consigne1),parseInt(consigne2)];
			consigne_temp_inf = Math.min.apply(Math, temp_bornes);
			consigne_temp_sup = Math.max.apply(Math, temp_bornes);
			document.getElementById("consigne_temp").innerHTML = consigne_temp_inf+"-"+consigne_temp_sup+"°C";
		}

	</script>

</head>
<body>


<div class="container">

	<h1><a style="text-decoration:none;color:#212121;cursor:pointer;" btn-lg" data-toggle="modal" data-target="#myModal">Pôt de fleurs connecté</a></h1>



<!- ----------------------------------------------------------------------------------------- -!>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Pôt de fleurs connecté</h4>
      </div>
      <div class="modal-body">
        <p>Projet réalisé en 2017 dans le cadre du projet "Systèmes Communicants" en IMA3.</p>
	<p><a href="http://projets-ima.plil.net/mediawiki/index.php?title=Projet_IMA3_P1,_2016/2017,_TD1">Lien du wiki</a> / <a href="https://archives.plil.fr/aduqueno/2017_TD1_1.git">Projet GIT</a></p>
	<p><i>Antoine Duquenoy, Clément Froissart, Amine El Messaoudi et Antoine Gosse</i></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

<!- ----------------------------------------------------------------------------------------- -!>

	<span id="onoff" class="label label-danger">Non connecté</span>
	<hr/>
	</br>

	<div class="panel panel-default">

		<div class="panel-heading">
			<h3><span id="hum_ok" class="glyphicon glyphicon-refresh" style="margin-right:10px;font-size: 0.8em;"></span>Taux d'humidité  <span id="consigne_moisture" class="badge">Consigne</span></h3>
		</div>

	  	<div class="panel-body">
			<div class="progress" style="background-color:#34495e">
				<div id="moisture_lvl" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:100%;background-color:#3498db">
					<div id="moisture">Chargement</div>
				</div>
			</div>

			<form onkeypress="return event.keyCode != 13" class="form-inline">
				<div class="form-group">
					<label for="lvl">Taux d'humidité souhaité</label>
					<input type="name" class="form-control" id="consigne_moisture_change">
				</div>
				<button type="button" class="btn btn-default" onclick="sendMoisture();">Envoyer</button>
			</form>

		</div>
	</div>

		
	
	</br>
	
	<div class="panel panel-default">

		<div class="panel-heading">
			<h3><span id="niv_ok" class="glyphicon glyphicon-refresh" style="margin-right:10px;font-size: 0.8em;"></span>Niveau d'eau</h3>  
		</div>
		
		<div id="water_alert" class="panel-body" style="background-color:#FCF8E3;">
			<div id="water">
			  Chargement
			</div>
		</div>
	</div>

	</br>

	<div class="panel panel-default">

		<div class="panel-heading">
			<h3><span id="temp_ok" class="glyphicon glyphicon-refresh" style="margin-right:10px;font-size: 0.8em;"></span>Température  <span id="consigne_temp" class="badge">Consigne</span></h3>
		</div>

  		<div class="panel-body">
			<div class="progress" style="background-color:#34495e">
				<div id="temp_lvl" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:100%;background-color:#e74c3c">
					<div id="temp">Chargement</div>
				</div>
			</div>  

			<form onkeypress="return event.keyCode != 13" class="form-inline">
				<div class="form-group">
					<label for="lvl">Température souhaitée entre</label>
					<input type="number" value="0" min="0" max="64" class="form-control" id="consigne1_temp_change">
					et
					<input type="number" value="40" min="0" max="64" class="form-control" id="consigne2_temp_change">
				</div>
				<button type="button" class="btn btn-default" onclick="sendTemp();">Envoyer</button>
			</form>
		</div>


	</div>

	
</div>

</body>
</html>