Send AT Commands to modem via script

I want to do something but have no idea how…

I am familiar with MikroTik scripting but what I want to do is, have a script that will be able to send an AT command to the modem connected on the board and parse the output given for the command to a variable.

I want to for instance send a USSD (AT+CUSD) command to the modem which will check the account balance of the SIM card in the modem and then use it to email the balance given. I have absolutely no idea how to access the modem and interactively do this via a script.

Any help or pointers in the correct direction will be appreciated.

please see ‘/interface ppp-client’ menu where you can add ppp client for some port, like serial, or, if you have connected some USB port so you can do dial out.

I don’t think this is what I am asking…

I want to send a command to the modem via interface connected e.g. usb2

The command is something like this:
AT+CUSD=1,“*101#”,15

If I do this command in a terminal on the RouterBoard connected to the modem it works fine. The command is a USSD command that returns the current account balance of the 3G card.

What I want to do now is to do this command via a script and the output of the command must then be parsed and stored in a variable so I can email the contents to someone. How to do the rest, e.g. send the email etc I know how but I do not know how to parse this command’s output that is returned from the ISP back to a variable.

Any Possible help?

USSD, even in a limited form, like for simple queries (balance lookup) would be a GREAT feature to have.

I can imagine it must be possible to talk to the modem as it presents multiple virtual serial ports to the router.

Please note that a similar feature: sending and receiving an SMS, is already supported: http://wiki.mikrotik.com/wiki/Manual:Tools/Sms

To talk to the modem directly, you can use /system serial-terminal usb2 channel=

Tags: mikrotik, USSD, pre-paid, prepaid, airtime, balance, *100#, *101#

I quote from http://mybroadband.co.za/vb/archive/index.php/t-361248.html?s=ccc00713f2762a358757f8271fc81707

What you do is redirect the terminal to one of the secondary serial ports on the modem (diagnostic or UI ports) as follows:

/system serial-terminal usb2 channel=2
Your usb port and channel may be different, follow the above link for the procedure to list the ports and channels.

You then can send USSD commands directly over the terminal, for example to check your Vodacom balance:

AT+CUSD=1,“111500#”,15

When you are done, disconnect from the modem’s serial port by pressing Ctrl-A followed by Q.

Hi did you find the solution of your question?
thanks