1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

71 lines
1.7 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
*/
#include <Process.h>
void setup() {
2013-06-05 14:51:15 +02:00
// Setup Bridge (needed every time we communicate with the Arduino Yún)
Bridge.begin();
2013-06-05 20:20:18 +02:00
2013-06-05 14:51:15 +02:00
// Setup Console
Console.begin();
2013-06-05 20:20:18 +02:00
// Buffering improves Console performance, but we must remember to
// finish sending using the Console.flush() command.
2013-06-05 14:51:15 +02:00
Console.buffer(64);
2013-06-05 20:20:18 +02:00
2013-06-05 14:51:15 +02:00
// Wait until a Network Monitor is connected.
while (!Console);
// 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 asciilogo from the network
2013-06-05 20:20:18 +02:00
Process p; // Create a process and call it "p"
p.begin("curl"); // Process should launch the "curl" command
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
2013-06-05 20:20:18 +02:00
// Print arduino logo over the console.
// 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-06-05 14:51:15 +02:00
Console.print(c);
}
2013-06-05 20:20:18 +02:00
// Ensure the latest bit of data is sent.
2013-06-05 14:51:15 +02:00
Console.flush();
}
2013-06-05 14:51:15 +02:00
void runCpuInfo() {
// Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
Process p;
p.begin("cat");
p.addParameter("/proc/cpuinfo");
p.run();
2013-06-05 20:20:18 +02:00
// Print command output on the Console.
// 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();
Console.print(c);
}
2013-06-05 20:20:18 +02:00
// Ensure the latest bit of data is sent.
2013-06-05 14:51:15 +02:00
Console.flush();
}
2013-06-05 14:51:15 +02:00