I try to retreive some Wifi info from my Yun (signal, mac address from Access Point and Frequency) with 3 specific functions.
In my loop() section, I try to call every 10 seconds my 3 functions, theses functions can only be called once, when a make a second call every function returns a empty string.
Probably a mistake worthy of a beginner.
Any ideas or comments are welcome.
Code of functions:
String Signal() {
//return signal in a range of 0 to 100
Process sCheck; // initialize a new process
reponse = "";
sCheck.runShellCommand(" /usr/bin/pretty-wifi-info.lua | grep Signal 2>&1"); // command you want to run
// a good answer looks like : Signal: 100%
//while (sCheck.running()); is it necessary ? works with or without once
Serial.print("Signal()>");
while (sCheck.available() > 0) {
char c = sCheck.read();
Serial.print(c);
reponse.concat(c);
}
reponse = reponse.substring(8, 11);
reponse.replace(" ", "0");
reponse.replace("%", "");
reponse.trim();
// return 100 for 100%
return reponse;
}
//
String Freq() {
// return the current frequency
Process fCheck; // initialize a new process
String reponse;
String frequence, ap;
reponse = "";
fCheck.runShellCommand("iwconfig wlan0 | grep 'Mode' | tr -s ' ' 2>&1");
Serial.print("Freq()>");
//while (fCheck.running());
// output is like : Mode:Managed Frequency:2.462 GHz Access Point: 28:37:37:4A:28:22
while (fCheck.available() > 0) {
char c = fCheck.read();
Serial.print(c);
reponse.concat(c);
}
reponse.trim();
frequence = reponse.substring(23, 28);
reponse = frequence;
reponse.replace(".", "");
return reponse;
}
//
String Ap() {
// return mac BSSID
Process aCheck; // initialize a new process
String reponse;
String frequence, ap;
reponse = "";
aCheck.runShellCommand("iwconfig wlan0 | grep 'Mode' | tr -s ' ' 2>&1");
// normal answer look like : Mode:Managed Frequency:2.462 GHz Access Point: 28:37:37:4A:28:22
//while (aCheck.running());
Serial.print("Ap()>");
while (aCheck.available() > 0) {
char c = aCheck.read();
Serial.print(c);
reponse.concat(c);
}
reponse.trim();
frequence = reponse.substring(23, 28);
ap = reponse.substring(47, 64);
reponse = ap;
return reponse;
}