Arduino Yún Yún WiFi Status

Runs a pre-configured script that reports back the strength of the current WiFi network.

This sketch runs a script called "pretty-wifi-info.lua" installed on your Yún device 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 device to your computer using a USB cable and select the appropriate port from the Port menu before it will run.

Hardware Required

  • Yún board or shield

  • wireless network

Circuit

There is no circuit for this example.

The circuit for this tutorial.
The circuit for this tutorial.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

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.

1void setup() {
2
3 Serial.begin(9600);
4
5 while(!Serial);
6
7 Serial.println("Starting bridge...\n");
8
9 pinMode(13,OUTPUT);
10
11 digitalWrite(13, LOW);
12
13 Bridge.begin();
14
15 digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready
16
17 delay(2000);
18}

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.

1void loop() {
2
3 Process wifiCheck;
4
5 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.

1while (wifiCheck.available() > 0) {
2
3 char c = wifiCheck.read();
4
5 Serial.print(c);
6
7 }
8
9 Serial.println();
10
11 delay(5000);
12}

The complete code is below :

1/*
2
3 WiFi Status
4
5 This sketch runs a script called "pretty-wifi-info.lua"
6
7 installed on your Yún in folder /usr/bin.
8
9 It prints information about the status of your wifi connection.
10
11 It uses Serial to print, so you need to connect your YunShield/Yún to your
12
13 computer using a USB cable and select the appropriate port from
14
15 the Port menu
16
17 created 18 June 2013
18
19 By Federico Fissore
20
21 This example code is in the public domain.
22
23 http://www.arduino.cc/en/Tutorial/YunWiFiStatus
24
25 */
26
27#include <Process.h>
28
29void setup() {
30
31 SerialUSB.begin(9600); // initialize serial communication
32
33 while (!SerialUSB); // do nothing until the serial monitor is opened
34
35 SerialUSB.println("Starting bridge...\n");
36
37 pinMode(13, OUTPUT);
38
39 digitalWrite(13, LOW);
40
41 Bridge.begin(); // make contact with the linux processor
42
43 digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready
44
45 delay(2000); // wait 2 seconds
46}
47
48void loop() {
49
50 Process wifiCheck; // initialize a new process
51
52 wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua"); // command you want to run
53
54 // while there's any characters coming back from the
55
56 // process, print them to the serial monitor:
57
58 while (wifiCheck.available() > 0) {
59
60 char c = wifiCheck.read();
61
62 SerialUSB.print(c);
63
64 }
65
66 SerialUSB.println();
67
68 delay(5000);
69}

Last revision 2016/05/25 by SM

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.