Go Down

Topic: is it possible to control the wifi led? Any command? (Read 9544 times) previous topic - next topic

ProfePaco

A friend of mine has sent me the way to know whether the yun in connected to wifi.

for example:

runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); // grab just the signal data
unShellCommand("/usr/bin/pretty-wifi-info.lua | grep RX");
runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Active"); // grab just the uptime
runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Interface");    // grab just the RX/TX
runShellCommand("/usr/bin/pretty-wifi-info.lua | grep IP");     // grab just the ip data

The question is if we could switch the led on/off from the arduino sketch side to show if Yun is connected.

Any way to do it? Of course this led is not attached to any pin...so, if possible, it has to be tricky.

Thanks in advance

federicofissore

Of course it's possible
Take a look at script /usr/bin/blink-start or invoke
Code: [Select]

blink-start 100
blink-start 500

You can use two leds (wlan and usb). You can find more info and docs at http://wiki.openwrt.org/doc/uci/system#leds

ProfePaco


Of course it's possible
Take a look at script /usr/bin/blink-start or invoke
Code: [Select]

blink-start 100
blink-start 500

You can use two leds (wlan and usb). You can find more info and docs at http://wiki.openwrt.org/doc/uci/system#leds


Thanks!

More things to study  :)

federicofissore


ProfePaco

#4
Dec 05, 2013, 05:47 pm Last Edit: Dec 05, 2013, 06:52 pm by ProfePaco Reason: 1
Here is the code. Now Arduino Yun shows the wifi state using the blue wifi led!


Code: [Select]

/*subroutine checkwificonnected.
Checks the strngth of wifi and show information on blue wifi led of Arduino Yun.
Checks the wifi signal after period_check miliseconds

1.- if no connected then blue wifi led is off
2.- if signal strength is more than good_strength value then blinks slowly (1 second).
3.- if singal is not zero but less than good_strength blinks fast (0.2 seconds).

*/


#include <Process.h>
Process wifiCheck;  // process used to get the wifi status
unsigned long now, before;
#define period_check 5000 //time in miliseconds to check wifi signal
#define good_strength 25



void setup()
{
 before = 0;
 now = millis();
 Bridge.begin();        // initialize Bridge
 //Serial.begin(9600);    // initialize serial. Only for degugging  
}

void loop()
{
 now = millis();
if (now - before > period_check ) {checkwificonnected(); before = now;}
}





//==========================================================//

void checkwificonnected(void)
{
wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); // grab just the signal data
 String strength = wifiCheck.readString();
 byte totallength = strength.length();
 strength = strength.substring(totallength-4,totallength-1);
 byte level = strength.toInt();
// Serial.println(level); //for debugging only
 
 if (level >= good_strength) {wifiCheck.runShellCommand("/usr/bin/blink-start 1000");};
 if (level >0 && level < good_strength) {wifiCheck.runShellCommand("/usr/bin/blink-start 200");};
 if (level == 0) {wifiCheck.runShellCommand("/usr/bin/blink-stop");} ;

}






ProfePaco

#5
Dec 05, 2013, 06:00 pm Last Edit: Dec 05, 2013, 06:03 pm by ProfePaco Reason: 1
this version is much better. It only runs the command if the status of quality signal has changed

Code: [Select]

/*subroutine checkwificonnected.
Checks the strngth of wifi and show information on blue wifi led of Arduino Yun.
Checks the wifi signal after period_check miliseconds

1.- if no connected then blue wifi led is off
2.- if signal strength is more than good_strength value then blinks slowly (1 second).
3.- if singal is not zero but less than good_strength blinks fast (0.2 seconds).

*/


#include <Process.h>
Process wifiCheck;  // process used to get the wifi status
unsigned long now, before;
#define period_check 5000 //time in miliseconds to check wifi signal
#define good_strength 25
byte previous_state = 0;




void setup()
{
 before = 0;
 now = millis();
 Bridge.begin();        // initialize Bridge
 //Serial.begin(9600);    // initialize serial. Only for degugging  
}

