Turn On-Off Wifi with Atheros and Cron (archer C5/C7)

Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware
Goto page Previous  1, 2, 3, 4, 5  Next
Author Message
cardboardbox
DD-WRT Novice


Joined: 27 Feb 2010
Posts: 22

PostPosted: Wed Jun 29, 2016 20:21    Post subject: Reply with quote
jwoods wrote:
Put the text value of the variable in quotes...

nvram set ath1_net_mode="disabled"

nvram set ath1_net_mode="ac-only"

https://www.dd-wrt.com/wiki/index.php/Hardware#NVRAM

There is no acn-only...there is acn-mixed and ac-only.
ah, that works! Thanks!

For ath0, the wireless network mode in the GUI is NG-Mixed but if I telnet and nvram show | grep ath0_net_mode it returns ng-only. So I guess I just assumed for AC/N-Mixed, the command would be acn-only following the ath0 pattern.

I think I'll just do ac-only as you suggested.
Sponsor
jwoods
DD-WRT User


Joined: 13 Mar 2016
Posts: 403

PostPosted: Thu Jun 30, 2016 1:05    Post subject: Reply with quote
cardboardbox wrote:
jwoods wrote:
Put the text value of the variable in quotes...

nvram set ath1_net_mode="disabled"

nvram set ath1_net_mode="ac-only"

https://www.dd-wrt.com/wiki/index.php/Hardware#NVRAM

There is no acn-only...there is acn-mixed and ac-only.
ah, that works! Thanks!

For ath0, the wireless network mode in the GUI is NG-Mixed but if I telnet and nvram show | grep ath0_net_mode it returns ng-only. So I guess I just assumed for AC/N-Mixed, the command would be acn-only following the ath0 pattern.

I think I'll just do ac-only as you suggested.


I just picked the closest match to what you were originally trying to use.

I personally use AC/N-Mixed ("acn-mixed")...it seems to be the most stable for my 5 Ghz connection.
plazma
DD-WRT User


Joined: 22 Feb 2012
Posts: 68

PostPosted: Sun Jul 03, 2016 22:06    Post subject: Reply with quote
cardboardbox wrote:
Thanks for the help in this thread. This might be a dumb question but I keep thinking about it... Does turning the radio on and off daily and adjusting TX Power eventually wear out the router faster than if we never changed these settings?


Sorry for the delayed response.

I dont really think so, many devices turn off wifi modules to save power, think your phone, laptop, etc, its a solid state device so the most likely thing to kill it over time is heat, so when the wifi is off (disabled) its likely the chipset runs cooler and hence should last longer... in theory.. in the real world, assuming you dont run the router in crazy ambient temperatures that it would make any real difference what so ever.
yomen9
DD-WRT Novice


Joined: 02 Nov 2016
Posts: 23

PostPosted: Sat Jan 21, 2017 6:04    Post subject: Reply with quote
Hi guys!

I have a Broadcom devices (R8500)

Do you know anyway I could use this kind of script, but tweak it so the router actually disable and re-enable the Wi-Fi immediately after having disabled it, every hours, everyday?

Basically rebooting the Wi-Fi (but not the router), every hours

It would be so much appreciate if you could point me out what kind of script would allow me to do that!

Thanks in advance for any help!!
plazma
DD-WRT User


Joined: 22 Feb 2012
Posts: 68

PostPosted: Sat Jan 21, 2017 8:20    Post subject: Reply with quote
I think you will find on most broadcom units you can use the built in (ddwrt) radio schedual just fine and this script would not be needed.

That said if you change the interface names etc the script in theory could be adapted.
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 10:26    Post subject: Reply with quote
plazma wrote:
I think you will find on most broadcom units you can use the built in (ddwrt) radio schedual just fine and this script would not be needed.

That said if you change the interface names etc the script in theory could be adapted.


I need to run this script. But looks like it doesnt work on my WR1043ND v2. I did everything you said plazma but I need help.

I want to turn on my wifi 10:00-20:00 other hours should be turn off. I send my settings:

statup script:

Code:
# PLAzmA WIFI Schedule Script Version 1.2

# WRITE SCRIPT OUT TO TMP
cat > /tmp/wificheduler.sh << 'EOF'
#!/bin/sh
START=1000
STOP=2000
WIFIMODE=mixed

# IF BOOT HAS NOT COMPLETED DONT RUN
if [ ! -f /tmp/boot_complete ]; then exit 1; fi

# IF TIME IS BEFORE START OR AFTER STOP AND HOSTAPD IS RUNNING, THEN BRING DOWN WIFI
if [ $(date +%H%M) -lt $START ] || [ $(date +%H%M) -gt $STOP ]; then if [ $(ps | grep hostapd | cut -c27-33 | grep -v grep) = hostapd ]; then echo "wifi off">/tmp/wificheduler.status; stopservice wland; nvram set ath0_net_mode=disabled; killall hostapd; mv /tmp/hostap_alive /tmp/hostap_dead; fi; fi

# IF TIME IS AFTER START TIME AND BEFORE END TIME AND WIFI HAS NOT BEEN WOKEN, WAKE IT UP
if [ $(date +%H%M) -gt $START ] && [ $(date +%H%M) -lt $STOP ]; then if [ ! -f /tmp/hostap_alive ]; then echo "wifi  on">/tmp/wificheduler.status; nvram set ath0_net_mode=$WIFIMODE; sleep 10; stopservice lan; startservice lan; mv /tmp/hostap_dead /tmp/hostap_alive; fi; fi
EOF

# SET THE EXECUTE BIT
chmod +x /tmp/wificheduler.sh

# BRING DOWN WIFI ON BOOT
sleep 15
stopservice wland; nvram set ath0_net_mode=disabled; killall hostapd; touch /tmp/hostap_dead; touch /tmp/boot_complete

# DONT FORGET TO ADD THE CRONTAB JOB IN THE GUI (SANS QUOTES) "* * * * * root /bin/sh /tmp/wificheduler.sh"

# TO DEBUG TELNET IN AND RUN (SANS QUOTES) "while true; do cat /tmp/wificheduler.status; sleep 10; done"
# THEN YOU CAN USE "date YYYYMMDDHHMM" IN ANOTHER SESSION TO QUICKLY ADJUST TIME.
# NOTE: wificheduler.status IS TOGGLED AS THE COMMAND STARTS TO RUN AND
# hostapd_(status) IS TOGGLED AT THE END OF THE RUN.
# THUS IT ALLOWS YOU TO DEBUG IF SOMETHING GETS STUCK BY COMPARING THE TWO.

# CHANGE LOG:
# 1.2 ADDED DEBUG, PREVENT CRON SCHEDULE RUN UNTIL BOOT ENDS AND
# ENSURED SCRIPT WOULD STILL RUN IF /tmp BECOMES FULL
# 1.1 CHANGE TO USE SERVICE LAN FOR QUICKER RESTART


Cron tab :

Code:
* * * * * root /bin/sh /tmp/wificheduler.sh


ifconfig results:

Quote:
ath0 Link encap:Ethernet HWaddr **************
inet addr:172.20.**** Bcast:172.20.**** Mask:255.255.255.240
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8633 errors:0 dropped:0 overruns:0 frame:0
TX packets:5833 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3355526 (3.1 MiB) TX bytes:1134938 (1.0 MiB)
ath0.1 Link encap:Ethernet HWaddr ******************
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:797 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:105267 (102.7 KiB)
br0 Link encap:Ethernet HWaddr ***********************
inet addr:************** Bcast:************* Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10255 errors:0 dropped:33 overruns:0 frame:0
TX packets:12177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:903992 (882.8 KiB) TX bytes:9430912 (8.9 MiB)
br0:0 Link encap:Ethernet HWaddr *******************
inet addr:169.254.255.1 Bcast:169.254.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0 Link encap:Ethernet HWaddr *********************
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:939 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:123885 (120.9 KiB)
Interrupt:4
eth1 Link encap:Ethernet HWaddr **********************
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10460 errors:0 dropped:50 overruns:0 frame:0
TX packets:12177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1083982 (1.0 MiB) TX bytes:9430912 (8.9 MiB)
Interrupt:5
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MULTICAST MTU:65536 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:592 (592.0 B) TX bytes:592 (592.0 B)
tap1 Link encap:Ethernet HWaddr ****************
inet addr:*********************** Bcast:************** Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8335 errors:0 dropped:120 overruns:0 frame:0
TX packets:5662 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2719368 (2.5 MiB) TX bytes:572264 (558.8 KiB)

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 10:51    Post subject: Reply with quote
jean019 your code is working for me but looks like my wireless bridge cannot restore after wifi on.

Normal condition (Wifi - On)

Code:
ath0 Link encap:Ethernet HWaddr **************
inet addr:172.20.**** Bcast:172.20.**** Mask:255.255.255.240
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8633 errors:0 dropped:0 overruns:0 frame:0
TX packets:5833 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3355526 (3.1 MiB) TX bytes:1134938 (1.0 MiB)


It gets IP from Remote Wife (This router is wireless client)

I manually triger turn of wife with this: /tmp/custom.sh wifioff

Then I turn on wifi with this : /tmp/custom.sh wifion

Now my ath0 can not restore the wireless bridge. I tried to connect this router to my iPhone Personal Hotspot. IT looks like connected (I see blue band on top) but ifconfig shows no IP after turn on:

Code:
ath0      Link encap:Ethernet  HWaddr ************** 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:81 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:10234 (9.9 KiB)  TX bytes:421 (421.0 B)

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
plazma
DD-WRT User


Joined: 22 Feb 2012
Posts: 68

PostPosted: Thu Jun 01, 2017 12:40    Post subject: Reply with quote
The issue with the original script noting coming back up was why i ended up creating my own, also the bigger advantage of my code is it ensures if the router gets rebooted it downs the wifi in the appropriate off period should the reboot happen part of the way though the period.

Although the 841 router i wrote this for was similar to the 1043 it should also work, although ive not tested and i forget where my v1 1043 router went to... i think i maybe installed it some place... i forget.

I see you have a real AP and a virtual AP, anyway you have not stated what your trying to do with the radio scheduled.. are you trying to turn off just the guest network? or both?

I would forget about the guest network for the second, save your nvram out to a backup file and then get the script working first on the router without the virtual ap.

Secondary it appears in your copy paste that your setting the mode as mixed, where as in your screen shot your showing ng-mixed, so i would also adjust which ever one appropriately to your situation, requirement.

You can also telnet/ssh into the router over CAT5 and issue the commands from the script manually and one at a time, observe what happens, this is going to tell you exactly what part is failing for you.
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 12:51    Post subject: Reply with quote
Thank you very much for fast response plazma! I appreicated. Let me explain my case:

I have ath0 and ath0.1 (virtual)

ath0 is important lets focus on this. as you can see ath0 is Wireless Client not AP. It connects to my iPhone Personal Hotspot.

Your script looks great but I need to know how to debug for my case. I am not make sure my cron is working or not. I need simple code just testing cron. Second you said run script manually one a time but how? I guest start and stop time is correct 1000 and 2000 it is not second or internal I guess. Based on 24 hours. But your script has if clouses so I am not linux expert how can test the conditions one by one. Can you tell me the shell commands that you are used in scripts like /tmp/hostap_alive etc can you make list? I can test one bye one. I need simple cron task just for testing my cron is working or not.

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 12:56    Post subject: Reply with quote
Quote:
root@GARDEN:~# /tmp/boot_complete
-sh: /tmp/boot_complete: not found
root@GARDEN:~#

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
plazma
DD-WRT User


Joined: 22 Feb 2012
Posts: 68

PostPosted: Thu Jun 01, 2017 13:19    Post subject: Reply with quote
I cant see why it would not work in client mode...

However while you are getting it working save the nvram, resetup without the virtual ap and test without it, once you get the scheduled working you can add that back in.

Do you have NTP working/setup ? if so the time is not set so the script probably fire at the times you expect.

you cant just type a file name, the boot complete is just a file flag/holder to check is exists you can use:

ls /tmp/boot_complete

As for checking the script is running, you can monitor the processes list to make sure its being started:

http://www.dd-wrt.com/phpBB2/viewtopic.php?p=680579

Although it runs fairly quickly so it might be hard to see it getting fired each minute...

Instead you probably want to check the tmp folder that the script is being created:

ls /tmp/wificheduler.sh

If its there startup script, you should also then have the boot complete flag:

ls /tmp/boot_complete

Assuming this is there you can then check status of what the script is done by doing:

ls /tmp/hostap*

cat /tmp/wificheduler.status

If you read my FAQ part of my original post i explain how the two above further.

However as i said remove the script for the second try manually issuing the commands over CAT5:

Start commands would be:

nvram set ath0_net_mode=$WIFIMODE
stopservice lan; startservice lan

The two above lines are separate commands and the bottom line needs both, as stopping the service without the start immediately after will see you getting locked out.

Note replace $WIFIMODE with your require mode, as someone else said this may need quote marks, however on the 841 unit i wrote the script for i needed none.

Try setting the ath0_net_mode and then check the nvram to see if its taken.

nvram show ath0_net_mode

Stop would be:

stopservice wland;
nvram set ath0_net_mode=disabled
killall hostapd

Like i said connect over CAT5, remove the virtual ap from the system for the moment, issues the commands manually and check that works and go from there.

Good luck.
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 22:00    Post subject: Reply with quote
Thank you very much for help plazma!

When I started my router there is no wificheduler.status in tmp folder. But I can see wificheduler.sh file


I did adjust for my time zone. Router time is correct. Here is the setting but. Looks like there is a bug 31899 build. I am in GMT+3 but if I choose GMT+3 time is incorrect. If I choose GMT-3 time is correct.

I will follow your directions + debug mode (two session for testing) but something is wrong. Looks like cron is sleeping I guess. Because there is no .status file in tmp but startup script is working. If I manually triger your script its create status file. We should focus cron I guess. What do you think.

Boot complete result:

Code:
root@GARDEN:~# ls /tmp/boot_complete
root@GARDEN:~#

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 22:07    Post subject: Reply with quote
I can not see wficheduler.sh if i run top command

Code:

Mem: 26128K used, 35616K free, 0K shrd, 3384K buff, 9208K cached
CPU:  0.9% usr  1.1% sys  0.0% nic 97.4% idle  0.0% io  0.0% irq  0.3% sirq
Load average: 0.08 0.20 0.27 3/41 2052
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
  929     1 root     S     4212  6.7   0  0.7 httpd -p 80
 1593     1 root     R     3652  5.8   0  0.7 openvpn --config /tmp/openvpncl/o
  792     1 root     S     1844  2.9   0  0.5 hostapd -B -P /var/run/ath0_hosta
    4     2 root     SW       0  0.0   0  0.5 [kworker/0:0]
  988     1 root     S     1972  3.1   0  0.0 ttraff
  794     1 root     S     1844  2.9   0  0.0 wpa_supplicant -B -Dnl80211 -iath
 1081     1 root     S     1764  2.8   0  0.0 resetbutton
  542     1 root     S     1764  2.8   0  0.0 watchdog
 1576     1 root     S     1764  2.8   0  0.0 process_monitor
 1586     1 root     S     1724  2.7   0  0.0 wland
    1     0 root     S     1580  2.5   0  0.0 /sbin/init
 1583     1 root     S     1544  2.4   0  0.0 upnp -D -W ath0
 1579     1 root     S     1428  2.3   0  0.0 inadyn -u --i
  885     1 root     S     1156  1.8   0  0.0 dnsmasq -u root -g root --conf-fi
 1912   849 root     S     1144  1.8   0  0.0 -sh
 2040  1912 root     R     1144  1.8   0  0.0 top
  849     1 root     S     1144  1.8   0  0.0 telnetd
 1916  1915 root     S     1136  1.8   0  0.0 sh -c /usr/libexec/sftp-server
 1595     1 root     S     1136  1.8   0  0.0 udhcpc -i ath0 -p /var/run/udhcpc
^C915   869 root     S     1056  1.7   0  0.0 dropbear -b /tmp/loginprompt -r /
root@GARDEN:~#

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 22:34    Post subject: Reply with quote
Code:
stopservice wland;
nvram set ath0_net_mode=disabled
killall hostapd


these are not stop my wifi in wireless client mode. It looks like radio off (really off) but It still connect to my iphone hotspot (wirelessly). I am sending this message via my iphone hotspot plus wifi radio is off. Sounds weird.

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
mkaand
DD-WRT User


Joined: 06 Jan 2008
Posts: 307
Location: Istanbul

PostPosted: Thu Jun 01, 2017 23:10    Post subject: Reply with quote
Code:
root@GARDEN:~# nvram show | grep ath0_net_mode
ath0_net_mode=ng-only
size: 29498 bytes (36038 left)
    nvram set ath0_net_mode=disabled
    nvram set ath0_net_mode=ng-mixed
root@GARDEN:~#


GUI says NG-Mixed I confused. Above shell results. I believe if I do not use this router as Wireless Client your script will be work perfectly. But Wireless Client a little bit different. I need to solve this problem. If you wish I can give you access for my this router. Thanks.

_________________
Kaan's World | @mkaand | PLEX Archive | Trakt.tv
Goto page Previous  1, 2, 3, 4, 5  Next Display posts from previous:    Page 2 of 5
Post new topic   Reply to topic    DD-WRT 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