Am I way off?

Forum rules
Before you post please read this

Re: Am I way off?

Postby Pilosopong Tasyo on Sat Nov 12, 2011 9:07 pm

tpprynn wrote:Wow, really. So it's worked for you. (Does that mean you weren't bothered until working out this script?)

To be perfectly honest with you, I never really paid any attention to the WiFi LED on my laptop (probably because there's always an indicator on the panel that tells me if WiFi is enabled or not). Years ago when Windows XP was installed, the LED does turn on/off when I push the WiFi button. But that was because the corresponding laptop drivers were installed as well. When I switched to Linux, the LED was constantly ON. I didn't let it bother me because back then, I knew that there may be some things that are not going to work under the Linux platform (compliments of the hardware manufacturer for NOT supporting Linux by NOT providing proper Linux drivers for it).

Then, this thread came along. :lol: And it piqued my curiosity.

tpprynn wrote:This is a Toshiba laptop that uses the asus_laptop module...

Perhaps this is one of those things you have to consider why the script won't work for you? I mean even if the asus_laptop module is supposed to be compatible with a Toshiba hardware, there is always the possibility of things -- no matter how small they are (literally, like an LED :lol: sorry I couldn't resist) -- of not working as expected. The hack I wrote worked on my end because the hardware exactly matches the module installed on my system. Unfortunately, the same can't be said in your case.

---

It's time to debug (FUN!) or at least determine where it went wrong, and see if there's another way to do this. Back in my original post, we already know that Step (2) will work:

Code: Select all
echo "1" > /sys/devices/platform/asus_laptop/wlan # turn on the LED
echo "0" > /sys/devices/platform/asus_laptop/wlan # turn off the LED

So there's no issue with that. I suspect that step (1) is not doing what it's supposed to do on your end. Humor me for a moment and perform a simple experiment for me. In terminal, copy/paste the following:

Code: Select all
while [ true ] ; do echo -n "`cat /sys/class/net/wlan0/operstate` " ; sleep 1 ; done

You mentioned your WiFi interface is wlan0 instead of wlan1. What the above piece of code will do is simply display on screen the operational state of your WiFi. It should show either "up," "down" or "dormant" in one-second intervals (I recently discovered "dormant" while performing this on my laptop). While it's looping, disable/enable your WiFi via Network Manager, one of the Fn+<whatever> combo keys on the keyboard, and physical WiFi switch/button on the laptop (if there's any). The state change should reflect on the terminal window. To interrupt the loop, just hit Ctrl+C. Ideally, the output should be similar to the following:

Code: Select all
administrator@asus-a8jn ~ $ while [ true ] ; do echo -n "`cat /sys/class/net/wlan0/operstate` " ; sleep 1 ; done
up up up up up down down down down down down down down down down down down down down up up up up up up up down down down down down down down down down up up up up up up up down down down down down down down dormant up up up up up up up up up up up up ^C
administrator@asus-a8jn ~ $

I tried the three methods mentioned above to disable/enable my WiFi, hence the output. What does it say on your end?
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1101
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Linux Mint is funded by ads and donations.
 

Re: Am I way off?

Postby tpprynn on Sun Nov 13, 2011 9:40 am

Apologies, but I've given up on this. I have been 'so close' to solving it several times since 2008. It is a small matter of course - no problem with my video chip or wireless like many have - but maybe it was the smallness of the issue that made it so niggling and irritating, and I have an illness that means it is a bit foolish of me and dangerous to over-persevere in the way I have in the last few weeks. Last night I even installed one after the other Debian 6, Kubuntu 11.10 and OpenSuse 11.4 to see if things would be any different. I did also try some debugging practices including the ones described earlier in this thread.

I think it is worth you contacting Corentin about your findings as he could probably improve the asus_laptop module and it would be good to get something out of this even if it doesn't help me. Will you consider this? Maybe just look at his site

http://dev.iksaif.net/projects/acpi4asus

and then maybe email him and show him the link to this thread or send your script to him? In the Linux Mint spirit of things.

