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