Signal strength and 4G LEDs on TP-Link MR200

Hi everyone,

I recently installed OpenWrt on my TP-Link Archer MR200, which had a very limited ISP-customized firmware. Everything worked after installing OpenWrt but the signal strength and the 4g LEDs.

MR200's LTE modem is connected via USB, has its own IP address (192.168.225.1) and GUI. As shown below, there doesn't seem to be any trigger for either the signal strength or the establishment of a 4g connection that could be associated with these LEDs

root@OpenWrt:~# cat /sys/class/leds/mr200\:white\:4g/trigger
none switch0 timer [default-on] netdev phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt
root@OpenWrt:~#

After doing some research I've found out that the status of the modem can be retrieved from the HTTP server in the modem. I have then written the following script that I've added in my /etc/rc.local file, which obtains the status of the modem and updates the state of these LEDs every 5 seconds. Note: it requires the real wget binary from wget package, rather than the tiny version in uclient-fetch package.

change_led() {
    echo "$2" > /sys/class/leds/mr200\:white\:$1/trigger
}

led_on() {
    change_led $1 "default-on"
}

led_off() {
    change_led $1 "none"
}

update_led_status() {
    $(wget --post-data='{"module":"status","action":0}' http://192.168.225.1/cgi-bin/qcmap_web_cgi -O -  -q \
        | jsonfilter -e 'SIGNALSTRENGTH=@.wan.signalStrength' -e 'NETWORKTYPE=@.wan.networkType')

    case $SIGNALSTRENGTH in
        "0;")
            led_off signal1
            led_off signal2
            led_off signal3
            led_off signal4
            ;;
        "1;")
            led_on signal1
            led_off signal2
            led_off signal3
            led_off signal4
            ;;
        "2;")
            led_on signal1
            led_on signal2
            led_off signal3
            led_off signal4
            ;;
        "3;")
            led_on signal1
            led_on signal2
            led_on signal3
            led_off signal4
            ;;
        "4;")
            led_on signal1
            led_on signal2
            led_on signal3
            led_on signal4
            ;;
    esac

    case $NETWORKTYPE in
        "3;")
            led_on 4g
            ;;
        *)
            led_off 4g
            ;;
    esac
}

led_status_loop() {
    while sleep 5; do
        update_led_status
    done
}

led_status_loop &

This solution works perfectly for me but I was wondering if there is a better way of doing this. If not, I wonder if this is something that could be added in a package.

Thanks!

Hi,

I just changed your script, so leds are only written when there is change in signal or 4g status.
Also using curl. Hopefuly I didnt make mistakes :slight_smile:

root@router:~# cat /etc/rc.local 
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/root/bin/led.sh >/dev/null

exit 0
root@router:~# cat /root/bin/led.sh 
#!/bin/sh

eval hash_LED_signal1=none
eval hash_LED_signal2=none
eval hash_LED_signal3=none
eval hash_LED_signal4=none
eval hash_LED_4g=none

change_led() {

#    echo debug: change_led "$1" "$2"

    echo "$2" > /sys/class/leds/mr200\:white\:$1/trigger
}

led_on() {

  export key=LED_$1

  if [ $(eval "echo \$hash_$key") != "default-on" ]; then

    change_led $1 "default-on"
    eval hash_$key="default-on"

  fi
}

led_off() {

  export key=LED_$1                                     

  if [ $(eval "echo \$hash_$key") != "none" ]; then

    change_led $1 "none"
    eval hash_$key="none"

  fi                                                     

}

update_led_status() {
    $(curl -s -d '{"module":"status", "action":"0"}' -H "Content-Type: application/json" -X POST http://192.168.225.1/cgi-bin/qcmap_web_cgi \
| jsonfilter -e 'SIGNALSTRENGTH=@.wan.signalStrength' -e 'NETWORKTYPE=@.wan.networkType')

    case $SIGNALSTRENGTH in
        "0;")
            led_off signal1
            led_off signal2
            led_off signal3
            led_off signal4
            ;;
        "1;")
            led_on signal1
            led_off signal2
            led_off signal3
            led_off signal4
            ;;
        "2;")
            led_on signal1
            led_on signal2
            led_off signal3
            led_off signal4
            ;;
        "3;")
            led_on signal1
            led_on signal2
            led_on signal3
            led_off signal4
            ;;
        "4;")
            led_on signal1
            led_on signal2
            led_on signal3
            led_on signal4
            ;;
    esac

    case $NETWORKTYPE in
        "3;")
            led_on 4g
            ;;
        *)
            led_off 4g
            ;;
    esac
}

led_status_loop() {
    while sleep 10; do
        update_led_status
    done
}

led_status_loop &



Can you help me to solve this problem?
what pakage i must install and this script i can paste in local.rc file with scp?
thank you!