aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/Bridge/examples/FileTest/FileTest.ino50
-rw-r--r--libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino65
2 files changed, 65 insertions, 50 deletions
diff --git a/libraries/Bridge/examples/FileTest/FileTest.ino b/libraries/Bridge/examples/FileTest/FileTest.ino
deleted file mode 100644
index 3fd7ce9..0000000
--- a/libraries/Bridge/examples/FileTest/FileTest.ino
+++ /dev/null
@@ -1,50 +0,0 @@
-
-#include <FileIO.h>
-
-void setup() {
- Bridge.begin();
- SD.begin();
-
- boolean r;
- r=SD.exists("/arduino/test");
- if (r) error("1");
- r=SD.exists("/arduino");
- if (!r) error("2");
-
- r=SD.mkdir("/arduino/test");
- if (!r) error("3");
- r=SD.exists("/arduino/test");
- if (!r) error("4");
-
- File f = SD.open("/arduino/test/bla", FILE_WRITE);
- if (!f) error("5");
- f.println("CIAO!");
- f.close();
-
- delay(10000);
-
- r=SD.rmdir("/arduino/test");
- if (r) error("6");
- r=SD.remove("/arduino/test");
- if (r) error("7");
-
- r=SD.remove("/arduino/test/bla");
- if (!r) error("8");
- r=SD.rmdir("/arduino/test");
- if (!r) error("9");
- r=SD.exists("/arduino/test");
- if (r) error("10");
-}
-
-
-void error(const char *s) {
- Bridge.print("# ERROR ");
- Bridge.println(s);
- while (true);
-}
-
-void loop() {
-}
-
-
-
diff --git a/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino
new file mode 100644
index 0000000..d5bbb26
--- /dev/null
+++ b/libraries/Bridge/examples/FileWriteScript/FileWriteScript.ino
@@ -0,0 +1,65 @@
+/*
+ Write to file using FileIO classes.
+
+ This sketch demonstrate how to write file into the Yún filesystem.
+ A shell script file is created in /tmp, and it is executed afterwards.
+
+ */
+
+#include <FileIO.h>
+
+void setup() {
+ // Setup Bridge (needed every time we communicate with the Arduino Yún)
+ Bridge.begin();
+
+ // Setup Console
+ Console.begin();
+ // Buffering improves Console performance, but we must remember to
+ // finish sending using the Console.flush() command.
+ Console.buffer(64);
+
+ // Setup File IO
+ SD.begin();
+
+ // Upload script used to gain network statistics
+ uploadScript();
+}
+
+void loop() {
+ // Run stats script every 5 secs.
+ runScript();
+ delay(5000);
+}
+
+void uploadScript() {
+ // Write our shell script in /tmp
+ // Using /tmp stores the script in RAM this way we can preserve
+ // the limited amount of FLASH erase/write cycles
+ File script = SD.open("/tmp/wlan-stats.sh", FILE_WRITE);
+ script.print("#!/bin/sh\n");
+ script.print("ifconfig wlan0 | grep \"RX bytes\" | tr ':' ' ' | awk \"{ print \\$3 \\\" \\\" \\$8 }\"\n");
+ script.close();
+
+ // Make the script executable
+ Process chmod;
+ chmod.begin("chmod");
+ chmod.addParameter("+x");
+ chmod.addParameter("/tmp/wlan-stats.sh");
+ chmod.run();
+}
+
+void runScript() {
+ // Launch script and show results on the console
+ Process myscript;
+ myscript.begin("/tmp/wlan-stats.sh");
+ myscript.run();
+
+ Console.print("WiFi RX/TX bytes: ");
+ while (myscript.available()) {
+ char c = myscript.read();
+ Console.print(c);
+ }
+ Console.println();
+ Console.flush();
+}
+