2013-06-05 14:51:15 +02:00
|
|
|
/*
|
|
|
|
Running process using Process class.
|
|
|
|
|
|
|
|
This sketch demonstrate how to run linux processes
|
|
|
|
using an Arduino Yún.
|
|
|
|
|
|
|
|
created 5 Jun 2013
|
|
|
|
by Cristian Maglie
|
|
|
|
|
2013-07-02 15:17:22 +02:00
|
|
|
This example code is in the public domain.
|
2013-09-09 20:56:15 +02:00
|
|
|
|
|
|
|
http://arduino.cc/en/Tutorial/Process
|
2013-07-02 15:17:22 +02:00
|
|
|
|
2013-06-05 14:51:15 +02:00
|
|
|
*/
|
|
|
|
|
2013-05-09 11:14:59 +02:00
|
|
|
#include <Process.h>
|
|
|
|
|
|
|
|
void setup() {
|
2013-07-02 15:17:22 +02:00
|
|
|
// Initialize Bridge
|
2013-05-09 11:14:59 +02:00
|
|
|
Bridge.begin();
|
2013-06-05 20:20:18 +02:00
|
|
|
|
2013-07-02 15:17:22 +02:00
|
|
|
// Initialize Serial
|
|
|
|
Serial.begin(9600);
|
2013-06-05 20:20:18 +02:00
|
|
|
|
2013-07-02 15:17:22 +02:00
|
|
|
// Wait until a Serial Monitor is connected.
|
|
|
|
while (!Serial);
|
2013-06-05 14:51:15 +02:00
|
|
|
|
|
|
|
// run various example processes
|
|
|
|
runCurl();
|
|
|
|
runCpuInfo();
|
|
|
|
}
|
2013-05-16 10:28:00 +02:00
|
|
|
|
2013-06-05 14:51:15 +02:00
|
|
|
void loop() {
|
|
|
|
// Do nothing here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void runCurl() {
|
2013-07-02 15:17:22 +02:00
|
|
|
// 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
|
2013-06-05 20:20:18 +02:00
|
|
|
p.addParameter("http://arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"
|
2013-07-02 15:17:22 +02:00
|
|
|
p.run(); // Run the process and wait for its termination
|
2013-06-05 14:51:15 +02:00
|
|
|
|
2013-07-02 15:17:22 +02:00
|
|
|
// Print arduino logo over the Serial
|
2013-06-05 20:20:18 +02:00
|
|
|
// A process output can be read with the stream methods
|
2013-05-16 10:28:00 +02:00
|
|
|
while (p.available()>0) {
|
|
|
|
char c = p.read();
|
2013-07-02 15:17:22 +02:00
|
|
|
Serial.print(c);
|
2013-05-09 11:14:59 +02:00
|
|
|
}
|
2013-07-02 15:17:22 +02:00
|
|
|
// Ensure the last bit of data is sent.
|
|
|
|
Serial.flush();
|
2013-05-09 11:14:59 +02:00
|
|
|
}
|
|
|
|
|
2013-06-05 14:51:15 +02:00
|
|
|
void runCpuInfo() {
|
|
|
|
// Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
|
2013-07-02 15:17:22 +02:00
|
|
|
// 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
|
2013-06-05 14:51:15 +02:00
|
|
|
|
2013-07-02 15:17:22 +02:00
|
|
|
// Print command output on the Serial.
|
2013-06-05 20:20:18 +02:00
|
|
|
// A process output can be read with the stream methods
|
2013-06-05 14:51:15 +02:00
|
|
|
while (p.available()>0) {
|
|
|
|
char c = p.read();
|
2013-07-02 15:17:22 +02:00
|
|
|
Serial.print(c);
|
2013-06-05 14:51:15 +02:00
|
|
|
}
|
2013-07-02 15:17:22 +02:00
|
|
|
// Ensure the last bit of data is sent.
|
|
|
|
Serial.flush();
|
2013-05-09 11:14:59 +02:00
|
|
|
}
|
2013-06-05 14:51:15 +02:00
|
|
|
|