This sketch demonstrates running Linux shell commands on an Arduino Yún.
It runs the wifiCheck script (located at /usr/bin/pretty-wifi-info.lua) on the Linux processor, then uses grep to get the signal strength.
On the 32U4, parseInt() is called to read the WiFi signal strength as an integer, and uses that number to fade an LED with
A red LED connected to digital pin 9 through a 220 ohm resistor on the breadboard.
Include the Process class in your sketch.
setup(), you'll want to initialize Bridge and start a serial connection. Before running the rest of the sketch, wait for a serial connection to become active.
Create a named Process with which you'll use to run the WiFi status script and grep.
runShellCommand() the path of the script you wish to run, along with any additional commands. In this case, you'll call "grep Signal" to pull out just the signal strength of the WiFi connection.
p.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal");
Wait until the process finishes so you get the entire output
Once the process has finished running, use
parseInt() to look for an integer that represents the signal strength. It should be in the range of 0 - 100. Map the result to a value between 0 and 255 with
map() and use that value to adjust the brightness of the LED on pin 9 with
analogWrite(). Print the signal strength to the serial monitor and wait for a few seconds before starting again.
The LED should change its brightness as the WiFi signal strength fluctuates.
The complete sketch is below:
Last revision 2015/08/12 by SM