void loop()
{
 now = millis();
if (now - before > period_check ) {checkwificonnected(); before = now;}
}





//==========================================================//

void checkwificonnected(void)
{
wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua | grep Signal"); // grab just the signal data
 String strength = wifiCheck.readString();
 byte totallength = strength.length();
 strength = strength.substring(totallength-4,totallength-1);
 byte level = strength.toInt();
// Serial.println(level); //for debugging only
 
 if (level >= good_strength) {
     if (previous_state != 1)
         {previous_state = 1;
         wifiCheck.runShellCommand("/usr/bin/blink-start 1000");}};
 if (level >0 && level < good_strength) {
     if (previous_state != 2)
         {previous_state = 2;
          wifiCheck.runShellCommand("/usr/bin/blink-start 200");};}
 if (level == 0) {
      if (previous_state != 3)
          {previous_state = 3;
           wifiCheck.runShellCommand("/usr/bin/blink-stop");} ;}

}



ProfePaco

#7
Dec 05, 2013, 07:00 pm Last Edit: Dec 05, 2013, 07:04 pm by ProfePaco Reason: 1

Nice! That comes in pretty handy.


Thanks.

I think something is left. I think that the function milllis() reaches a maximum after several days... 52 days?... and then the value of millis() starts from zero again. If so some code has to be added.

for example:

if (before > now) {before = now;}

Am I right?

noblepepper

The usual way people handle the millis() rollover is to use unsigned ints, the magic of ones complement math makes the difference correct.

Try this:
Code: [Select]

void setup() {
  // put your setup code here, to run once:
unsigned int a, b;
delay(1000);
a = 0xFFF8;//65528
b = 0x0008;//    8
Serial.begin(115200);
while (!Serial) ;
Serial.println(a);
Serial.println(b);
Serial.println(b-a);
}

void loop() {
  // put your main code here, to run repeatedly:

}

AlexDC


PCWorxLA

#10
Dec 09, 2013, 08:44 pm Last Edit: Dec 09, 2013, 09:04 pm by PCWorxLA Reason: 1
Just as a general note, if the purpose is only to display the status via the LED, why don't you just run a Python script (possibly via cron) on the Linino side instead of going through hoops to do this on the 32u4 side?  :~

Ralf

mamu

PCWorxLA, good point (had the same on my mind)  :smiley-roll:

ProfePaco


Just as a general note, if the purpose is only to display the status via the LED, why don't you just run a Python script (possibly via cron) on the Linino side instead of going through hoops to do this on the 32u4 side?  :~

Ralf


Because I do not know how to do it, obviously.

Now you have a new task to do. Thanks for your offer  :smiley-roll:

PCWorxLA



Just as a general note, if the purpose is only to display the status via the LED, why don't you just run a Python script (possibly via cron) on the Linino side instead of going through hoops to do this on the 32u4 side?  :~

Ralf


Because I do not know how to do it, obviously.
Well, you have it already almost completely running on the Linino side already with all the shell commands. Would be just a matter of interpreting the output in a Python script instead of pushing it down the bridge.
There is always something new to learn...  :smiley-mr-green:
Quote
Now you have a new task to do. Thanks for your offer  :smiley-roll:
Well, "schaun 'mer mal"...  8)
But it's likely not going to happen before the weekend though...  ;)

Ralf

PCWorxLA

Holy mackerel, Batman!  :smiley-eek-blue:

Nothing personal ProfePaco,  but I just took actually a closer look at the script and almost fell of my chair! =(

This is what we would call in German "Von hinten durch die Brust ins Auge".
Or as someone in another Arduino forum just stated "for someone who only knows a hammer as a tool, everything looks like a nail"...

You are actually using an Arduino Sketch on the 32u4 side to  call a Python script on the Linino side to call a Lua script and two shell scripts also on the Linino side to actually access some hardware on the Linino side...

Don't have my Yun during the (at least this) week on a wireless network to test this, but this certainly cries to be replaced by a Linino side only solution, probably by adapting the pretty-wifi-info.lua script...

Ralf

Go Up