Ubuntu: Balance of GSM USB Modem using USSD



Question:

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)?


Solution:1

These are some Apps with USSD balance check support:

Prepaid Manager

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:

Prepaid Manager App on Ubuntu Software

Or run the following command:

sudo apt install prepaid-manager-applet  

Modem Manager GUI

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:

Modem Manager GUI App on Ubuntu Software

Or run the following command:

sudo apt install modem-manager-gui  

V Mobile Broadband

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 on wader, which replaces Ubuntu's default modemmanager. So, if you encounter problems with the new setup and decide to uninstall v-mobile-broadband, don't forget to reinstall modemmanager package.


Sources


Solution:2

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:

gammu getussd "*901#"  

For installation and configuration instructions and more details, see here.


Solution:3

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 package modemmanager.

If you are in Ubuntu 13.10:

sudo apt-get install modem-manager-gui modemmanager  

In other versions of Ubuntu you can do it with the application prepaid-manager-applet

sudo apt-get install prepaid-manager-applet  


Solution:4

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):

gsm-ussd -m /dev/ttyUSB1 "*901#"  


Solution:5

You can use the mmcli command line client of Ubuntu's default ModemManager to send a USSD code and get the reply:

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

  2. Enable the modem (assuming your modem index is 0): mmcli -m 0 -e

  3. 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:

    mmcli -m 0 --3gpp-ussd-initiate="*901#"  

For the case that querying your balance requires operating a USSD menu: this is also possible with mmcli, see this answer.


Solution:6

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:

sudo apt-get install ruby-ronn;  git clone git://git.code.sf.net/p/atinout/code atinout;  cd atinout;  make;  sudo checkinstall make install;  

Then, if you use ModemManager (the default under Ubuntu Linux), you might have to disable it first to allow atinout to access your modem:

sudo stop modemmanager;  

Now, to send a USSD code for balance query to the network (say, *901#) and display the result, you would use this command:

atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"*901#\",15") && sleep 4 && \  atinout - /dev/ttyUSB1 - < <(echo "AT");  

This assumes that your modem is at /dev/ttyUSB1. The AT command in the second atinout command is just to get the unsolicited USSD answer displayed as a side effect, which should have arrived after the sleep.

For the case that querying your balance requires operating a USSD menu: this is also possible with atinout, see this answer.


Solution:7

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:

You have:  2.07 GB of traffic, valid until N  47 minutes  

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:

$ sudo stop modemmanager  

Now, you need to know your modem port; in my case, it is /dev/ttyACM0.

If you don't know your port, try this:

for n in `ls /sys/class/*/*{ACM,wdm}*/device/interface`;do echo $(echo $n|awk -F '/' '{print $5}') : $(cat $n);done  

And look for the entry with Mobile Broadband Modem. E.g. my output looks as follows:

ttyACM0 : F5521gw Mobile Broadband Modem  ttyACM1 : F5521gw Mobile Broadband Data Modem  ttyACM2 : F5521gw Mobile Broadband GPS Port  cdc-wdm0 : F5521gw Mobile Broadband Device Management  cdc-wdm1 : F5521gw Mobile Broadband USIM Port  

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:

$ sudo picocom /dev/ttyACM0  

You should see something like this:

picocom v1.7    port is        : /dev/ttyACM0  flowcontrol    : none  baudrate is    : 9600  parity is      : none  databits are   : 8  escape is      : C-a  local echo is  : no  noinit is      : no  noreset is     : no  nolock is      : no  send_cmd is    : sz -vv  receive_cmd is : rz -vv  imap is        :   omap is        :   emap is        : crcrlf,delbs,    Terminal ready    *EMRDY: 1  

(if you don't see this *EMRDY: 1, it probably means that you haven't stopped Modem Manager, see above)

Then enter:

AT+CUSD=1,"*104#"  

And after several seconds, you should get your reply, which can be multiline:

+CUSD: 0,"You have:  2.07 GB of traffic, valid until N  47 minutes    ",15    OK  

To exit picocom, use Ctrl-A Ctrl-X

And start modem manager again:

$ sudo start modemmanager  


Solution:8

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:

chat SMS|interface3|ussd|*901#  

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 …).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »