Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MikroTik LTE signal meter bar graph script for Quectel modems
#1
While MikroTik provides live signal strength, SINR, etc. in its LTE status screen, I have run into several issues at least in my particular situation, especially with fine tuning an antenna's direction / height.  The readings update every 3 seconds, which makes it tedious when fine tuning and constantly having to wait for the signals to refresh.  The readings only show the primary carrier and it's difficult seeing the thin bar lines on the phone screen particularly in bright sunlight. 

My script has the following features:
  • Shows an RSRP bar line from -130 to -80dB in single dB increments.
  • SINR covers from -20dB to 30dB in single dB increments.
  • The Margin line is the RSRP difference between the current cell and the strongest neighbour cell on the same EARFCN. 
  • Bar lines update twice per second.
  • Each Bar individually turns red to indicate weak or blue to indicate strong reading.
  • Shows the current eNB ID, which one can look up on a cell tower map such as CellMapper.
  • Shows the currently active aggregated EARFCNs. 
  • EARFCN / PCI selection.  Press the corresponding number on the keyboard to select which carrier to show readings for. 

The longer the bar lines, the better the signal strength / quality / neighbour cell margin. Smile

The script has some limitations:
  • On a mobile, set the font size to 34 or smaller to show the bars properly - Touch the cog wheel as shown in the screenshot below, enter 34 and touch OK.
  • This script only works on 4G carriers as no mobile network operates 5G in my area (Kilcar, Co. Donegal) and the nearest 5G I can pick up requires a 20 minute drive.  If 5G reaches my area on any network before fibre does, I will update the script for 5G.  If the script does not work properly, try disabling 5G temporarily.
  • When selecting an aggregated carrier, the carrier must be active to show readings.  If an aggregated carrier does not appear or no bars appear when selected, try running a speed test to activate the aggregated carriers.  Alternatively start a large file download or use cell / band lock to have it has the primary band temporarily. 

Screenshots from mobile (Chateau 5G on Vodafone) / desktop (Chateau LTE12 on Three):
       

Code:
# Select lte interface
set $lte lte1

# Print meter line
local meterline do={
    /terminal el; put "";
    /terminal style varname-local
    /terminal el; put $1
    set $output ""
    if ($2>0) do={ for i from=1 to=$2 do={ set $output "$output#" } }
    /terminal style syntax-old
    if ($2<22) do={ /terminal style error }
    if ($2>38) do={ /terminal style ambiguous }
    /terminal el; put [pick $output 0 50]
    /terminal style none
}

# Reset counters
set $count 0
set $pcount 0
set $cacell [ toarray "" ]
set $caband [ toarray "" ]
set $line 0

