Page 1 of 1

Using "interface ppp-client info" in script

Posted: Sat Dec 17, 2011 11:09 pm
by asesko
Hi,
I just want to retrieve RSSI from Sierra mPCIE modem and use for something else. I am using the follwoing line in my script:
/interface ppp-client info ppp-out1 do=  { /global rssi "$"signal-strengh""; <other part of script>;}
The problem is that "interface ppp-client info" command works in loop and the script doesn't end... I can use option "once" but then I don't get any data since this command need to make at lest 2 loops to dsiplay any data.

Any idea how to resolve my problem or is there any other way to get RSSI from Sierra MC8780 modem ?

Re: Using "interface ppp-client info" in script

Posted: Mon Mar 12, 2012 10:29 pm
by alphil
Hello
I have the same problem. We found the solution?
Thanks.
Hi,
Any idea how to resolve my problem or is there any other way to get RSSI from Sierra MC8780 modem ?

Re: Using "interface ppp-client info" in script

Posted: Thu Mar 15, 2012 1:04 pm
by alphil
Mainly, I want to have three preset profiles (three different operators) ppp-client for UMTS connection.
I want to enable automatic selection of the profile that corresponds to the SIM card inserted.
The only thing I can think of is read the value of "current-operator" and use one or another of the preset profiles, according to the value obtained (p.ex: Vodafone).
If I use "/interface ppp-client info ppp-out1" I can not get data from the current-operator as a variable.
I can only view it.

Is there any way to get this data?

Re: Using "interface ppp-client info" in script

Posted: Thu Mar 15, 2012 1:37 pm
by Base122
It seems if you use "/interface ppp-client info ppp-out1" in a script, it runs continuously in the background and keeps logging the information to the system log file. This can be seen if the async topic is enabled for system logging.

If you have issued this info command once in a script, it cannot be issued again as it is already running.

Once the info command has been started from the script, it cannot be used again by Winbox either.

I have not yet found a way to stop this once it has been started, except by unplugging the 3G modem.

Does anyone know of a command that can be used inside a script to stop PPP info once it has been started??

If you use this PPP info from a terminal window, you would use Q to stop it, but how from inside a script?

Re: Using "interface ppp-client info" in script

Posted: Fri Mar 16, 2012 6:50 pm
by alphil
Is true, you can create the script "umts_info" that contains "/interface ppp-client info ppp-out1" and call it from scheduler.
To kill it you can use "/system script job remove [find script=umts_info ]"

In log we can see information about the SIM card operator.
/log print where topics~"async"

01:51:16 async,debug modem:2\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00: sent AT+COPS? 
01:51:16 async,debug modem:2\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00: rcvd +COPS: 0,0,"movistar",2
In my case is "movistar", but no way to retrieve that information as a variable
Do not understand why does not the command /log print where message~"movistar", I think it is by zeros

Re: Using "interface ppp-client info" in script

Posted: Sat Mar 17, 2012 9:04 pm
by Base122
Is true, you can create the script "umts_info" that contains "/interface ppp-client info ppp-out1" and call it from scheduler.
To kill it you can use "/system script job remove [find script=umts_info ]"
Thanks for this tip alphil.
asesko, I think I have found a way to successfully use this ppp-client info command inside a script.
You have to use a counter and let the loop run at least 3 times to set the system variables properly.
After that they can be used for whatever you need. But you must "kill" the script job after you have finished.

I have created two scripts.
One named pppUptime, which uses the ppp-client monitor command to get the interface uptime.

The other is named pppInfoUPtime, which uses ppp-client info, but starts the pppUptime script as well, to allow me to get the Uptime to add to the information file and for email.

I hope these scripts are useful.
I have spent many hours on this and have learned a great deal.

Enjoy!

pppUptimeOnly:
## All this script does is set the pppUptime global variable for "wan2" in this example##
## This script name is pppUptime in this example ##
## Used in conjunction with my other pppInfo script ##
## Share, modify, improve and use as you wish ##
## Tested on RouterOS v5.12 using Huawei E367 modem #
## Peter James 2012-03-17 ##

