File size: 1,908 Bytes
a9536d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /*
Running process using Process class.
This sketch demonstrate how to run linux processes
using a YunShield/Yún
created 5 Jun 2013
by Cristian Maglie
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Process
*/
#include <Process.h>
void setup() {
// Initialize Bridge
Bridge.begin();
// Initialize Serial
SerialUSB.begin(9600);
// Wait until a Serial Monitor is connected.
while (!SerialUSB);
// run various example processes
runCurl();
runCpuInfo();
}
void loop() {
// Do nothing here.
}
void runCurl() {
// Launch "curl" command and get Arduino ascii art logo from the network
// curl is command line program for transferring data using different internet protocols
Process p; // Create a process and call it "p"
p.begin("curl"); // Process that launch the "curl" command
p.addParameter("http://www.arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"
p.run(); // Run the process and wait for its termination
// Print arduino logo over the Serial
// A process output can be read with the stream methods
while (p.available() > 0) {
char c = p.read();
SerialUSB.print(c);
}
// Ensure the last bit of data is sent.
SerialUSB.flush();
}
void runCpuInfo() {
// Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
// cat is a command line utility that shows the content of a file
Process p; // Create a process and call it "p"
p.begin("cat"); // Process that launch the "cat" command
p.addParameter("/proc/cpuinfo"); // Add the cpuifo file path as parameter to cut
p.run(); // Run the process and wait for its termination
// Print command output on the SerialUSB.
// A process output can be read with the stream methods
while (p.available() > 0) {
char c = p.read();
SerialUSB.print(c);
}
// Ensure the last bit of data is sent.
SerialUSB.flush();
}
|