How split the variable?

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!

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...
}

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]

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
}

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

For the one that works, does it take some time before the information shows up?

Yes.
But delay doesn’t help.

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"
  }
}

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]
  }
}

Sorry.
Can you hep me yet?
How do this variable add to the content of existing file?

Well done, good solution.

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);
}

Thanks!

Well done, good solution.

maybe, but it generates log message “script error:interrapted”

Try this script:

/interface ppp-client info ppp-out1 user-command="AT^HCSQ\?" do={
  :if ([:len $manufacturer] > 0 ) do={
  :set HCSQ $"manufacturer"
  :quit;
  }
}

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"

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;
}
}