## Set the PPP interface name for which Uptime value is required ##
:local pppName "wan2";

# loop counter #
:local k 0;

# Defined as global, so that other script can use #
:global pppUptime;

:local pppID [/interface ppp-client find name=$pppName];
:log info "PPP Uptime $pppName Script Starting";


# Start of monitor command #
/interface ppp-client monitor $pppName do={

:set k ($k+1);

# run loop twice to be sure #
:if ($k=2) do={

:set pppUptime $"uptime";

## Must now stop this script, or Monitor will run forever ##
:log info "PPP Uptime $pppName Script completed";
/system script job remove [find script=pppUptime ];

}
}
pppInfoUptime (starts the above pppUptimeOnly script):
## Script to write PPP-info to a file and send to Email ##
## For this example, my PPP name is "wan2" ##
## and my script name is "wan2PPPinfoUptime" ##
## This script makes use of the ppp-client info command ##
## with a loop counter to stop the command once the ##
## information has been acquired. ##
## Can be used in conjunction with my other pppUptime ##
## script if the Uptime is required as well. ##
## You can use the info file to extract information for other purposes ##
## Remember to set up Tools-Email ##
## Share, modify, improve and use as you wish ##
## Tested on RouterOS v5.12 using Huawei E367 modem #
## Peter James 2012-03-17 ##

# Set the PPP interface name #
:local pppName "wan2";

# Define the email address to receive PPP Info report  #
:local emailAddress "your_email_address"

:local i 0;

global pppUptime;

:local pppID [/interface ppp-client find name=$pppName];

# Variables to hold PPP Info #
:local String1;
:local String2;
:local pppInfoString;

# Variable to hold PPP interface current IP address #
:local currentIP;


# Get System Identity #
:local SystemID [/system identity get name];

:local pppStatus;
:if ([/interface get [find name=$pppName ] running ]=true) do={

:set pppStatus "Running";

### Get the address of the specified wan interface ###
:set currentIP [/ip address get [find interface=$pppName] address];
:set currentIP [:pick $currentIP 0 [:find $currentIP "/"]]

} else={
:set pppStatus "Disabled";
}

# Start the pppUptime script #
# Comment out if you do not need #
/system script run pppUptime;

:log info "PPP Info $pppName Script Starting";

# Create the information File #
/file print file="$SystemID-$pppName-PPP-info";

:global SysDate [/system clock get date]
:global SysTime [/system clock get time]


# Start of info command #
/interface ppp-client info $pppID do={

:set i ($i+1);

# for some reason this loop must run at least 3 times to set the system variables #
# set to run 5 times to be sure #
:if ($i=5) do={

# non info command stuff #
:set String1 "Date: $SysDate\nTime: $SysTime\nSystem ID: $SystemID\nPPP Interface: $pppName\nPPP Interface Status: $pppStatus\nIP Address: $currentIP\nUptime: $pppUptime\n";

:set String2 "Modem Status: $"status"\nPin Status: $"pin-status"\nFunctionality: $"functionality"\nManufacturer: $"manufacturer"\nModel: $"model"\nRevision: $"revision"\nSerial Number: $"serial-number"\nCurrent Operator: $"current-operator"\nAccess Technology: $"access-technology"\nSignal Strength: $"signal-strengh"";

:set pppInfoString "$String1$String2";

:log info $pppInfoString;

# Populate file with required information #
/file set "$SystemID-$pppName-PPP-info" contents=$pppInfoString; 


# Do all the other things you need to do here ???#

# Example, send Email #
:log info "Sending PPP Info email";
/tool e-mail send tls=yes subject="$SystemID $pppName PPP Info" to=$emailAddress body="$pppInfoString";

:log info "PPP Info $pppName Script Completed";

## Must now stop this script, or info will run forever ##
/system script job remove [find script=wan2PPPinfoUptime ];

}
} 

