Arduino Yún Wi-Fi Status
Runs a pre-configured script that reports back the strength of the current Wi-Fi 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 Wi-Fi 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.
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 ready16
17 delay(2000);18}
In
loop()
, initialize a new process that will run the Wi-Fi 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 Status4
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 your12
13 computer using a USB cable and select the appropriate port from14
15 the Port menu16
17 created 18 June 201318
19 By Federico Fissore20
21 This example code is in the public domain.22
23 http://www.arduino.cc/en/Tutorial/YunWiFiStatus24
25 */26
27#include <Process.h>28
29void setup() {30
31 SerialUSB.begin(9600); // initialize serial communication32
33 while (!SerialUSB); // do nothing until the serial monitor is opened34
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 processor42
43 digitalWrite(13, HIGH); // Led on pin 13 turns on when the bridge is ready44
45 delay(2000); // wait 2 seconds46}47
48void loop() {49
50 Process wifiCheck; // initialize a new process51
52 wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua"); // command you want to run53
54 // while there's any characters coming back from the55
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
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.