Reputation: 41
I want to obtain information about the account balance of a SIM card I have installed in a mobile broadband modem in my computer. For my mobile network operator, this works using the USSD code 100#
.
I found that gammu
can send that USSD code using gammu getussd '100#'
. In response, gammu shows me this USSD menu:
Press Ctrl+C to break...
USSD received
Status : Action needed
Service reply : "Reply with your option:
1.Account Balance
2.Buy a Data Plan
3.Top Up Now
No response in specified timeout. Probably phone not connected.
How can select an option from that menu (like, 1
)?
Upvotes: 2
Views: 13896
Reputation: 13
The answer from the link below worked great for me.
You can add the modemmanager PPA and update your apt. There's a bug mentioned in the link for some usb modems, but that has been fixed with the update
sudo add-apt-repository ppa:aleksander-m/modemmanager-xenial<br>
sudo apt-get update
Then follow this: https://stackoverflow.com/a/31864567/6161579
Thanks @tanius
Upvotes: 1
Reputation: 16779
I found that I can successfully navigate USSD menus with AT commands directly. Given my system's issues with the otherwise preferable mmcli
solution (see my other answer for details), this is so far the only working solution to navigate USSD for me.
How to get this to work:
(1) Install an AT terminal. I chose atinout
to communicate with the modem via AT commands. You can also use any other AT terminal software like putty
, minicom
etc.. To install atinout
:
sudo apt-get install ruby-ronn;
git clone git://git.code.sf.net/p/atinout/code atinout;
cd atinout;
make;
sudo checkinstall make install;
(2) If you use ModemManager (which is the default under Ubuntu Linux), you might have to disable it first to allow atinout
to access your modem:
sudo stop modemmanager;
(3) Now, to receive and reply to an USSD menu, you would use a command like this:
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"100#\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT") && \
\
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"1\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT");
This assumes your modem is at /dev/ttyUSB1
and the code to receive the USSD menu is 100#
. Adapt to your situation.
Explanation: The command sends 100#
to the network to receive the USSD menu, and then 1
to choose the first option. Spreading one USSD menu session over multiple atinout
calls like this does not break the session if you don't exceed the timeouts (which are usually >20s).
Troubleshooting: If the above all-in-one command does not work, try executing the individual parts manually, repeating those that fail. If something fails repeatedly ("resource busy" etc.), your modem might be in a strange state. Reset it, or just let the computer go through a suspend / resume cycle.
Upvotes: 2
Reputation: 16779
It seems to me that ModemManager (and its command line client interface mmcli) is currently the most sophisticated, highest-quality solution for interacting with USSD and USSD menus under Linux.
Installation (under Debian / Ubuntu Linux):
sudo apt-get install modemmanager modem-manager-gui
Usage (following the manpage):
Listing your modems: mmcli -L
. This will show a modem device path like /org/freedesktop/ModemManager1/Modem/12
and you can use the number at its end to specify the modem to use after the -m
option in the following commands.
Showing attributes of your modem: mmcli -m 12
.
Enabling the modem (needed before using it for USSD): mmcli -m 12 -e
Starting a USSD session. For example, for Ncell this command shows the main USSD menu: mmcli -m 12 --3gpp-ussd-initiate="*100#"
Responding to a USSD menu. After the session is started, you may use a command like this to respond, here using option 1
: mmcli -m 12 --3gpp-ussd-respond="1"
Canceling the USSD session on the given modem: mmcli -m 12 --3gpp-ussd-cancel
.
Obtaining the status of all USSD sessions (of all available modems): mmcli --3gpp-ussd-status
.
With most hardware, this should work properly and immediately as described.
(With my hardware however, I could not use mmcli
so far due to a bug. All USSD related commands in mmcli
would reply error: modem not unlocked yet
, and mmcli -m 12 | grep " lock"
would show that the sim-pin2
lock is enabled. But it is not (means I could not get past this by disabling the lock). And even if it would be enabled, that lock would not limit USSD usage (it's rather just meant for limiting outgoing calls to certain numbers). So, I'll have to remove this overzealous test condition from here, compile it myself and test again … .)
Upvotes: 7
Reputation: 16779
The Linux command line tool gsm-ussd
has support for USSD sessions that will allow you to answer to USSD menus. For detailed installation and configuration instructions see here. The version 0.4 Debian package offered there for installation is the latest dev branch version.
However, the support for this is not yet stable [source]. At least for me, it does not work. With different hardware and / or mobile network operators, you might have more luck.
The way it is meant to be used is like this (using Ncell as example):
$ gsm-ussd -m /dev/ttyUSB1 "*100#"
USSD session open, to cancel use "gsm-ussd -c".
1 Account
2 Services operations
3 Offices information
4 How to call Call Center
5 Change password
Note:
Back:* Top:#
To reply and select an option, you would send something like:
$ gsm-ussd -m /dev/ttyUSB1 "1"
To end the session and return back to normal single-command USSD mode, you would execute gsm-ussd -c
. More complete documentation is here.
Upvotes: 2
Reputation: 10091
It's currently not possible with Gammu command line, but you can use simple Python script using python-gammu: https://github.com/gammu/python-gammu/blob/master/examples/service_numbers.py
Upvotes: 1