Components and supplies
Breadboard and Wire Kit
sensor RHT03
Arduino Yun
5 KΩ resistor
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
arduino
1#include "DHT.h" //librarie used by the RHT03 sensor 2#include <Bridge.h> //function used to communicate with Arduino 3#include <YunServer.h> //We call the functions for creating a server 4#include <YunClient.h> //to display the data collected. 5 6#define DHTPIN 2 //We define the number of pin (2 in my case) 7#define DHTTYPE DHT22 //the type of sensor RHT03 8 9YunServer server; //Initialize the global variables that are used for the server and the sensor: 10 //The variable "h" will serve to store the humidity reading and "t" for the temperature 11DHT dht(DHTPIN, DHTTYPE); 12int h, t; 13 14void setup() { 15 Bridge.begin(); 16 server.listenOnLocalhost(); 17 server.begin(); 18 dht.begin(); 19} 20 21void loop() { 22 h = dht.readHumidity(); 23 t = dht.readTemperature(); 24 25 YunClient client = server.accept(); 26 if (client) { 27 process(client); 28 client.stop(); 29 } 30 31 delay(50); 32} 33 34void process(YunClient client) { 35 36 String command = client.readStringUntil('\r'); 37 38 if (command == "termo") { 39 temp(client); 40 } 41 42 if (command == "idro") { 43 idro(client); 44 } 45} 46 47void temp(YunClient client) { 48 if (isnan(t)) { 49 client.print(F("Error")); 50 } else { 51 client.print(t); 52 } 53} 54 55void idro(YunClient client) { 56 if (isnan(t)) { 57 client.print(F("Error")); 58 } else { 59 client.print(h); 60 } 61}
Code snippet #2
xml
1<?PHP 2$umido = file_get_contents ("http://192.168.1.200/arduino/idro"); 3$tempe = file_get_contents ("http://192.168.1.200/arduino/termo"); 4date_default_timezone_set('Europe/Rome'); 5$save= date ("H:i:s d.m.Y")."|".$umido."|".$tempe."\ 6"; 7$write_file = fopen("datilog.txt","a"); 8fwrite($write_file,$save); 9fclose($write_file); 10?> 11
Code snippet #4
xml
1<!DOCTYPE html> 2include ("data.php"); 3$umido = file_get_contents ("http://localhost/arduino/idro"); 4$tempe = file_get_contents ("http://localhost/arduino/termo"); 5?> 6<HTML> 7<HEAD> 8<TITLE> Arduino YUN Pagina <?PHP echo $pag/$val; ?></TITLE> 9 10 11 <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> 12 <link rel="stylesheet" href="css/print.css" type="text/css" media="print" /> 13 14 15<script type="text/javascript" src="//www.google.com/jsapi"></script> 16 <script type="text/javascript"> 17 google.load('visualization', '1'); 18 </script> 19 <script type="text/javascript"> 20 function drawVisualization() { 21 var wrapper = new google.visualization.ChartWrapper({ 22 chartType: 'ColumnChart', 23 dataTable: [['', <?PHP for($a = 1; $a < $numero; $a++) { echo "'".$dat[$a]."',"; } echo "'".$dat[$numero]."'"; ?> ], 24 ['', <?PHP for($a = 1; $a < $numero; $a++) { echo $tem[$a].","; } echo $tem[$numero]; ?> ]], 25 options: {'temperatura': 'data'}, 26 containerId: 'temperatura' 27 }); 28 wrapper.draw(); 29 } 30 31 32 33 google.setOnLoadCallback(drawVisualization); 34 </script> 35 <script type="text/javascript"> 36 google.load('visualization', '1'); 37 </script> 38 <script type="text/javascript"> 39 function drawVisualization() { 40 var wrapper = new google.visualization.ChartWrapper({ 41 chartType: 'ColumnChart', 42 dataTable: [['', <?PHP for($a = 1; $a < $numero; $a++) { echo "'".$dat[$a]."',"; } echo "'".$dat[$numero]."'"; ?> ], 43 ['', <?PHP for($a = 1; $a < $numero; $a++) { echo $umi[$a].","; } echo $umi[$numero]; ?> ]], 44 options: {'umidita': 'data'}, 45 containerId: 'umidita' 46 }); 47 wrapper.draw(); 48 } 49 50 51 52 google.setOnLoadCallback(drawVisualization); 53 </script> 54<script type='text/javascript'> 55 google.load('visualization', '1', {packages:['gauge']}); 56 google.setOnLoadCallback(drawChart); 57 function drawChart() { 58 var data = google.visualization.arrayToDataTable([ 59 ['Label', 'Value'], 60 ['C', <?PHP echo $tempe; ?>], 61 ]); 62 63 var options = { 64 width: 400, height: 120, 65 redFrom: 40, redTo: 60, 66 yellowFrom:30, yellowTo: 40, 67 minorTicks: 5, 68 max: 60 69 }; 70 71 var chart = new google.visualization.Gauge(document.getElementById('tempe')); 72 chart.draw(data, options); 73 } 74 </script> 75<script type='text/javascript'> 76 google.load('visualization', '1', {packages:['gauge']}); 77 google.setOnLoadCallback(drawChart); 78 function drawChart() { 79 var data = google.visualization.arrayToDataTable([ 80 ['Label', 'Value'], 81 ['%', <?PHP echo $umido; ?>] 82 ]); 83 84 var options = { 85 width: 400, height: 120, 86 redFrom: 90, redTo: 100, 87 yellowFrom:75, yellowTo: 90, 88 minorTicks: 5 89 }; 90 91 var chart = new google.visualization.Gauge(document.getElementById('umido')); 92 chart.draw(data, options); 93 } 94 </script> 95 96</HEAD> 97 98 99<BODY> 100<div align="center"> 101 <table border="0"> 102 103<tr><th align="center" colspan="2"><h1>Grafico Temperatura</h1></th></tr> 104 105<tr><td align="right" width="55%"><h2>Temperatura attuale:</h2></td><td><div id='tempe'></div></td></tr> 106<tr><th align="center" colspan="2"><div id="temperatura" style="width: 900px; height: 500px;"></div></th></tr> 107<tr><th align="center" colspan="2"><h1>Grafico Umidita'</h1></th></tr> 108<tr><td align="right" width="55%"><h2>Umidita' attuale:</h2></td><td><div id='umido'></div></td></tr> 109<tr><th align="center" colspan="2"><div id="umidita" style="width: 900px; height: 500px;"></div></th></tr> 110<tr><form id= "mioForm" action="index.php" method="get"> 111 <th align ="center"> 112Pagina: <select name="pag" onchange='this.form.submit()'> 113 <?PHP 114 for($a = 1; $a <= $pp ; $a++) { 115 echo '<option value="'.$a.'"'; 116 if ($a == $pag/$val) echo ' selected'; 117 echo '>'.$a.'</option>'; 118 } 119 ?> 120</br> 121</select> 122 Numero Valori: <select name="nrv" onchange='this.form.submit()'> 123 <?PHP 124 for($a =1; $a <= 50; $a++) { 125 echo '<option value="'.$a.'"'; 126 if ($a == $val) echo ' selected'; 127 echo '>'.$a.'</option>'; 128 } 129 ?> 130</select> 131 <noscript><input type="submit" value="Submit"></noscript></th> 132</form> 133 </table> 134</div> 135</BODY> 136</HTML> 137
Code snippet #1
arduino
1#include "DHT.h" //librarie used by the RHT03 sensor 2#include <Bridge.h> //function used to communicate with Arduino 3#include <YunServer.h> //We call the functions for creating a server 4#include <YunClient.h> //to display the data collected. 5 6#define DHTPIN 2 //We define the number of pin (2 in my case) 7#define DHTTYPE DHT22 //the type of sensor RHT03 8 9YunServer server; //Initialize the global variables that are used for the server and the sensor: 10 //The variable "h" will serve to store the humidity reading and "t" for the temperature 11DHT dht(DHTPIN, DHTTYPE); 12int h, t; 13 14void setup() { 15 Bridge.begin(); 16 server.listenOnLocalhost(); 17 server.begin(); 18 dht.begin(); 19} 20 21void loop() { 22 h = dht.readHumidity(); 23 t = dht.readTemperature(); 24 25 YunClient client = server.accept(); 26 if (client) { 27 process(client); 28 client.stop(); 29 } 30 31 delay(50); 32} 33 34void process(YunClient client) { 35 36 String command = client.readStringUntil('\ '); 37 38 if (command == "termo") { 39 temp(client); 40 } 41 42 if (command == "idro") { 43 idro(client); 44 } 45} 46 47void temp(YunClient client) { 48 if (isnan(t)) { 49 client.print(F("Error")); 50 } else { 51 client.print(t); 52 } 53} 54 55void idro(YunClient client) { 56 if (isnan(t)) { 57 client.print(F("Error")); 58 } else { 59 client.print(h); 60 } 61}
Code snippet #2
xml
1<?PHP 2$umido = file_get_contents ("http://192.168.1.200/arduino/idro"); 3$tempe = file_get_contents ("http://192.168.1.200/arduino/termo"); 4date_default_timezone_set('Europe/Rome'); 5$save= date ("H:i:s d.m.Y")."|".$umido."|".$tempe."\ 6"; 7$write_file = fopen("datilog.txt","a"); 8fwrite($write_file,$save); 9fclose($write_file); 10?> 11
Code snippet #3
xml
1<?PHP 2if (isset($_GET['nrv'])) { 3 $val = intval($_GET['nrv']); 4 if ($val < 1) $val = 10; 5 if ($val > 50) $val = 50; 6} else { 7 $val = 10; 8} 9if (isset($_GET['pag'])) { 10 $pag = intval($_GET['pag'])*$val; 11 if ($pag == 0) $pag = 10; 12} else { 13 $pag = 10; 14} 15$linee = file("datilog.txt"); 16foreach($linee as $line) 17{ 18 $nr++; 19 if ($nr <= $pag && $nr > $pag-$val-1) $numero++; 20 list($dat[$numero],$umi[$numero],$tem[$numero]) = explode("|", $line); 21 } 22if ($numero > $val) $numero = $val; 23$pp = $nr/$val; 24if ($pp-intval($pp) != 0) { 25 $pp = intval($pp)+1; 26} else { 27 $pp = intval($pp); 28} 29if (($pag/$val) > $pp) { 30 $pag = $pp*$val; 31 echo '<meta http-equiv="refresh" content="0; url=?pag='.($pag/$val).'&nrv='.$val.'">'; 32} 33?> 34
Code snippet #4
xml
1<!DOCTYPE html> 2include ("data.php"); 3$umido = file_get_contents 4 ("http://localhost/arduino/idro"); 5$tempe = file_get_contents ("http://localhost/arduino/termo"); 6?> 7<HTML> 8<HEAD> 9<TITLE> 10 Arduino YUN Pagina <?PHP echo $pag/$val; ?></TITLE> 11 12 13 <link rel="stylesheet" 14 href="css/style.css" type="text/css" media="screen" /> 15 <link rel="stylesheet" 16 href="css/print.css" type="text/css" media="print" /> 17 18 19<script 20 type="text/javascript" src="//www.google.com/jsapi"></script> 21 <script 22 type="text/javascript"> 23 google.load('visualization', '1'); 24 </script> 25 26 <script type="text/javascript"> 27 function drawVisualization() { 28 29 var wrapper = new google.visualization.ChartWrapper({ 30 chartType: 31 'ColumnChart', 32 dataTable: [['', <?PHP for($a = 1; $a < $numero; $a++) 33 { echo "'".$dat[$a]."',"; } echo "'".$dat[$numero]."'"; ?> ], 34 ['', 35 <?PHP for($a = 1; $a < $numero; $a++) { echo $tem[$a].","; } echo $tem[$numero]; 36 ?> ]], 37 options: {'temperatura': 'data'}, 38 containerId: 39 'temperatura' 40 }); 41 wrapper.draw(); 42 } 43 44 45 46 47 google.setOnLoadCallback(drawVisualization); 48 </script> 49 50 <script type="text/javascript"> 51 google.load('visualization', '1'); 52 53 </script> 54 <script type="text/javascript"> 55 function drawVisualization() 56 { 57 var wrapper = new google.visualization.ChartWrapper({ 58 chartType: 59 'ColumnChart', 60 dataTable: [['', <?PHP for($a = 1; $a < $numero; $a++) 61 { echo "'".$dat[$a]."',"; } echo "'".$dat[$numero]."'"; ?> ], 62 ['', 63 <?PHP for($a = 1; $a < $numero; $a++) { echo $umi[$a].","; } echo $umi[$numero]; 64 ?> ]], 65 options: {'umidita': 'data'}, 66 containerId: 'umidita' 67 68 }); 69 wrapper.draw(); 70 } 71 72 73 74 google.setOnLoadCallback(drawVisualization); 75 76 </script> 77<script type='text/javascript'> 78 google.load('visualization', 79 '1', {packages:['gauge']}); 80 google.setOnLoadCallback(drawChart); 81 function 82 drawChart() { 83 var data = google.visualization.arrayToDataTable([ 84 85 ['Label', 'Value'], 86 ['C', <?PHP echo $tempe; ?>], 87 ]); 88 89 90 var options = { 91 width: 400, height: 120, 92 redFrom: 93 40, redTo: 60, 94 yellowFrom:30, yellowTo: 40, 95 minorTicks: 96 5, 97 max: 60 98 }; 99 100 var chart = new google.visualization.Gauge(document.getElementById('tempe')); 101 102 chart.draw(data, options); 103 } 104 </script> 105<script type='text/javascript'> 106 107 google.load('visualization', '1', {packages:['gauge']}); 108 google.setOnLoadCallback(drawChart); 109 110 function drawChart() { 111 var data = google.visualization.arrayToDataTable([ 112 113 ['Label', 'Value'], 114 ['%', <?PHP echo $umido; ?>] 115 ]); 116 117 118 var options = { 119 width: 400, height: 120, 120 redFrom: 121 90, redTo: 100, 122 yellowFrom:75, yellowTo: 90, 123 minorTicks: 124 5 125 }; 126 127 var chart = new google.visualization.Gauge(document.getElementById('umido')); 128 129 chart.draw(data, options); 130 } 131 </script> 132 133</HEAD> 134 135 136<BODY> 137<div 138 align="center"> 139 <table border="0"> 140 141<tr><th align="center" colspan="2"><h1>Grafico 142 Temperatura</h1></th></tr> 143 144<tr><td align="right" width="55%"><h2>Temperatura 145 attuale:</h2></td><td><div id='tempe'></div></td></tr> 146<tr><th align="center" 147 colspan="2"><div id="temperatura" style="width: 900px; height: 500px;"></div></th></tr> 148<tr><th 149 align="center" colspan="2"><h1>Grafico Umidita'</h1></th></tr> 150<tr><td align="right" 151 width="55%"><h2>Umidita' attuale:</h2></td><td><div id='umido'></div></td></tr> 152<tr><th 153 align="center" colspan="2"><div id="umidita" style="width: 900px; height: 154 500px;"></div></th></tr> 155<tr><form id= "mioForm" action="index.php" method="get"> 156 <th 157 align ="center"> 158Pagina: <select name="pag" onchange='this.form.submit()'> 159 160 <?PHP 161 for($a = 1; $a <= $pp ; $a++) { 162 echo '<option value="'.$a.'"'; 163 if 164 ($a == $pag/$val) echo ' selected'; 165 echo '>'.$a.'</option>'; 166 } 167 ?> 168 169</br> 170</select> 171 Numero Valori: <select name="nrv" onchange='this.form.submit()'> 172 <?PHP 173 for($a 174 =1; $a <= 50; $a++) { 175 echo '<option value="'.$a.'"'; 176 if ($a == 177 $val) echo ' selected'; 178 echo '>'.$a.'</option>'; 179 } 180 ?> 181</select> 182 183 <noscript><input type="submit" value="Submit"></noscript></th> 184</form> 185 </table> 186</div> 187</BODY> 188</HTML> 189
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
2
0