Community discussions

MikroTik App
 
tim7979
just joined
Topic Author
Posts: 4
Joined: Mon Sep 28, 2020 8:11 pm

Setting a variable

Tue Jan 04, 2022 4:56 pm

What is the correct way in v7 to get this info please and set the variables?

:local enb ([/interface lte info [find name="lte1"] once as-value]->"enb-id")
:local sector ([/interface lte info [find name="lte1"] once as-value]->"sector-id")

I used to use this happily in v6 but fails to get the info on v7
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3255
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Setting a variable

Tue Jan 04, 2022 5:10 pm

What is the correct way in v7 to get this info please and set the variables?

:local enb ([/interface lte info [find name="lte1"] once as-value]->"enb-id")
:local sector ([/interface lte info [find name="lte1"] once as-value]->"sector-id")

I used to use this happily in v6 but fails to get the info on v7
What modem are we talking about? R11e-LTE6 or something else... Do those value show up in winbox or in the CLI when you don't setup them?

If they don't show in winbox/CLI, outside of script too, possible it is a bug that they just aren't being reported anymore. And thus your script can't get anything to set. If they do show up, then perhaps you should be using a ":global" not ":local" variable – but that depending on where this code lives.

Now the third possibility is if ROS get an error reading the value, it remove the attribute until get a successful results. You'd typically see this in winbox if the # of fields changes in the LTE interface (e.g. if you don't get RSRQ, it hides the controls upon an error - some for sector-id or any of the data from the modem). So your script may be get nothing, just because of poor timing. To fix this add duration=5s & add do loop that will then set the value (here you'd need a global outside the do loop to store the value).
 
tim7979
just joined
Topic Author
Posts: 4
Joined: Mon Sep 28, 2020 8:11 pm

Re: Setting a variable

Tue Jan 04, 2022 6:17 pm

Thanks Amm0

I use various SXT's and LHG's I was just having a play on a SXT with a R11e-LTE upgraded it just to see if my little scripts still worked okay.

I'm just using a little scheduled task where i set a few variables then load a /tool fetch url php page passing the variables to save in a database.

:local enb ([/interface lte info [find name="lte1"] once as-value]->"enb-id")
:local sector ([/interface lte info [find name="lte1"] once as-value]->"sector-id")

The modem is connected to the LTE and under the cellular tab i can see the info required.

I'm not sure how I get the info straight from the terminal though?

The method i have been using has been working on multiple devices for ages.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3255
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Setting a variable  [SOLVED]

Tue Jan 04, 2022 10:52 pm

:local enb ([/interface lte info [find name="lte1"] once as-value]->"enb-id")
:local sector ([/interface lte info [find name="lte1"] once as-value]->"sector-id")

The method i have been using has been working on multiple devices for ages.

Sorry I should have read more carefully. I think your fix is easier, change "info" to "monitor" – they changed this in V7.

If you want to see all the variable you can use, you can use this from Terminal (I call it the "CLI"), you can use:
/interface/lte/monitor [/interface/lte find running] once
To understand the signal data, this article is helpful: https://www.sharetechnote.com/html/Hand ... E_CQI.html
If your reading several of the LTE "info"/"monitor" variable, it's easier to get them all at once into an "array", then use the values you need – makes changing the script easier, code cleaner, and reduces the number of "AT" commands going to the modem. This can be done like this in V7 – you don't need to use the V7 syntax "/interface/lte", "/interface lte" from V6 still works (e.g. with space), but I do to make sure I know it's V7 script code ;).
:global cellulardata [/interface/lte/monitor  [/interface/lte find running] once as-value]
:log info "*LTE signal report*  CQI:  $($cellulardata->"cqi")  RSRQ: $($cellulardata->"rsrq")  RSRP: $($cellulardata->"rsrp") "

# you can also assign the various parts to a variable, which makes using them in a string easier
:global enb ($cellulardata->"enb-id")
:global sector ($cellulardata->"sector-id")
:global carrier ($cellulardata->"current-operator")
:global band ($cellulardata->"primary-band")
:global caband ($cellulardata->"ca-band")

:put "And, with https://cellmapper.net you can find location etc., checking '$carrier' for enb: $enb finding the sector $sector and/or $($cellulardata->"phy-cellid")"
:put "*LTE CA report*.  PRIMARY $band. with $([:len $caband]) subcarriers $caband"
# scripting tip: if you create new variable use only lowercase letters, the "string interpolation" is WAY cleaner see above vs first line with $($var->"attribute-name") stuff
 
You see that cellulardata gets all the data in one operation, then you can pick what you need later in a script. While a bit complex "$($varname->"lteattribute")" is required if you want text with one or more of the variable (e.g. log entry, an email template with signal report or whatnot). To assign a LTE attribute to a variable only the () and quote around the attribute name are needed.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3255
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Setting a variable

Tue Jan 04, 2022 11:16 pm

 
tim7979
just joined
Topic Author
Posts: 4
Joined: Mon Sep 28, 2020 8:11 pm

Re: Setting a variable

Wed Jan 05, 2022 1:12 pm

@Amm0 A perfect reply, many thanks for taking the time!

Who is online

Users browsing this forum: No registered users and 11 guests