Script for obtaining signal strength and access technology from an LTE modem

Hi All,

I'm trying to create a script to get the signal strength and access technology from an LTE modem. It will collect this data throughout the day and email me a file at the end of the day. The script works as expected on my hAP AC3 LTE6. However, my modem always uses LTE access technology, so I don't know how the script will work with other settings. I used gpt for the current values. I've already seen:

LTE, Evolved 3G (LTE), LTE (CA2), Evolved 3G (LTE CA2)
3G, 3G HSDPS & HSUPA, 3G HSPA+, 3G HSDPA,
GSM compact,

on the forum, which are included now in my script. Could you tell me where I can find all the access technology options available in RouterOS?

:local toEmail "you@mail.net"
:local MAXMINUTE 1438
:local id [/system/identity/get name]

:local lteData [/interface/lte print as-value]
:local ifaceName ""
:if ([:len $lteData] > 0) do={
    :set ifaceName ([:pick $lteData 0]->"name")
} else={
    :quit
}

:global LTELog
:if ([:len $LTELog] = 0) do={ :set LTELog "" }

:local t [/system/clock/get time]
:local hh [:tonum [:pick $t 0 2]]
:local mi [:tonum [:pick $t 3 5]]
:local minute (($hh * 60) + $mi)

:local mon [/interface/lte monitor $ifaceName once as-value]

:local techRaw ""
:if ([:len ($mon->"access-technology")] > 0) do={
    :set techRaw ($mon->"access-technology")
}

:local tech "xG"

# LTE / 4G variants
:if ($techRaw = "LTE" || \
     $techRaw = "Evolved 3G (LTE)" || \
     $techRaw = "LTE (CA2)" || \
     $techRaw = "LTE-A" || \
     $techRaw = "LTE CA" || \
     $techRaw = "LTE (CA)" || \
     $techRaw = "E-UTRAN" || \
     $techRaw = "Evolved 3G (LTE CA2)") do={
    :set tech "4G"
} else={

    # 5G variants
    :if ($techRaw = "NR5G" || \
         $techRaw = "5G" || \
         $techRaw = "NR") do={
        :set tech "5G"
    } else={

        # 3G variants
        :if ($techRaw = "3G" || \
             $techRaw = "WCDMA" || \
             $techRaw = "UTRAN" || \
             $techRaw = "HSPA" || \
             $techRaw = "HSPA+" || \
             $techRaw = "HSUPA" || \
             $techRaw = "3G HSUPA" || \
             $techRaw = "HSDPA" || \
             $techRaw = "HSDPA & HSUPA" || \
             $techRaw = "HSDPS & HSUPA" || \
             $techRaw = "3G HSDPA & HSUPA" || \
             $techRaw = "3G HSDPS & HSUPA" || \
             $techRaw = "3G HSPA+" || \
             $techRaw = "3G HSDPA") do={
            :set tech "3G"
        } else={

            # 2G variants
            :if ($techRaw = "GSM" || \
                 $techRaw = "GPRS" || \
                 $techRaw = "EDGE" || \
                 $techRaw = "GSM compact" || \
                 $techRaw = "EGPRS") do={
                :set tech "2G"
            }
        }
    }
}


:local rssiStr ""
:if ([:len ($mon->"signal-strength")] > 0) do={
    :set rssiStr ($mon->"signal-strength")
} else={
    :if ([:len ($mon->"rssi")] > 0) do={
        :set rssiStr ($mon->"rssi")
    }
}

:local rssi -140
:if ([:len $rssiStr] > 0) do={
    :local L [:len $rssiStr]
    :if ($L > 3 && [:pick $rssiStr ($L-3) $L] = "dBm") do={
        :set rssi [:tonum [:pick $rssiStr 0 ($L-3)]]
    } else={
        :set rssi [:tonum $rssiStr]
    }
}

:local lvl -1

:if ($rssi > -65) do={:set lvl 4} else={
    :if ($rssi > -75) do={:set lvl 3} else={
        :if ($rssi > -85) do={:set lvl 2} else={
            :if ($rssi > -95) do={:set lvl 1} else={
                :if ($rssi > -120) do={:set lvl 0}
            }
        }
    }
}

:local rsrpStr ""
:if ([:len ($mon->"rsrp")] > 0) do={
    :set rsrpStr ($mon->"rsrp")
} else={
    :if ([:len ($mon->"primary-rsrp")] > 0) do={
        :set rsrpStr ($mon->"primary-rsrp")
    }
}

:local rsrp -140
:if ([:len $rsrpStr] > 0) do={
    :local L [:len $rsrpStr]
    :if ($L > 3 && [:pick $rsrpStr ($L-3) $L] = "dBm") do={
        :set rsrp [:tonum [:pick $rsrpStr 0 ($L-3)]]
    } else={
        :set rsrp [:tonum $rsrpStr]
    }
}

:if ($rsrp > -120) do={
    :if ($rsrp > -80) do={:set lvl 4} else={
        :if ($rsrp > -90) do={:set lvl 3} else={
            :if ($rsrp > -100) do={:set lvl 2} else={
                :if ($rsrp > -110) do={:set lvl 1} else={
                    :set lvl 0
                }
            }
        }
    }
}



#/log info ("LTE dbg: iface=" . $ifaceName . " techRaw=" . $techRaw . " tech=" . $tech . " rssiStr=" . $rssiStr . " rssi=" . $rssi . " lvl=" . $lvl)

:global LTELog
:global LTEFileName
:local line ($minute . "," . $tech . "," . $lvl)

:if ($minute < $MAXMINUTE) do={
    :if ($LTELog = "" || [:len $LTELog] = 0) do={
        :set LTELog $line
    } else={
        :set LTELog ($LTELog . "\r\n" . $line)
    }
} else={
    :if ([:len $LTELog] > 0 && $LTELog != "") do={
        :local dateStr [/system/clock/get date]
        :set LTEFileName ($id . "_" . $dateStr . ".txt")
        /file add name=$LTEFileName contents=$LTELog
        /tool e-mail send to=$toEmail subject=("LTE Log for " . $dateStr . " (" . $id . ")") file=$LTEFileName
        :set LTELog ""
    } else={
        :if ([/file find name=$LTEFileName] != "") do={
           /file remove $LTEFileName
        }
    }
}

Hi,

The standarization materials from LTE consortim should answer your question.
On the other hand what is the real problem?
Just decode known values as you decode them already and when there is a data "unknown" to you then report it as "unknown" + verbatim value, so you would be able to improve your script.

1 Like

I'm not sure the level granularity of access technology is too important. So I'd just use a regular expression to find $techRaw~"(NR|5G)" and assume it's "5G". These values may from the modem, so model may affect the what's presented too.

What may be a more important data point is the number of CA channels and/or the aggregate bandwidth from all the CA. While the "access-technology" will inform how efficient the bandwidth is used...but for example a single 5G band can certain be slower than 4G with multiple bands.

1 Like

This script is designed simply to collect modem data for display on a graph for the user, not to measure speed, channels, throughput, etc. It simply reads the access technology data and converts it to 2G, 3G, 4G, 5G, and so on, so that the file can then be opened in my Android app, which will plot a simple graph from the file, for example, showing 5 bars and 3G signal in the morning, and 4G and 4 bars at night. That's it, I wanted to collect all the access technology options that RouterOS will provide for all built-in modems. I'll continue collecting them, for now.

:if ($techRaw = "LTE" ||
$techRaw = "Evolved 3G (LTE)" ||
$techRaw = "LTE (CA2)" ||
$techRaw = "LTE-A" ||
$techRaw = "LTE CA" ||
$techRaw = "E-UTRAN" ||
$techRaw = "Evolved 3G (LTE CA2)") do={
:set tech "4G"
} else={

5G options

:if ($techRaw = "NR5G" ||
$techRaw = "5G" ||
$techRaw = "NR") do={
:set tech "5G"
} else={

3G options

:if ($techRaw = "3G" || \
$techRaw = "WCDMA" || \
$techRaw = "UTRAN" || \
$techRaw = "HSPA" || \
$techRaw = "HSPA+" || \
$techRaw = "3G HSDPS & HSUPA" || \
$techRaw = "3G HSPA+" || \
$techRaw = "3G HSDPA") do={
:set tech "3G"
} else={
#2G variant
:if ($techRaw = "GSM" || \
$techRaw = "GPRS" || \
$techRaw = "EDGE" || \
$techRaw = "GSM compact") do={
:set tech "2G"
}
}
}
}

Fair enough. More suggesting I'm not sure there is a definitive list. And some regex might cover the ones you have not yet seen.