Re: Using "interface ppp-client info" in script

Posted: Sun Mar 18, 2012 12:34 am
by alphil
Great job. I didn't know that can get in this way ($"current-operator").
Really I used a piece of your script and is what I needed.
:local i 0;
/interface ppp-client info umts do={
:set i ($i+1);
:if ($i=5) do={
:global modemstatus $"status";
:global pinstatus $"pin-status";
:global currentoperator $"current-operator";
:global signalstrengh $"signal-strengh";
/system script job remove [ find script=umts_info ];
}
}

Re: Using "interface ppp-client info" in script

Posted: Sun Mar 18, 2012 11:14 pm
by Base122
Great job. I didn't know that can get in this way ($"current-operator").
Really I used a piece of your script and is what I needed.
:local i 0;
/interface ppp-client info umts do={
:set i ($i+1);
:if ($i=5) do={
:global modemstatus $"status";
:global pinstatus $"pin-status";
:global currentoperator $"current-operator";
:global signalstrengh $"signal-strengh";
/system script job remove [ find script=umts_info ];
}
}
Now if you try the script like this:
/interface ppp-client info umts do={
:global modemstatus $"status";
:global pinstatus $"pin-status";
:global currentoperator $"current-operator";
:global signalstrengh $"signal-strengh";
}
Now it will run forever, but your global variables will be updated continuously and you can get their values using another script at any time.

I have tested this with signalstrengh, by using this second script:
:global signalstrengh;
:do {
:log info $signalstrengh;
delay 1;
} while=(true)
If I unplug the 3G modem external antenna, I can see the signal strength change (1 second interval) in the log, when I run the second script.

I don't know if this has an affect on router cpu load? (job runs all the time)
It does not seem to change much.

Only problem is, because the first "info" command script is running forever, you cannot use WinBox Info button.
You get error message "Couldn't start - Info command already running! (12)"
But, this is not a problem if you do not need to use WinBox.

Now you can watch signal strength with another script and take some action if it is too low maybe?

Re: Using "interface ppp-client info" in script

Posted: Mon Mar 19, 2012 1:39 am
by alphil
In my case, this option is not valid, because I use LED's to monitor the signal strength.
/system leds
set 0 disabled=no leds=led1 modem-signal-treshold=-85 type=modem-signal
If the info-channel is busy by the command "ppp-client info", the visualization of the LEDs is not available.
I prefer to run this script on request. And I do it from "The Dude" because I put all routers on the map and want to see operator, signal, etc. on the device label.

Re: Using "interface ppp-client info" in script

Posted: Thu Jan 12, 2017 3:01 am
by greek
I use this variant of script:
/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;
}
}

Re: Using "interface ppp-client info" in script

Posted: Tue Jan 02, 2018 2:07 am
by EIKA
Guys, please help. I come across with the same issue. I run the main script from where I calling modemStatus (aka daughter) script. But everything sticks at this command and can't move forward.
/interface ppp-client info $ifName
Because as was stated above it's a tools that provides async data and works all the time until keypress (Q, D or ctrl+Z).
When I try to use
/system script job remove [find script="modemStatus"]
from daughter (modemStatus) script, this command kills the main script as well. And I see 2 red lines in log: Script error: interrupted / Script error: interrupted
And there is no future script (main one) execution.
Command
/system script job remove [find name="modemStatus"]
doesn't work for me, but looks like this syntax is OK for some other places, like script calling.

I've tried to insert Q, quit or something in the daughter script, but not luck as well.

Please advise what to do.

P.S.
I run ROS 6.41 and looks like there are many many changes during past year, because this script worked for me in the past.

Re: Using "interface ppp-client info" in script

Posted: Tue Jan 02, 2018 2:21 am
by EIKA
And 2 more questions:

1. Is it OK to see script interrupted messages in log when I use job remove command?
2. Is there any way to check script status: running vs not running (stopped/killed/removed)? From any terminal at this router.

Thanks in advance!