# Loop until a keystroke
do {
    # Reset previous line readings
    set $mrsrp -140
    set $msinr -20
    set $mmargin -20
    set $mpci ""
    set $carriers "None"
    set $enb "Disconnected"

        # Reset cursor position and note previous line count
    for n from=1 to=$count step=1 do={/terminal cuu}
    set $pcount $count
    set $count 0

    # Select EARFCN from #1 to #9 keypress
    if ($key>16 and $key<26) do={
        set $i 0
        foreach k,v in=$cacell do={
            if ($i=($key-17)) do={set $line $k}
            set $i ($i+1)
        }
    }

    # Get the list of carrier aggregation cells from using the modem at-chat commands
    set $cells [/interface lte at-chat $lte input="at+qnetinfo=\"servingcell\"" as-value ]
    set $cells [toarray [pick $cells 0]]
    set $ncells [/interface lte at-chat $lte input="at+qeng=\"NEIGHBOURCELL\"" as-value ]
    set $ncells [toarray [pick $ncells 0]]
    set $CA "PCC"

    # Loop through each LTE carrier
    set $i ([find $cells "PCC"] + 1)

    while ($i>1) do={
        # Get the PCI, EARFCN RSRP, RSRQ and SINR readings
        set $pci [pick $cells ($i + 1)]
        set $earfcn [pick $cells ($i + 2)]
        set $band [pick $cells ($i + 3)]
        set $rsrp [pick $cells ($i + 4)]
        set $sinr [pick $cells ($i + 7)]

        # Take note of any active EARFCN and PCI combination
        set ($cacell->$earfcn) $pci
        set ($caband->$earfcn) $band
        if ($line=0) do={ set $line $earfcn }
        if ($carriers="None") do={
            set $carriers $earfcn
            set $enb (tonum ("0x" . [pick $cells $i]) / 256)
        } else={ set $carriers "$carriers + $earfcn" }

        # Check RSRP reading against neighbour cell RSRP readings
        set $nrsrp -140
        set $margin 30
        set $npci "None"
        set $j [find $ncells "LTE"]
        while ($j>0) do={
            set $crsrp [pick $ncells ($j+4)]
            if ([pick $ncells ($j+1)] = $earfcn and \
                ([pick $ncells ($j+2)] != $pci) and \
                ($crsrp > $nrsrp) and \
                ($crsrp < 0)) do={
                    set $nrsrp [pick $ncells ($j+4)]
                    set $npci [pick $ncells ($j+2)]
            }
            set $j [find $ncells "LTE" $j]
        }

        # Calculate the RSRP margin
        if ($nrsrp > -140) do={set $margin [($rsrp - $nrsrp)]}     

        if ($line=$earfcn) do={
            set $mrsrp $rsrp
            set $msinr $sinr
            set $mmargin $margin
            set $mpci $npci
        }    
        
        # Check and loop for any aggregated carriers
        set $i [find $cells "SCC" $i]
        set $CA "SCC"
    }

    # Print available EARFCN / PCI combinations
    /terminal el
    /terminal style syntax-noterm
    put "Press # to select EARFCN - PCI:"
    /terminal style none

    set $i 0
    foreach k,v in=$cacell do={
        set $i ($i+1)
        /terminal el
        if ($k=$line) do={ /terminal style escaped }
        put ("$i: B" . $caband->$k . "\t$k\t$v")
        /terminal style none
        set $count ($count+1)
    }

    # Print the meter lines
    $meterline "RSRP   -120      -110      -100       -90       -80" (mrsrp+130)
    $meterline "SINR    -10        0         10        20        30" (msinr+20)
    $meterline "MARGIN  -10        0         10        20        30" (mmargin+20)

    # Print the connected carriers
    /terminal el; put ""    
    /terminal el; put "eNB ID:          $enb";
    /terminal el; put "EARFCNs active:  $carriers"    
    /terminal el
    if ($mpci="") do={ put "EARFCN $line offline" } else={ put "Top nearby cell: $mpci" }
    /terminal el; put "";
    set $count ($count+15)

    # Clear any extra lines from the previous run
    /terminal el
    for n from=($count+1) to=$pcount step=1 do={put ""; /terminal el}
    for n from=($count+1) to=$pcount step=1 do={/terminal cuu}

    # Check for any keystroke, then wait a split second
    /terminal el; put "-- [# line | Q quit | P pause]"
    set $key ([/terminal inkey timeout=0.5] & 223)
    set $time [/system clock get time]
    /terminal cuu;

    # Keystroke P (80) = Pause, Q (81) = Quit
    if ($key=80) do={/terminal el; put "-- Paused" ; /terminal inkey; /terminal cuu; }
} while (key!=81)
/terminal el

Usage:

If you are new to using scripts, see this thread on how to add / run a script. 

The script starts by showing the readings for the primary carrier.  To select another carrier, press the number corresponding to the carrier in the list.  The selected carrier turns blue.  To reset the list such as after aiming to another tower, stop and restart the script.

When fine tuning the antenna, first try getting the RSRP signal as high as possible, then fine tune the antenna by getting the SINR line as high as possible.

The Margin line shows how the signal strength of the selected carrier compares with the strongest neighbour.  If the SINR is fluctuating all over the place, try getting the Margin as high as possible.  It may not be possible to improve the margin much if the neighbour cell is another sector on the same mast / tower, such as being directly in-between two sectors.

If the script crashes out or does not operate properly, try disabling 3G and 5G (if present) in the LTE configuration. 

This script has been tested and debugged on the following routers with RouterOS 7.16:
  • Chateau LTE12 (EG12-EA)
  • Chateau LTE12 with Quectel EG18-EA m.2 modem on USB port
  • Chateau 5G (RG502Q-EA)
  • LHG with Quectel EP06 PCIe modem
Reply
#2
Thanks for the script. Very useful indeed.
It is working fine with the EM12-G modem in the LHGG here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)