1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-13 23:48:46 +01:00
Arduino/libraries/Bridge/examples/Process/Process.ino

73 lines
1.8 KiB
Arduino
Raw Normal View History

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
This example code is in the public domain.
2013-09-09 20:56:15 +02:00
http://arduino.cc/en/Tutorial/Process
2013-06-05 14:51:15 +02:00
*/
#include <Process.h>
void setup() {
// Initialize Bridge
Bridge.begin();
2013-06-05 20:20:18 +02:00
// Initialize Serial
Serial.begin(9600);
2013-06-05 20:20:18 +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() {
// 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"
p.run(); // Run the process and wait for its termination
2013-06-05 14:51:15 +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();
Serial.print(c);
}
// Ensure the last bit of data is sent.
Serial.flush();
}
2013-06-05 14:51:15 +02:00
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
2013-06-05 14:51:15 +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();
Serial.print(c);
2013-06-05 14:51:15 +02:00
}
// Ensure the last bit of data is sent.
Serial.flush();
}
2013-06-05 14:51:15 +02:00