From f8bf2ff9242624d8aeb6460065c892e543921eac Mon Sep 17 00:00:00 2001 From: tigoe Date: Sat, 6 Jul 2013 07:48:10 -0400 Subject: Added TemperatureWebPanel example --- .../TemperatureWebPanel/TemperatureWebPanel.ino | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino (limited to 'libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino') diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino new file mode 100644 index 0000000..48414ac --- /dev/null +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -0,0 +1,92 @@ +/* + Temperature web interface + + This example shows how to serve data from an analog input +via the Arduino Yún's built-in webserver using the Bridge library. + + The circuit: + * TMP36 temperature sensor on analog pin A1 + * SD card attached to SD card slot of the Arduino Yún + + Prepare your SD card with an empty folder in the SD root + named "arduino" and a subfolder of that named "www". + This will ensure that the Yún will create a link + to the SD to the "/mnt/sd" path. + + In this sketch folder is a basic webpage and a copy of zepto.js, a + minimized version of jQuery. When you upload your sketch, these files + will be placed in the /arduino/www/TemperatureWebPanel folder on your SD card. + + You can then go to http://arduino.local/sd/TemperatureWebPanel + to see the output of this sketch. + + You can remove the SD card while the Linux and the + sketch are running but be careful not to remove it while + the system is writing to it. + + created 6 July 2013 + by Tom Igoe + + + This example code is in the public domain. + + */ +#include +#include + +// Listen on default port 5555, the webserver on the Yun +// will forward there all the HTTP requests for us. +YunServer server; + +void setup() { + Serial.begin(9600); + + // Bridge startup + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + + // using A0 and A2 as vcc and gnd for the TMP36 sensor: + pinMode(A0, OUTPUT); + pinMode(A2, OUTPUT); + digitalWrite(A0, HIGH); + digitalWrite(A2, LOW); + + // Listen for incoming connection only from localhost + // (no one from the external network could connect) + server.listenOnLocalhost(); + server.begin(); +} + +void loop() { + // Get clients coming from server + YunClient client = server.accept(); + + // There is a new client? + if (client) { + // read the command + String command = client.readString(); + command.trim(); //kill whitespace + Serial.println(command); + // is "temperature" command? + if (command == "temperature") { + int sensorValue = analogRead(A1); + // convert the reading to millivolts: + float voltage = sensorValue * (5000/ 1024); + // convert the millivolts to temperature celsius: + float temperature = (voltage - 500)/10; + // print the temperature: + client.print("Current temperature: "); + client.print(temperature); + client.print(" degrees C"); + + } + + // Close connection and free resources. + client.stop(); + } + + delay(50); // Poll every 50ms +} + -- cgit v1.2.3-18-g5258 From 2a3701bcc10b044dd82d1b02a4441e66e82ac869 Mon Sep 17 00:00:00 2001 From: tigoe Date: Sat, 6 Jul 2013 08:10:13 -0400 Subject: Updated TemperatureWebPanel --- .../TemperatureWebPanel/TemperatureWebPanel.ino | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino') diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino index 48414ac..0621174 100644 --- a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -2,7 +2,7 @@ Temperature web interface 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: * 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 by Tom Igoe - + 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 // will forward there all the HTTP requests for us. YunServer server; +String startString; void setup() { Serial.begin(9600); @@ -57,6 +58,14 @@ void setup() { // (no one from the external network could connect) server.listenOnLocalhost(); 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() { @@ -71,16 +80,29 @@ void loop() { Serial.println(command); // is "temperature" command? 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); // convert the reading to millivolts: float voltage = sensorValue * (5000/ 1024); // convert the millivolts to temperature celsius: float temperature = (voltage - 500)/10; // print the temperature: - client.print("Current temperature: "); + client.print("Current time on the Yún: "); + client.println(timeString); + client.print("
Current temperature: "); client.print(temperature); client.print(" degrees C"); - + client.print("
This sketch has been running since "); + client.print(startString); } // Close connection and free resources. @@ -90,3 +112,5 @@ void loop() { delay(50); // Poll every 50ms } + + -- cgit v1.2.3-18-g5258 From 028d96687cea24aec389c1d7ff66b7c46e2531bc Mon Sep 17 00:00:00 2001 From: tigoe Date: Sat, 6 Jul 2013 08:20:02 -0400 Subject: Updated TemperatureWebPanel --- libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino') diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino index 0621174..8f50459 100644 --- a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -38,6 +38,7 @@ // will forward there all the HTTP requests for us. YunServer server; String startString; +long hits = 0; void setup() { Serial.begin(9600); @@ -103,10 +104,13 @@ void loop() { client.print(" degrees C"); client.print("
This sketch has been running since "); client.print(startString); + client.print("
Hits so far: "); + client.print(hits); } // Close connection and free resources. client.stop(); + hits++; } delay(50); // Poll every 50ms -- cgit v1.2.3-18-g5258 From 7310f8c8effd98901088584da55af9691d483932 Mon Sep 17 00:00:00 2001 From: tigoe Date: Sat, 6 Jul 2013 09:11:37 -0400 Subject: Corrected file structure on TemperatureWebPanel --- libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino | 1 + 1 file changed, 1 insertion(+) (limited to 'libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino') diff --git a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino index 8f50459..2149737 100644 --- a/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino +++ b/libraries/Bridge/examples/TemperatureWebPanel/TemperatureWebPanel.ino @@ -33,6 +33,7 @@ */ #include #include +#include // Listen on default port 5555, the webserver on the Yun // will forward there all the HTTP requests for us. -- cgit v1.2.3-18-g5258