Are there some tools or commands I can use to send USSD codes for checking balance and data balance of the GSM SIM Card in my USB modem (Mobile broadband dongle)?
Are there some tools or commands I can use to send USSD codes for checking balance and data balance of the GSM SIM Card in my USB modem (Mobile broadband dongle)?
These are some Apps with USSD balance check support:
Prepaid Manager
Prepaid Manager is an applet for the GNOME Desktop that allows you to check and top up the balance of GSM mobile prepaid SIM cards. It is a simple and minimalistic app with USSD balance check and topup being all that it does. But on the flip side, it is a very dated application and haven't received any new updates in a long time. And if your provider isn't supported, you'll have to manually configure it as described on their homepage. To install, click here:
Or run the following command:
Modem Manager GUI
Modem Manager GUI is a complete solution to manage and monitor mobile network based modems. It packs quite a lot of features, and USSD support is just one of them. For a complete list of features, visit their official homepage. To install, click here:
Or run the following command:
V Mobile Broadband
V Mobile Broadband is the original Vodafone Mobile Connect software for Linux rewritten to be compatible with Network Manager by Vodafone's open source Betavine Connection Manager team. Unfortunately, it doesn't seem to be very actively maintained at the moment and isn't available in Ubuntu repos. However, you may try your luck building the project from source. Check out their GitHub page.
Warning:
v-mobile-broadband
depends onwader
, which replaces Ubuntu's defaultmodemmanager
. So, if you encounter problems with the new setup and decide to uninstallv-mobile-broadband
, don't forget to reinstallmodemmanager
package.Sources
You can use the command-line utility
gammu
for this purpose. If the USSD code to get your balance is (say) *901#, you would execute:For installation and configuration instructions and more details, see here.
You can do them with the package
modem-manager-gui
. But it is only available for 13.10. In other versions you have to manage them in Terminal with the packagemodemmanager
.If you are in Ubuntu 13.10:
In other versions of Ubuntu you can do it with the application
prepaid-manager-applet
You can use AT commands directly to query your balance via USSD. For that, use any serial terminal program that lets you communicate with your modem directly (
putty
,minicom
etc.).I chose
atinout
because it integrated nicely with the command line. First you install it:Then, if you use ModemManager (the default under Ubuntu Linux), you might have to disable it first to allow
atinout
to access your modem:Now, to send a USSD code for balance query to the network (say, *901#) and display the result, you would use this command:
This assumes that your modem is at
/dev/ttyUSB1
. TheAT
command in the secondatinout
command is just to get the unsolicited USSD answer displayed as a side effect, which should have arrived after thesleep
.For the case that querying your balance requires operating a USSD menu: this is also possible with
atinout
, see this answer.You can use the
mmcli
command line client of Ubuntu's default ModemManager to send a USSD code and get the reply:Start by listing your modems:
mmcli -L
. This will show a modem device path like/org/freedesktop/ModemManager1/Modem/0
. The number at the end is the modem index, remember it.Enable the modem (assuming your modem index is 0):
mmcli -m 0 -e
Send the USSD request and display the answer. Assuming your network operator's USSD code to obtain the balance is *901#, the command would be:
For the case that querying your balance requires operating a USSD menu: this is also possible with
mmcli
, see this answer.You can use the Linux command line tool
gsm-ussd
to send USSD codes, get answers, and even navigate USSD menus (though that was not stable / usable for me).For detailed installation and configuration instructions see here. The version 0.4 Debian package offered there for installation is the latest dev branch version.
If the USSD code to get your balance is (say) *901# and your modem is
/dev/ttyUSB1
you would execute this to send a simple USSD code and display the network's answer (not resulting in a menu):For me, both ModemManager-based solutions and
gammu
don't work correctly with the multiline USSD response; e.g. my operator has a USSD command*104#
, to which it responds something like:It's disappointing to see just the first useless line:
You have:
.Finally I found a workaround with
picocom
and manual AT command. So every time I want to check my balance, I have to do the following:First, stop Modem Manager:
Now, you need to know your modem port; in my case, it is
/dev/ttyACM0
.If you don't know your port, try this:
And look for the entry with
Mobile Broadband Modem
. E.g. my output looks as follows:For more information on getting the right port, see this link: https://gist.github.com/heyalexej/cc6c97b1ea42736b3ff7
Then, use picocom to connect to your port:
You should see something like this:
(if you don't see this
*EMRDY: 1
, it probably means that you haven't stopped Modem Manager, see above)Then enter:
And after several seconds, you should get your reply, which can be multiline:
To exit picocom, use Ctrl-A Ctrl-X
And start modem manager again:
You can use the open source virtual PBX solution FreeSwitch together with its extension GSMopen to send USSD commands [source].
For example, if the USSD code to get your balance is (say) *901#, you would execute:
There are simpler solutions in the other answers of course, but in case you use GSMopen anyway (… for example because it's the only way to do GSM voice calls under Linux …).