Community discussions

MikroTik App
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

How split the variable?

Wed Dec 10, 2014 8:51 am

Hi!
How to split this value ^HCSQ:"LTE",56,47,101,18 ?
I would like to get 5 value by script:

Signal = LTE (maybe WDMA)
RSSI = 56 (the first)
RSSP = 47 (the second)
SINR = 101 (the next)
RSRQ = 18 (only for LTE).


ex.:
^HCSQ:"LTE",56,47,101,18
^HCSQ:"WDMA",45,147,60
^HCSQ:"LTE",58,39,99,32

Thanks!
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: How split the variable?

Wed Dec 10, 2014 6:41 pm

You can split the string to get rid of the prefix, and then convert the remaining string into an array.
{
:local var "^HCSQ:\"LTE\",56,47,101,18"
:local myArray [:toarray [:pick $var ([:find $var ":"]+1) [:len $var]]]

:local signal [:pick $myArray 0]
:put "Signal: $signal"
:local rssi [:pick $myArray 1]
:put "RSSI: $rssi"

etc...
}
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Wed Dec 17, 2014 1:33 pm

Thanks!
It works.

Do you know how to send "Q" using script?

interface ppp-client info ppp-out1 user-command="AT^HCSQ\?"

modem-status: ready
pin-status: no password required
functionality: full
manufacturer: ^HCSQ:"LTE",52,47,156,26
model: E3372
revision: 21.285.01.02.143
serial-number: 864346021423076
current-operator: Beeline (cellid bc4ae05)
access-technology: Evolved 3G (LTE)
signal-strengh: -69 dBm
frame-error-rate: n/a

-- [Q quit|D dump|C-z pause]
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: How split the variable?

Thu Dec 18, 2014 8:48 pm

I don't think you can send Q from a script, but you can tell it to just run once. And from there you can get data. Paste this in the terminal and it should output ^HCSQ:"LTE",52,47,156,26.
{
:local mf
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" once do={
  :set mf $manufacturer
}
:put $mf
}
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Fri Dec 19, 2014 11:03 am

It is the problem =(
[mikatmbank@TEST2] > interface ppp-client info ppp-out1 user-command="AT^HCSQ\?"
works
-- [Q quit|D dump|C-z pause]

interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" once
modem-status:
pin-status:
functionality:
manufacturer:
model:
revision:
serial-number:
current-operator: (cellid )
access-technology:
signal-strengh:
frame-error-rate:

nterface ppp-client info ppp-out1 user-command="AT^HCSQ\?" once do={:delay 10}
modem-status:
pin-status:
functionality:
manufacturer:
model:
revision:
serial-number:
current-operator: (cellid )
access-technology:
signal-strengh:
frame-error-rate:

doesn't work
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: How split the variable?

Fri Dec 19, 2014 6:05 pm

For the one that works, does it take some time before the information shows up?
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Fri Dec 19, 2014 9:09 pm

Yes.
But delay doesn't help.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: How split the variable?

Mon Dec 22, 2014 10:20 pm

You could try just sending the letter, or echoing it with :put, but I doubt either of these will work...
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0) do={
    :put $manufacturer
    q
  }
}
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0) do={
    :put $manufacturer
    :put "q"
  }
}
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Tue Dec 23, 2014 9:36 am

Thanks for your help!

It works!
My script has name QTY_Signal
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0 ) do={
  :set HCSQ $"manufacturer"
  /system script job remove [find script=QTY_Signal]
  }
}
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Tue Dec 23, 2014 10:19 am

Sorry.
Can you hep me yet?
How do this variable add to the content of existing file?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: How split the variable?

Tue Dec 23, 2014 8:25 pm

Thanks for your help!

It works!
My script has name QTY_Signal
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0 ) do={
  :set HCSQ $"manufacturer"
  /system script job remove [find script=QTY_Signal]
  }
}
Well done, good solution.
Sorry.
Can you hep me yet?
How do this variable add to the content of existing file?
You can add content to existing file by doing something like this:
{
:local fileContent [/file get myFile.txt content];
:local manufacturer "^HCSQ:\"LTE\",52,47,156,26"
/file set myFile.txt contents=($fileContent . "\n" . $manufacturer);
}
 
Anirey
just joined
Topic Author
Posts: 24
Joined: Mon Sep 22, 2014 8:37 am

Re: How split the variable?

Wed Dec 24, 2014 9:08 am

Thanks!
Well done, good solution.
maybe, but it generates log message "script error:interrapted"
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 117
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: How split the variable?

Thu Jan 12, 2017 2:44 am

Thanks for your help!

It works!
My script has name QTY_Signal
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0 ) do={
  :set HCSQ $"manufacturer"
  /system script job remove [find script=QTY_Signal]
  }
}

Try this script:
/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0 ) do={
  :set HCSQ $"manufacturer"
  :quit;
  }
}
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 117
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: How split the variable?

Thu Jan 12, 2017 2:49 am

I use this variant:
/system script
add name=lte owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source=":local i 0;\
    \n/interface ppp-client info ppp-WAN do={\
    \n:set i (\$i+1);\
    \n:if (\$i=5) do={\
    \n:global lte \$\"access-technology\" ;\
    \n:global signalstrengh \$\"signal-strengh\";\
    \n:global itog (\$lte.\"  \".\$signalstrengh); \
    \n:log warn \$itog;\
    \n:quit;\
    \n}\
    \n}\
    \n\
    \n\
    \n"
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 117
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: How split the variable?

Thu Jan 12, 2017 2:55 am

And after reading this topic my final variant:
/interface ppp-client info ppp-WAN do={
:if ([:len $"access-technology"] > 0 ) do={
:global lte $"access-technology" ;
:global signalstrengh $"signal-strengh";
:global itog ($lte."  ".$signalstrengh); 
:log warn $itog;
:quit;
}
}

Who is online

Users browsing this forum: acn, Bing [Bot], GoogleOther [Bot], K0NCTANT1N, Marc1963 and 35 guests