As I may have said, I've just been given some money I wasn't expecting, and don't we all know what a treat it is to have a new machine... That's what I'm doing, and as I type, on my Kubuntu desktop pc, Vista is being reinstalled on the Toshiba, with a prospective new owner in mind. Hopefully I won't have issues with the new laptop (and Mint 12 when it's out)... It is not that I'm selling the laptop over a small LED issue, this has just coincided with the chance of replacing a machine that has had a lot of use in four years.

But I have become intrigued about scripting as a result of this thread and have returned to an idea for something I'm going to work on and use as a motivation for more learning, maybe it could be interesting to share here later. In brief, I'm hoping to write a script that looks for bluetooth devices and shows on my screen when I boot up in the morning if a neighbour's phone's ID via bluetooth isn't found. No, it's not to spy or do anything bad! I play the guitar and do home recording of music and would like to reserve times when the neighbour is out to do this, although her poor often abandoned dog's barking is much worse than my guitar. So it's using technology to do something socially responsible, even if it does sound a bit off and odd at first. If the project proves irresistible to anyone else I'm not going to stand in their way.

Thanks for your help. And of course one of you three now has a working LED as a result (five minutes more battery life?) so it's 'win-win' even if I've copped out.

(All the same I'm slightly annoyed with myself that I had already wiped the Toshiba before I saw your latest post...)
tpprynn
Level 3
Level 3
 
Posts: 145
Joined: Fri May 27, 2011 7:09 pm

Re: Am I way off?

Postby Pilosopong Tasyo on Sun Nov 13, 2011 9:28 pm

Well, if it's of any consolation, at least you got a new laptop to replace that problematic one :mrgreen:

I sent an e-mail to Corentin and gave the link to this thread. Good luck on the new laptop! :D
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1101
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Am I way off?

Postby Pilosopong Tasyo on Mon Dec 26, 2011 9:37 am

Lee, I received your PM earlier but can't reply back. The forum software said you disabled receipt of private messages :?: So, I'll just respond here for everyone's benefit. :)

-----

:!: UPDATE :!:

Corentin replied on the same day as that on my previous post (Nov. 14). Unfortunately, I wasn't able to write the results back here due to the circumstances surrounding the thread back then. Anyway, it's about time this gets addressed.

He (Corentin) mentioned about using the NetworkManager infrastructure (/etc/NetworkManager/dispatcher.d/) to implement tpprynn's goal. Looking at the contents of the dispatcher.d directory, there is a script named 01ifupdown. Upon examination of the script's contents, I understood what needed to be added in order to make it work:

To turn ON the LED:
Code: Select all
if [ "$IFACE" = "wlan0" ]
then
  echo "1" > /sys/devices/platform/asus_laptop/wlan
fi

To turn OFF the LED:
Code: Select all
if [ "$IFACE" = "wlan0" ]
then
  echo "0" > /sys/devices/platform/asus_laptop/wlan
fi

The code fragments above are to be inserted at key points in the 01ifupdown script. Press Alt+F2 to bring up the Run Application box and enter:

Code: Select all
gksudo gedit /etc/NetworkManager/dispatcher.d/01ifupdown

I'm using Mint 9 as of this writing, so the code fragments below are based on what's written in my installation of 01ifupdown.

Between lines 22-24 in the original 01ifupdown:
Code: Select all
...
export PHASE="up"

##### Insert the code fragment to turn ON the LED here #####

if [ -d /var/run/network/ ] ; then
...

Between lines 37-39 in the original 01ifupdown:
Code: Select all
...
export PHASE="down"

##### Insert the code fragment to turn OFF the LED here #####

if [ -e /var/run/network/ifstate ] ; then
...

Save the modified script. The effect should be immediate. Turn OFF wireless and the corresponding LED should turn off. And vice-versa. The hacks posted in the previous page are no longer necessary since the above changes already suffice.

HTH.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1101
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Am I way off?

Postby tpprynn on Mon Dec 26, 2011 2:05 pm

This is looking great, but the file is different in Mint 12 enough that I'm unsure. Where would it go in this? I think it looks like we're done then, that'll be amazing. Thanks for getting back to me and if you're able to help with this hopefully last step.

#!/bin/sh -e
# Script to dispatch NetworkManager events
#
# Runs ifupdown scripts when NetworkManager fiddles with interfaces.
# See NetworkManager(8) for further documentation of the dispatcher events.

if [ -z "$1" ]; then
echo "$0: called with no interface" 1>&2
exit 1;
fi

# Fake ifupdown environment
export IFACE="$1"
export LOGICAL="$1"
export ADDRFAM="NetworkManager"
export METHOD="NetworkManager"
export VERBOSITY="0"

# Run the right scripts
case "$2" in
up|vpn-up)
export MODE="start"
export PHASE="post-up"
exec run-parts /etc/network/if-up.d
;;
down|vpn-down)
export MODE="stop"
export PHASE="post-down"
exec run-parts /etc/network/if-post-down.d
;;
hostname)
# do nothing here, the 'hostname' action is not handled by ifupdown scripts.
exit 0
;;
# pre-up/pre-down not implemented. See
# https://bugzilla.gnome.org/show_bug.cgi?id=387832
# pre-up)
# export MODE="start"
# export PHASE="pre-up"
# exec run-parts /etc/network/if-pre-up.d
# ;;
# pre-down)
# export MODE="stop"
# export PHASE="pre-down"
# exec run-parts /etc/network/if-down.d
# ;;
hostname|dhcp4-change|dhcp6-change)
# Do nothing
;;
*)
echo "$0: called with unknown action \`$2'" 1>&2
exit 1
;;
esac
tpprynn
Level 3
Level 3
 
