2013-06-22 08:03:35 +02:00
|
|
|
/*
|
2013-07-02 21:23:59 +02:00
|
|
|
Running shell commands using Process class.
|
2013-06-22 08:03:35 +02:00
|
|
|
|
|
|
|
This sketch demonstrate how to run linux shell commands
|
2013-06-25 20:07:53 +02:00
|
|
|
using an Arduino Yún. It runs the wifiCheck script on the linino side
|
|
|
|
of the Yun, then uses grep to get just the signal strength line.
|
|
|
|
Then it uses parseInt() to read the wifi signal strength as an integer,
|
|
|
|
and finally uses that number to fade an LED using analogWrite().
|
|
|
|
|
2013-06-22 08:03:35 +02:00
|
|
|
The circuit:
|
2013-06-25 20:07:53 +02:00
|
|
|
* Arduino Yun with LED connected to pin 9
|
2013-06-22 08:03:35 +02:00
|
|
|
|
|
|
|
created 12 Jun 2013
|
|
|
|
by Cristian Maglie
|
2013-06-25 20:07:53 +02:00
|
|
|
modified 25 June 2013
|
2013-06-22 08:03:35 +02:00
|
|
|
by Tom Igoe
|
|
|
|
|
|
|
|
This example code is in the public domain.
|
2013-06-25 20:07:53 +02:00
|
|
|
|
2013-06-22 08:03:35 +02:00
|
|
|
*/
|
2013-06-12 13:28:24 +02:00
|
|
|
|
|
|
|
#include <Process.h>
|
|
|
|
|
|
|
|
void setup() {
|
2013-07-02 21:23:59 +02:00
|
|
|
Bridge.begin(); // Initialize the Bridge
|
|
|
|
Serial.begin(9600); // Initialize the Serial
|
|
|
|
|
|
|
|
// Wait until a Serial Monitor is connected.
|
|
|
|
while(!Serial);
|
2013-06-12 13:28:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
Process p;
|
2013-07-05 15:06:37 +02:00
|
|
|
// This command line runs the WifiStatus script, (/usr/bin/pretty-wifi-info.lua), then
|
2013-06-25 20:07:53 +02:00
|
|
|
// sends the result to the grep command to look for a line containing the word
|
|
|
|
// "Signal:" the result is passed to this sketch:
|
2013-07-05 15:06:37 +02:00
|
|
|
p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal");
|
2013-06-12 13:28:24 +02:00
|
|
|
|
2013-06-25 20:07:53 +02:00
|
|
|
// do nothing until the process finishes, so you get the whole output:
|
|
|
|
while(p.running());
|
|
|
|
|
|
|
|
// Read command output. runShellCommand() should have passed "Signal: xx&":
|
2013-06-12 13:28:24 +02:00
|
|
|
while (p.available()) {
|
2013-07-02 21:23:59 +02:00
|
|
|
int result = p.parseInt(); // look for an integer
|
|
|
|
int signal = map(result, 0, 100, 0, 255); // map result from 0-100 range to 0-255
|
|
|
|
analogWrite(9, signal); // set the brightness of LED on pin 9
|
|
|
|
Serial.println(result); // print the number as well
|
2013-06-22 08:03:35 +02:00
|
|
|
}
|
2013-07-02 21:23:59 +02:00
|
|
|
delay(5000); // wait 5 seconds before you do it again
|
2013-06-12 13:28:24 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 20:07:53 +02:00
|
|
|
|
|
|
|
|