TL-WR841N v8 wifi button script

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Atheros WiSOC based Hardware
Author Message
c7rax
DD-WRT Novice


Joined: 09 Nov 2017
Posts: 43

PostPosted: Wed Dec 13, 2017 12:49    Post subject: TL-WR841N v8 wifi button script Reply with quote
r33607 and r33986 has badly support for WiFi button and WiFi led for this device as described in http://svn.dd-wrt.com/ticket/6048.
DD-WRT is managing ses button probably with script according to .sesbutton event which is launched when button is pushed. In my situation there is nothing to push because this device has on/off switch with two positions.
Even without jffs in this router I have decided to create small script to maintain button better.

EDIT: the router has a tendency to run next instance of custom.sh in different occasions, can't figure why. I mean, it launches custom.sh probably by next "startup" event, probably when some other process crashes.
I have noticed it before but didn't figure approach to eliminate it before. So the previous script had instance variable not used anywhere.
Script below should eliminate duplicates of itself. With kill -9 can't it can't kill itself so i just used head, not tail.
Due to some unknown for me specifics, launching custom.sh gives 2 processes, not 1 in the first step. And this is not grep process.

Code:
#!/bin/sh

instance=`ps | grep [c]ustom.sh | awk '{print $1}' | wc -l`
instanceps=`ps | grep [c]ustom.sh | awk '{print $1}' | head -1`
while [ "$instance" -gt "2" ]; do
   kill -9 "$instanceps"
   sleep 2
   instance=`ps | grep [c]ustom.sh | awk '{print $1}' | wc -l`
   instanceps=`ps | grep [c]ustom.sh | awk '{print $1}' | head -1`
done

while true; do
sleep 10
gpio16=`cat /proc/gpio/16_in`
wstatus=`iw ath0 info | grep ssid`

if [ "$gpio16" -ne "0" ] && [ -z "$wstatus" ]; then
   ifconfig ath0 up
   sleep 5
   hostapd -B -P /var/run/ath0_hostapd.pid /tmp/ath0_hostap.conf
   sleep 20
   wstatus=`iw ath0 info | grep ssid`
   if [ -z "$wstatus" ]; then
      ifconfig ath0 down
      sleep 5
      kill -9 `ps | grep [h]ostapd | head -1 | awk '{print $1}'`
   fi
fi
if [ "$gpio16" -eq "0" ] && [ -n "$wstatus" ]; then
   ifconfig ath0 down
   sleep 5
   kill -9 `ps | grep [h]ostapd | head -1 | awk '{print $1}'`
fi
done

At first it seemed that "ifconfig ath0 up" and "ifconfig ath0 down" are enough commands to manage WiFi. But later it appeared that they are not.
"ifconfig ath0 up" after "ifconfig ath0 down" would not rise radio properly - radio was on (at least according to webgui) but the channel (auto mode) wasn't assigned and SSID wasn't transmitted. The second combination of "down/up" for interface would give working Wifi with channel assigned properly but then next issue arose (BTW this time i am using Dynamic 20/40 mode - I don't remember such issues with Fixed 20MHz mode).

After long time of disabled WiFi, none of the devices would reconnect. Devices like laptop or smartphone were able to see my WiFi network as active but weren't able to pass a authorization state.
This is where I added hostapd start stop which solved problem. After a day there wasn't any issue to put down or up the WiFi. Killing hostapd without puting down ath0 interface will make system to restart hostapd by itself, at least in my case. Hostapd needs some time to start so I added 20 seconds sleep.
I know it is simple workaround and it should be put at different level, in dd-wrt code but well ...

I didn't make a fix for WiFi led, it is reversed (off when wifi on, and on when wifi is off) but something is constantly controlling this led so my "gpio disable/enable" are overrided whole time. So I left it in current state.


Last edited by c7rax on Sat Dec 16, 2017 23:37; edited 1 time in total
Sponsor
ian5142
DD-WRT Guru


Joined: 23 Oct 2013
Posts: 2170
Location: Canada

PostPosted: Wed Dec 13, 2017 14:34    Post subject: Wiki Reply with quote
I added it to the wiki here: https://www.dd-wrt.com/wiki/index.php/TP-LINK_TL-WR841ND
_________________
Before asking a question on the forums, update dd-wrt: Where do I download firmware? I suggest reading it all.

Some dd-wrt wiki pages are up to date, others are not. PM me if you find an old one, I am trying to update them.

Atheros:
Netgear R7800 - gateway, DHCP, QoS, VPN
TP-Link Archer C7 v2 x2 - WDS AP, WDS Station
TP-Link TL-WDR3600 v1 - WDS Station
TP-Link 841nd v8 - WDS Station
D-Link 615 C1 x 4 - not used
D-Link 615 E3 x 2 - not used
D-Link 825 B1 - WDS Station
D-Link 862L A1 x2 - WDS Station
Netgear WNDR3700v2 - WDS Station
UBNT loco M2 x2 - airOS

Broadcom
Asus N66U - backup Gateway
Netgear r6300 v1 - AP
Linksys E2500 - not used
Linksys EA2700 - not used
Linksys 160N v3 x2 - not used
Netgear WNDR3700v3 - not used
MediaTek
UBNT EdgeRouter X - not used
c7rax
DD-WRT Novice


Joined: 09 Nov 2017
Posts: 43

PostPosted: Sat Dec 16, 2017 23:43    Post subject: Reply with quote
Script updated to eliminate duplicates.
Duplicates can make enabling/disabling wifi to not work.
ian5142
DD-WRT Guru


Joined: 23 Oct 2013
Posts: 2170
Location: Canada

PostPosted: Sun Dec 17, 2017 0:55    Post subject: Wiki updated Reply with quote
I have updated the wiki with your script.
_________________
Before asking a question on the forums, update dd-wrt: Where do I download firmware? I suggest reading it all.

Some dd-wrt wiki pages are up to date, others are not. PM me if you find an old one, I am trying to update them.

Atheros:
Netgear R7800 - gateway, DHCP, QoS, VPN
TP-Link Archer C7 v2 x2 - WDS AP, WDS Station
TP-Link TL-WDR3600 v1 - WDS Station
TP-Link 841nd v8 - WDS Station
D-Link 615 C1 x 4 - not used
D-Link 615 E3 x 2 - not used
D-Link 825 B1 - WDS Station
D-Link 862L A1 x2 - WDS Station
Netgear WNDR3700v2 - WDS Station
UBNT loco M2 x2 - airOS

Broadcom
Asus N66U - backup Gateway
Netgear r6300 v1 - AP
Linksys E2500 - not used
Linksys EA2700 - not used
Linksys 160N v3 x2 - not used
Netgear WNDR3700v3 - not used
MediaTek
UBNT EdgeRouter X - not used
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum