Learning   Examples | Foundations | Hacking | Links

Examples > WiFiStatus

Yún WiFi Status

This sketch runs a script called "pretty-wifi-info.lua" installed on your Yún in the folder /usr/bin. It prints information about the status of your WiFi connection.

It uses Serial to print, so you need to connect your Yún to your computer using a USB cable and select the appropriate port from the Port menu before it will run.

Hardware Required

  • Arduino Yún
  • wireless network

Circuit

There is no circuit for this example.

Code

You'll first need to include the Process class :
#include <Process.h>

In setup(), start serial communication, and the Bridge. The sketch won't run until a serial connection is made.

void setup() {
  Serial.begin(9600);
  while(!Serial);      

  Serial.println("Starting bridge...\n");
  pinMode(13,OUTPUT);  
  digitalWrite(13, LOW);  
  Bridge.begin();  
  digitalWrite(13, HIGH);  // Led on pin 13 turns on when the bridge is ready

  delay(2000);  
}

In loop(), initialize a new process that will run the WiFi check script. you can run the script by calling @runShellCommand()@@ with the path to the script.

void loop() {
  Process wifiCheck;
  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");

Print out any characters returned by the script to the serial monitor, and wair for a few seconds before running again.

while (wifiCheck.available() > 0) {
    char c = wifiCheck.read();
    Serial.print(c);
  }

  Serial.println();

  delay(5000);
}

The complete code is below :

/*
 WiFi Status

 This sketch runs a script called "pretty-wifi-info.lua"
 installed on your Yún in folder /usr/bin.
 It prints information about the status of your wifi connection.

 It uses Serial to print, so you need to connect your Yún to your
 computer using a USB cable and select the appropriate port from
 the Port menu

 created  18 June 2013
 By Federico Fissore

 This example code is in the public domain.
 */


#include <Process.h>

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);  // Led on pin 13 turns on when the bridge is ready

  delay(2000);  // wait 2 seconds
}

void loop() {
  Process wifiCheck;  // initialize a new process

  wifiCheck.runShellCommand("/usr/bin/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 c = wifiCheck.read();
    Serial.print(c);
  }

  Serial.println();

  delay(5000);
}
 

Share