Posts: 145
Joined: Fri May 27, 2011 7:09 pm

Re: Am I way off?

Postby Pilosopong Tasyo on Mon Dec 26, 2011 8:00 pm

Ah, I see what you mean. They are indeed slightly different, although logically the additions should be the same. The portion where you are going to insert the two code fragments are marked in color:

...
export PHASE="post-up"
##### Insert the code fragment to turn ON the LED here #####
exec run-parts /etc/network/if-up.d
...
export PHASE="post-down"
##### Insert the code fragment to turn OFF the LED here #####
exec run-parts /etc/network/if-post-down.d
...

Don't forget to make a backup copy of the original 01ifupdown script before you make changes. Copy the original in a convenient location, say, /root (superuser's home directory).

HTH.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1101
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Am I way off?

Postby tpprynn on Tue Dec 27, 2011 5:34 am

I'd liked to have added a 'Solved' here but though it seems the job's nearly done, what happens on my laptop is as with your previous script. With the 01ifupdown file altered as suggested the wireless itself disconnects as soon as it connects, and then it reconnects again in a loop of this process. Unlike with your own script though the LED is on at boot whether or not the wireless is. Corentin did give me a kernel parameter to use in /etc/default/grub but I've lost my little folder with all our emails in, though maybe it's not now necessary. Something with acpi and dst in. Damn my filing skills...

I'm away until about the 3rd of January, without my laptop, but will get back to this myself when I'm home. I'm not going to give up this time and I'll be pleased if you or anyone has any ideas.

Thanks.
tpprynn
Level 3
Level 3
 
Posts: 145
Joined: Fri May 27, 2011 7:09 pm

Re: Am I way off?

Postby Pilosopong Tasyo on Wed Dec 28, 2011 12:01 am

Hmm, it's puzzling that this fix doesn't work as expected on your end. I don't have an idea why it would exhibit that kind of behavior. At first, I thought perhaps repositioning the fix between the exec and ;; lines would do it. Then I remembered it will never work since the exec line will never return to the originating script. The other possible fix was to adapt your original post:

Code: Select all
STATUS="$2"
LED_FILE="/sys/devices/platform/asus_laptop/wlan"

if [ "$IFACE" = "wlan0" -a "$STATUS" = "up" ]
then
  echo "1" > $LED_FILE
elif [ "$IFACE" = "wlan0" -a "$STATUS" = "down" ]
then
  echo "0" >  $LED_FILE
fi

and insert the above between:

Code: Select all
export VERBOSITY="0"

# Run the right scripts

That ensures the echoes will only execute if and only if $IFACE is wlan0 and $STATUS is either up or down (vpn-up/vpn-down values skips the if-fi block). I'm not sure it will make any difference, since it's just a variation of the other fix I posted before this one. It's worth a shot though; nothing to lose.

In the event that it still doesn't work, then I'm afraid I'm out of ideas. You mentioned Mint 12. When you started this thread, did you also use Mint 12 or was it an older version? The kernel parameter Corentin gave you may or may not be relevant, but still worth checking out as well.

Good luck!
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1101
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Am I way off?

Postby tpprynn on Thu Dec 29, 2011 6:52 am

Thanks for that. I'll give it a try when I get home. I think I will download Mint 9 again too in case, out of curiosity about whether things will work differently. Otherwise it will be time for a Launchpad bug report, whether or not its hopeful or appropriate.

Thanks for your contributions.
tpprynn
Level 3
Level 3
 
Posts: 145
Joined: Fri May 27, 2011 7:09 pm

Linux Mint is funded by ads and donations.
 
Previous

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests