TP-Link Archer C9 GPIO pins

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Sat Nov 21, 2015 22:41    Post subject: TP-Link Archer C9 GPIO pins Reply with quote
I started tinkering about with the GPIO pins as an experiment.
I gather the layout is something like:
gpio 1 - Ethernet
gpio 2 - WPS
gpio 3 - RESET (input - warning!!)
gpio 4 - WLAN 2.4Ghz
gpio 5 - WLAN 5.0Ghz
gpio 6 - USB (RHS)
gpio 7 - USB (LHS)

I wrote a script that will correctly display the WLAN LEDs - dependent on whether the WLAN is really on or off, e.g. for 2.4Ghz:
Code:
#!/bin/sh

wlan_led()
{
   wlan_device=$1
   led_gpio_pin=$2

   gpio disable ${led_gpio_pin}
   wlan_status=0
   while sleep 2; do
      previous_wlan_status=${wlan_status}
      wlan_mode=$( nvram get "${wlan_device}_net_mode" )
      wlan_radio=$( nvram get "${wlan_device}_radio" )
      wlan_status=1
      if [[ "${wlan_mode}" == "disabled" ]] || [[ ${wlan_radio} == 0 ]]; then
         wlan_status=0
      fi
      if [ ${wlan_status} -eq 0 ]; then
         gpio disable ${led_gpio_pin}
      elif [ ${wlan_status} -ne ${previous_wlan_status} ]; then
         gpio enable ${led_gpio_pin}
      fi
   done
}

wlan_led "wl0" 4


Despite my "extensive knowledge" garnered from using Gentoo Desktop Linux (i.e. not Android or DOS)...
Both ip and ifconfig are slightly odd/striped down BusyBox versions of the tools I'm used to using! Items I would use - like the carrier field - are disabled... Confused

I just can't figure out a way of seeing if any of the 4 wired Ethernet LAN ports are physically connected... It would be nice to figure this out to control the LAN LED (which is currently ignored). Cool

From:
Simplified wrt54g block diagram
It looks like testing for packet transfer activity on VLAN1 would be the only way to check whether any of the LAN ports is connected...

Any thoughts? Is there a better / more reliable way to do this?


Ta
Bob
Sponsor
takeahike
DD-WRT User


Joined: 21 Apr 2016
Posts: 67

PostPosted: Tue May 03, 2016 0:25    Post subject: Archer C9 ethernet led Reply with quote
This worked for me! I logged into telnet and ran the script and then typed 'gpio enable 1' and the ethernet led came on! I was looking everywhere to try and get this led on, since it went off after flashing with DD-WRT (was on with stock firmware). Got rest of lights on--see original post to control all lights, including WPS.


router_lights_shrunk.JPG
 Description:
 Filesize:  105.19 KB
 Viewed:  8183 Time(s)

router_lights_shrunk.JPG




Last edited by takeahike on Sun Jun 19, 2016 22:22; edited 2 times in total
wirelesskebab
DD-WRT Novice


Joined: 12 Apr 2016
Posts: 33

PostPosted: Tue May 03, 2016 4:30    Post subject: Re: Archer C9 ethernet led Reply with quote
takeahike wrote:
This worked for me! I logged into telnet and ran the script and then typed 'gpio enable 1' and the ethernet led came on! I was looking everywhere to try and get this led on, since it went off after flashing with DD-WRT (was on with stock firmware).


Fascinating, does it turn off if you disconnect the cat cord? Wink
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Tue May 03, 2016 16:00    Post subject: Re: Archer C9 ethernet led Reply with quote
wirelesskebab wrote:

Fascinating, does it turn off if you disconnect the cat cord? Wink


I have to confess that it's so long since I wrote my little script can't remember... I think I updated it a bit with activity levels for the Wi-Fi channels, etc... I'm away on holiday just now- so I can't easily check!
Cool

Bob
takeahike
DD-WRT User


Joined: 21 Apr 2016
Posts: 67

PostPosted: Tue May 03, 2016 20:57    Post subject: Re: Archer C9 ethernet led Reply with quote
wirelesskebab wrote:
takeahike wrote:
This worked for me! I logged into telnet and ran the script and then typed 'gpio enable 1' and the ethernet led came on! I was looking everywhere to try and get this led on, since it went off after flashing with DD-WRT (was on with stock firmware).

Fascinating, does it turn off if you disconnect the cat cord?

No.
takeahike
DD-WRT User


Joined: 21 Apr 2016
Posts: 67

PostPosted: Mon May 09, 2016 3:02    Post subject: Re: Archer C9 ethernet led Reply with quote
takeahike wrote:
This worked for me! I logged into telnet and ran the script and then typed 'gpio enable 1' and the ethernet led came on! I was looking everywhere to try and get this led on, since it went off after flashing with DD-WRT (was on with stock firmware).

If you want the WPS light on as well just follow the procedure above and type 'gpio enable 2.' I've found that playing with gpio can cause you to lose your connection if you play with number 3 (see warning in original post). No big deal--the router will just re-boot.
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Sat May 14, 2016 13:54    Post subject: Reply with quote
Finally back home. So I checked what my current Archer C9 scripts are. I'll post them in 2 blocks - yup they've got a bit of feature creep Razz
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Sat May 14, 2016 14:03    Post subject: Reply with quote
LAN LED

This is really just a hack that turns off the LAN LED on extremely low network activity. I can't really be bothered to dig about to find out if there's a way to directly access the ethernet driver status (i.e. to find if a cable is physically plugged or not).

You get a nice flashing light - where the flashing speed increases - as your network activity level increases... Cool



lan_led.startup
Code:
#! /bin/sh

lan_device="vlan1"
led_gpio_pin=1

usecond=1000000
low_pwm=$((usecond/32))
ucycle_time=5000000

idle_tx_rx=$((1024*(ucycle_time/usecond)/8))    # 1kbit/s
low_tx_rx=$((10*idle_tx_rx))                                    # 10kbit/s
medimum_tx_rx=$((10*low_tx_rx))                                 # 100kbit/s
high_tx_rx=$((10*medimum_tx_rx))                                # 1Mbit/s
vhigh_tx_rx=$((10*high_tx_rx))                                  # 10Mbit/s
extreme_tx_rx=$((10*vhigh_tx_rx))                               # 100Mbit/s

while [ true ]; do
        previous_total_bytes=${total_bytes:-}
        total_bytes=$( ifconfig ${lan_device} | awk -F '(TX|RX) bytes\:' '{ if (NF == 3) { gsub(/ \([\.\ [:alnum:]]+\)/, ""); print $2+$3 } }' )
        if [[ "${previous_total_bytes}" == "" ]]; then
                delta_bytes=0
        else
                delta_bytes=$( echo "${previous_total_bytes} ${total_bytes}" | awk '{ print $2-$1 }' )
        fi
        if [ ${delta_bytes} -gt ${extreme_tx_rx} ]; then
                uinterval=$((usecond/64))
        elif [ ${delta_bytes} -gt ${vhigh_tx_rx} ]; then
                uinterval=$((usecond/32))
        elif [ ${delta_bytes} -gt ${high_tx_rx} ]; then
                uinterval=$((usecond/16))
        elif [ ${delta_bytes} -gt ${medimum_tx_rx} ]; then
                uinterval=$((usecond/8))
        elif [ ${delta_bytes} -gt ${low_tx_rx} ]; then
                uinterval=$((usecond/4))
        elif [ ${delta_bytes} -gt ${idle_tx_rx} ]; then
                uinterval=$((usecond/2))
        else
                gpio disable ${led_gpio_pin}
                usleep ${ucycle_time}
                continue
        fi
        led_on=1
        count_down=${ucycle_time}
        while [[ ${count_down} -gt 0 ]]; do
                if [[ ${led_on} -eq 1 ]]; then
                        gpio enable ${led_gpio_pin}
                        usleep ${uinterval}
                        count_down=$((count_down-uinterval))
                else
                        gpio disable ${led_gpio_pin}
                        usleep ${low_pwm}
                        count_down=$((count_down-low_pwm))
                fi
                led_on=$((1-led_on))
        done
done
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Sat May 14, 2016 14:13    Post subject: Reply with quote
WLAN LEDS

The wlan_led script tests both if the radios are disabled/enabled and also whether the radios are turned off/on (i.e. a radio needs to be enabled and turned on to be "really" on - go figure).

You get nice flashing LEDS - for your WLAN network activity... The flashing frequency is again dependent on the activity level of the WLAN band (as per the LAN script above).


wlan_led.sh
Code:
#!/bin/sh

wlan_device=$1
led_gpio_pin=$2
virtual_wlan_device=$( nvram get "${wlan_device}_ifname" )

gpio disable ${led_gpio_pin}
wlan_enabled=0
while sleep 2; do
        prev_wlan_enabled=${wlan_enabled}
        wlan_mode=$( nvram get "${wlan_device}_net_mode" )
        wlan_status=$( wl -i ${virtual_wlan_device} radio )
        wlan_status=$(( ${wlan_status} & 0x0001 ))
        if [[ "${wlan_mode}" == "disabled" ]] || [[ ${wlan_status} == 1 ]]; then
                wlan_enabled=0
        else
                wlan_enabled=1
        fi
        if [ ${wlan_enabled} -eq 0 ]; then
                gpio disable ${led_gpio_pin}
        elif [ ${wlan_enabled} -ne ${prev_wlan_enabled} ]; then
                gpio enable ${led_gpio_pin}
        fi
done



wlan0_led.startup
Code:
#!/bin/sh

/jffs/etc/config/wlan_led.sh "wl0" 4



wlan1_led.startup
Code:
#!/bin/sh

/jffs/etc/config/wlan_led.sh "wl1" 5
takeahike
DD-WRT User


Joined: 21 Apr 2016
Posts: 67

PostPosted: Sun May 15, 2016 3:30    Post subject: Error with wireless led script Reply with quote
Got the following errors running wireless script. Also, when I run the lan led script it affects the light but it doesn't return to the telnet prompt at the end.


C9_errors.jpg
 Description:
 Filesize:  77.54 KB
 Viewed:  8519 Time(s)

C9_errors.jpg


bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Sun May 15, 2016 4:33    Post subject: Re: Error with wireless led script Reply with quote
takeahike wrote:
Got the following errors running wireless script. Also, when I run the lan led script it affects the light but it doesn't return to the telnet prompt at the end.


The name of each script file is in bold before the code contents.

The .startup scripts will auto start each time you boot (although that's the theory - because my dd-wrt installation has a habit of partially wiping them, from the jffs storage, during a reboot sometimes??!!)

To start them manually you have to run each .startup script as a background process...
Code:
sh *.startup &

should do the the trick...
batagy
DD-WRT Novice


Joined: 23 Dec 2018
Posts: 4

PostPosted: Sun Dec 23, 2018 23:09    Post subject: Reply with quote
bobwya wrote:
[color=darkblue]WLAN LEDS

The wlan_led script tests both if the radios are disabled/enabled and also whether the radios are turned off/on (i.e. a radio needs to be enabled and turned on to be "really" on - go figure).



Hi!

Will this script work on TP-Link Archer C7 V4?
I'd want my Wifi LEDs just to lit continuously if radios are turned on or off, instead of blinking for activity.

Thanks indeed!
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Mon Dec 24, 2018 12:29    Post subject: Reply with quote
batagy wrote:


Hi!

Will this script work on TP-Link Archer C7 V4?
I'd want my Wifi LEDs just to lit continuously if radios are turned on or off, instead of blinking for activity.

Thanks indeed!


Yeah, the script will work on any TP-Link router, where the LEDs are wired up to the GPIO pins.

To not flash the LEDs on activity you'd just do something like:
Code:
wlan_led.sh
Code:   
#!/bin/sh

wlan_device=$1
led_gpio_pin=$2
virtual_wlan_device=$( nvram get "${wlan_device}_ifname" )

gpio disable ${led_gpio_pin}
wlan_enabled=0
while sleep 2; do
        wlan_mode=$( nvram get "${wlan_device}_net_mode" )
        wlan_status=$( wl -i ${virtual_wlan_device} radio )
        wlan_status=$(( ${wlan_status} & 0x0001 ))
        if [[ "${wlan_mode}" == "disabled" ]] || [[ ${wlan_status} == 1 ]]; then
                wlan_enabled=0
        else
                wlan_enabled=1
        fi
        if [ ${wlan_enabled} -eq 0 ]; then
                gpio disable ${led_gpio_pin}
        else
                gpio enable ${led_gpio_pin}
        fi
done


Obviously the GPIO pin numbering may differ between TP-Link devices. You have been warned!

Bob
batagy
DD-WRT Novice


Joined: 23 Dec 2018
Posts: 4

PostPosted: Tue Dec 25, 2018 21:32    Post subject: Reply with quote
bobwya wrote:
Obviously the GPIO pin numbering may differ between TP-Link devices. You have been warned!

Bob

Hi Bob,
Many thanks.
I was brave enough and actually now tried some pin numbers with gpio command directly before applying the script. But below commands didn't work for me on C7 V4:
gpio enable 4
gpio enable 5
gpio enable 9
gpio enable 33

(Last two tips were only idea from info at https://github.com/lede-project/source/blob/master/target/linux/ar71xx/files/arch/mips/ath79/mach-archer-c7-v4.c page, I don't have a clue if those values in code are actually pin numbers or not.)

Anyway these numbers didn't work for me on C7 V4.

Do you use the WPS button on your router to turn on/off the wifi radio? Is it working for you?
For me the button is not doing any activity. I have these settings:
Administration -> Reset Button: Enable (was default)
Services -> SES / AOSS / EZ-SETUP / WPS Button -> Turning off radio: Enable.

I read on various topics that it doesn't work for many.

Thanks
bobwya
DD-WRT Novice


Joined: 19 Nov 2015
Posts: 12

PostPosted: Wed Dec 26, 2018 11:08    Post subject: Reply with quote
batagy wrote:
bobwya wrote:
Obviously the GPIO pin numbering may differ between TP-Link devices. You have been warned!

Bob

Hi Bob,
Many thanks.
I was brave enough and actually now tried some pin numbers with gpio command directly before applying the script. But below commands didn't work for me on C7 V4:
gpio enable 4
gpio enable 5
gpio enable 9
gpio enable 33

(Last two tips were only idea from info at https://github.com/lede-project/source/blob/master/target/linux/ar71xx/files/arch/mips/ath79/mach-archer-c7-v4.c page, I don't have a clue if those values in code are actually pin numbers or not.)

Anyway these numbers didn't work for me on C7 V4.


If you poking about trying to find the GPIO pins for the LED, then you are looking at the right file. But you obviously would use this block (a bit lower down in the file):
Code:
#define ARCHER_C7_74HC_GPIO_BASE   32
#define ARCHER_C7_GPIO_LED_WPS      (ARCHER_C7_74HC_GPIO_BASE + 0)
#define ARCHER_C7_GPIO_LED_LAN1      (ARCHER_C7_74HC_GPIO_BASE + 1)
#define ARCHER_C7_GPIO_LED_LAN2      (ARCHER_C7_74HC_GPIO_BASE + 2)
#define ARCHER_C7_GPIO_LED_LAN3      (ARCHER_C7_74HC_GPIO_BASE + 3)
#define ARCHER_C7_GPIO_LED_LAN4      (ARCHER_C7_74HC_GPIO_BASE + 4)
#define ARCHER_C7_GPIO_LED_WAN_GREEN   (ARCHER_C7_74HC_GPIO_BASE + 5)
#define ARCHER_C7_GPIO_LED_WAN_AMBER   (ARCHER_C7_74HC_GPIO_BASE + 6)
#define ARCHER_C7_GPIO_LED_WLAN2   (ARCHER_C7_74HC_GPIO_BASE + 7)

I.e. GPIO pins 32-39.

batagy wrote:

Do you use the WPS button on your router to turn on/off the wifi radio? Is it working for you?
For me the button is not doing any activity. I have these settings:
Administration -> Reset Button: Enable (was default)
Services -> SES / AOSS / EZ-SETUP / WPS Button -> Turning off radio: Enable.

I read on various topics that it doesn't work for many.

Thanks


I recall that the WPS button just crashed dd-wrt and didn't allow me to toggle the WiFi radios.

Anyway at present, I'm not using my Archer C9. It bricked after a routine update. Quite frankly I can't be bothered with that hassle... I.e. if I have to hook up my USB->serial connector, to fix the device, on every update... I'd personally rather just use a cheap commodity x86 board, running pfsense.

Bob
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC 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 can attach files in this forum
You can download files in this forum