1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Updated TemperatureWebPanel

This commit is contained in:
tigoe 2013-07-06 08:10:13 -04:00
parent 41f1be5fc7
commit c777b5c76b
2 changed files with 30 additions and 6 deletions

View File

@ -2,7 +2,7 @@
Temperature web interface Temperature web interface
This example shows how to serve data from an analog input This example shows how to serve data from an analog input
via the Arduino Yún's built-in webserver using the Bridge library. via the Arduino Yún's built-in webserver using the Bridge library.
The circuit: The circuit:
* TMP36 temperature sensor on analog pin A1 * TMP36 temperature sensor on analog pin A1
@ -26,7 +26,7 @@ via the Arduino Yún's built-in webserver using the Bridge library.
created 6 July 2013 created 6 July 2013
by Tom Igoe by Tom Igoe
This example code is in the public domain. This example code is in the public domain.
@ -37,6 +37,7 @@ via the Arduino Yún's built-in webserver using the Bridge library.
// Listen on default port 5555, the webserver on the Yun // Listen on default port 5555, the webserver on the Yun
// will forward there all the HTTP requests for us. // will forward there all the HTTP requests for us.
YunServer server; YunServer server;
String startString;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -57,6 +58,14 @@ void setup() {
// (no one from the external network could connect) // (no one from the external network could connect)
server.listenOnLocalhost(); server.listenOnLocalhost();
server.begin(); server.begin();
// get the time that this sketch started:
Process startTime;
startTime.runShellCommand("date");
while(startTime.available()) {
char c = startTime.read();
startString += c;
}
} }
void loop() { void loop() {
@ -71,16 +80,29 @@ void loop() {
Serial.println(command); Serial.println(command);
// is "temperature" command? // is "temperature" command?
if (command == "temperature") { if (command == "temperature") {
// get the time from the server:
Process time;
time.runShellCommand("date");
String timeString = "";
while(time.available()) {
char c = time.read();
timeString += c;
}
Serial.println(timeString);
int sensorValue = analogRead(A1); int sensorValue = analogRead(A1);
// convert the reading to millivolts: // convert the reading to millivolts:
float voltage = sensorValue * (5000/ 1024); float voltage = sensorValue * (5000/ 1024);
// convert the millivolts to temperature celsius: // convert the millivolts to temperature celsius:
float temperature = (voltage - 500)/10; float temperature = (voltage - 500)/10;
// print the temperature: // print the temperature:
client.print("Current temperature: "); client.print("Current time on the Yún: ");
client.println(timeString);
client.print("<br>Current temperature: ");
client.print(temperature); client.print(temperature);
client.print(" degrees C"); client.print(" degrees C");
client.print("<br>This sketch has been running since ");
client.print(startString);
} }
// Close connection and free resources. // Close connection and free resources.
@ -90,3 +112,5 @@ void loop() {
delay(50); // Poll every 50ms delay(50); // Poll every 50ms
} }

View File

@ -4,13 +4,13 @@
<script type="text/javascript" src="zepto.min.js"></script> <script type="text/javascript" src="zepto.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function refresh() { function refresh() {
$('#content').load('/arduino/avr/temperature'); $('#content').load('/arduino/temperature');
} }
</script> </script>
</head> </head>
<body onload="setInterval(refresh, 1000);"> <body onload="setInterval(refresh, 1000);">
Analog 0: <span id="content">0</span> <span id="content">0</span>
</body> </body>
</html> </html>