From 78f0baeb26a05a5fc547848c62d71a69dae47479 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 18 Jun 2013 16:42:24 +0200 Subject: wifi examples renamed OLD*, introducing new comprehensive WiFiStatus example reviewed ShellCommands example to be not wifi related --- .../Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino | 53 ++++++++++ .../OLDWifiSignalStrengthIndicator.ino | 112 +++++++++++++++++++++ .../examples/ShellCommands/ShellCommands.ino | 4 +- libraries/Bridge/examples/WiFiCheck/WiFiCheck.ino | 53 ---------- .../Bridge/examples/WiFiStatus/WiFiStatus.ino | 32 ++++++ .../WifiSignalStrengthIndicator.ino | 112 --------------------- 6 files changed, 199 insertions(+), 167 deletions(-) create mode 100644 libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino create mode 100644 libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino delete mode 100644 libraries/Bridge/examples/WiFiCheck/WiFiCheck.ino create mode 100644 libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino delete mode 100644 libraries/Bridge/examples/WifiSignalStrengthIndicator/WifiSignalStrengthIndicator.ino diff --git a/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino b/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino new file mode 100644 index 0000000..1cb9f03 --- /dev/null +++ b/libraries/Bridge/examples/OLDWiFiCheck/OLDWiFiCheck.ino @@ -0,0 +1,53 @@ +/* + Arduino Yun Wireless Config Check + + Checks the wireless state of Arduino Yun by calling + the linux command iwconfig. + + Upload this to an Arduino Yun via serial (not WiFi) + then open the serial monitor to see the status of + your Yun's WiFi connection. If it's connected to + a wireless network, the ESSID (name) of that network + and the signal strength will appear. + + The circuit: + * Arduino Yun + + created 22 May 2013 + by Tom Igoe + + This example code is in the public domain. + */ + +#include + +void setup() { + Serial.begin(9600); // initialize serial communication + while(!Serial); // do nothing until the serial monitor is opened + + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); // make contact with the linux processor + digitalWrite(13, HIGH); + + delay(2000); // wait 2 seconds + + Process wifiCheck; // initialize a new process + + + wifiCheck.begin("iwconfig"); // command you want to run + wifiCheck.addParameter("wlan0"); // parameter of the command + wifiCheck.run(); // run the command + + // while there's any characters coming back from the + // process, print them to the serial monitor: + while (wifiCheck.available() > 0) { + char thisChar = wifiCheck.read(); + Serial.print(thisChar); + } +} + +void loop() { + // nothing to do here. +} + diff --git a/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino b/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino new file mode 100644 index 0000000..e0b2d1f --- /dev/null +++ b/libraries/Bridge/examples/OLDWifiSignalStrengthIndicator/OLDWifiSignalStrengthIndicator.ino @@ -0,0 +1,112 @@ +/* + Wifi Signal Strength Indicator + + This example demonstrates the use of the bridge and process libraries + to communicate between the Arduino side and the linux side of the Arduino Yun. + + The Linux script returns the strength of the wifi signal. + + The Arduino sketch uses LEDs to indicate whether the current value of + the signal strength is above, below, or the same as the last value + + The circuit: + * LEDs on pins 8, 9, and 10 + * Built-in LED on pin 13 + + The script: + The following one line script must exist in the /root directory of the + linux file system, in a file named "wifiStrength.sh", and it must be executable: + + tail -1 /proc/net/wireless | cut -c22-23 + + created 06 June 2013 + by Michael Shiloh + modified 08 June 2013 + by Tom Igoe + + This example code is in the public domain + + */ + + +#include + +// global variable to store the last value of the signal strength +int lastValue; + +void setup() { + // set up LED pins as outputs: + pinMode(8, OUTPUT); + pinMode(9, OUTPUT); + pinMode(10, OUTPUT); + pinMode(13,OUTPUT); + + // Indicate that you're ready by flashing pin 13 LED twice + for (int flash = 0; flash < 3; flash++) { + digitalWrite(13,HIGH); + delay(200); + digitalWrite(13,LOW); + delay(800); + } + // initialize Serial and Bridge: + Serial.begin(9600); + Bridge.begin(); + + // Indicate that setup is finished + digitalWrite(13,HIGH); +} + +void loop() { + int value = 0; // the signal strength as an integer + String result; // the result of the process as a String + Process wifiCheck; // the process itself + + + // Run the script on the linux side. Note that any word + //or text separated by a tab or space is considered + //an additional parameter: + wifiCheck.begin("ash"); + wifiCheck.addParameter("/root/wifiStrength.sh"); + wifiCheck.run(); + + // If the process has sent any characters: + while (wifiCheck.available()>0) { + result = wifiCheck.readString(); // read the result into a string + value = result.toInt(); // parse the string as an int + } + + // for debugging + Serial.print("previous strength:"); + Serial.print(lastValue); + Serial.print("\tcurrent strength:"); + Serial.println(value); + + // indicate the relative string by lighting the appropriate LED + allOff(); // turn off all the LEDS + + if (value > lastValue) { // if the signal's getting stronger + digitalWrite(10, HIGH); + } + else if (value < lastValue){ // if the signal's getting weaker + digitalWrite(8, HIGH); + } + else { // if the signal's stayed steady + digitalWrite(9, HIGH); + } + + lastValue = value; // record this value for next time + delay(10); // small delay before next time through the loop +} + + +void allOff() { + digitalWrite(8, LOW); + digitalWrite(9, LOW); + digitalWrite(10, LOW); +} + + + + + + diff --git a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino index a362ed8..4fd7384 100644 --- a/libraries/Bridge/examples/ShellCommands/ShellCommands.ino +++ b/libraries/Bridge/examples/ShellCommands/ShellCommands.ino @@ -11,8 +11,8 @@ void setup() { void loop() { Process p; - // This command line prints the number of bytes received and transmitted from WLAN - p.runShellCommand(F("ifconfig wlan0 | grep \"RX bytes\" | tr ':' ' ' | awk \"{ print \\$3 \\\" \\\" \\$8 }\"\n")); + // This command line prints the name of the wireless that the board is connected to or that the board has created + p.runShellCommand(F("lua /usr/lib/lua/pretty_wifi_info.lua | grep SSID")); // Read command output while (p.available()) { diff --git a/libraries/Bridge/examples/WiFiCheck/WiFiCheck.ino b/libraries/Bridge/examples/WiFiCheck/WiFiCheck.ino deleted file mode 100644 index 1cb9f03..0000000 --- a/libraries/Bridge/examples/WiFiCheck/WiFiCheck.ino +++ /dev/null @@ -1,53 +0,0 @@ -/* - Arduino Yun Wireless Config Check - - Checks the wireless state of Arduino Yun by calling - the linux command iwconfig. - - Upload this to an Arduino Yun via serial (not WiFi) - then open the serial monitor to see the status of - your Yun's WiFi connection. If it's connected to - a wireless network, the ESSID (name) of that network - and the signal strength will appear. - - The circuit: - * Arduino Yun - - created 22 May 2013 - by Tom Igoe - - This example code is in the public domain. - */ - -#include - -void setup() { - Serial.begin(9600); // initialize serial communication - while(!Serial); // do nothing until the serial monitor is opened - - pinMode(13,OUTPUT); - digitalWrite(13, LOW); - Bridge.begin(); // make contact with the linux processor - digitalWrite(13, HIGH); - - delay(2000); // wait 2 seconds - - Process wifiCheck; // initialize a new process - - - wifiCheck.begin("iwconfig"); // command you want to run - wifiCheck.addParameter("wlan0"); // parameter of the command - wifiCheck.run(); // run the command - - // while there's any characters coming back from the - // process, print them to the serial monitor: - while (wifiCheck.available() > 0) { - char thisChar = wifiCheck.read(); - Serial.print(thisChar); - } -} - -void loop() { - // nothing to do here. -} - diff --git a/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino new file mode 100644 index 0000000..840ceee --- /dev/null +++ b/libraries/Bridge/examples/WiFiStatus/WiFiStatus.ino @@ -0,0 +1,32 @@ +#include + +void setup() { + Serial.begin(9600); // initialize serial communication + while(!Serial); // do nothing until the serial monitor is opened + + Serial.println("Starting bridge...\n"); + pinMode(13,OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); // make contact with the linux processor + digitalWrite(13, HIGH); + + delay(2000); // wait 2 seconds +} + +void loop() { + Process wifiCheck; // initialize a new process + + wifiCheck.runShellCommand("lua /usr/lib/lua/pretty_wifi_info.lua"); // command you want to run + + // while there's any characters coming back from the + // process, print them to the serial monitor: + while (wifiCheck.available() > 0) { + char thisChar = wifiCheck.read(); + Serial.print(thisChar); + } + + Serial.println(); + + delay(5000); +} + diff --git a/libraries/Bridge/examples/WifiSignalStrengthIndicator/WifiSignalStrengthIndicator.ino b/libraries/Bridge/examples/WifiSignalStrengthIndicator/WifiSignalStrengthIndicator.ino deleted file mode 100644 index e0b2d1f..0000000 --- a/libraries/Bridge/examples/WifiSignalStrengthIndicator/WifiSignalStrengthIndicator.ino +++ /dev/null @@ -1,112 +0,0 @@ -/* - Wifi Signal Strength Indicator - - This example demonstrates the use of the bridge and process libraries - to communicate between the Arduino side and the linux side of the Arduino Yun. - - The Linux script returns the strength of the wifi signal. - - The Arduino sketch uses LEDs to indicate whether the current value of - the signal strength is above, below, or the same as the last value - - The circuit: - * LEDs on pins 8, 9, and 10 - * Built-in LED on pin 13 - - The script: - The following one line script must exist in the /root directory of the - linux file system, in a file named "wifiStrength.sh", and it must be executable: - - tail -1 /proc/net/wireless | cut -c22-23 - - created 06 June 2013 - by Michael Shiloh - modified 08 June 2013 - by Tom Igoe - - This example code is in the public domain - - */ - - -#include - -// global variable to store the last value of the signal strength -int lastValue; - -void setup() { - // set up LED pins as outputs: - pinMode(8, OUTPUT); - pinMode(9, OUTPUT); - pinMode(10, OUTPUT); - pinMode(13,OUTPUT); - - // Indicate that you're ready by flashing pin 13 LED twice - for (int flash = 0; flash < 3; flash++) { - digitalWrite(13,HIGH); - delay(200); - digitalWrite(13,LOW); - delay(800); - } - // initialize Serial and Bridge: - Serial.begin(9600); - Bridge.begin(); - - // Indicate that setup is finished - digitalWrite(13,HIGH); -} - -void loop() { - int value = 0; // the signal strength as an integer - String result; // the result of the process as a String - Process wifiCheck; // the process itself - - - // Run the script on the linux side. Note that any word - //or text separated by a tab or space is considered - //an additional parameter: - wifiCheck.begin("ash"); - wifiCheck.addParameter("/root/wifiStrength.sh"); - wifiCheck.run(); - - // If the process has sent any characters: - while (wifiCheck.available()>0) { - result = wifiCheck.readString(); // read the result into a string - value = result.toInt(); // parse the string as an int - } - - // for debugging - Serial.print("previous strength:"); - Serial.print(lastValue); - Serial.print("\tcurrent strength:"); - Serial.println(value); - - // indicate the relative string by lighting the appropriate LED - allOff(); // turn off all the LEDS - - if (value > lastValue) { // if the signal's getting stronger - digitalWrite(10, HIGH); - } - else if (value < lastValue){ // if the signal's getting weaker - digitalWrite(8, HIGH); - } - else { // if the signal's stayed steady - digitalWrite(9, HIGH); - } - - lastValue = value; // record this value for next time - delay(10); // small delay before next time through the loop -} - - -void allOff() { - digitalWrite(8, LOW); - digitalWrite(9, LOW); - digitalWrite(10, LOW); -} - - - - - - -- cgit v1.2.3-18-g5258