Thanks to the author of the topic
Checking the Kyivstar modem account on Linux which helped me understand how modems work and how to work with them in Linux. I just needed to solve the problem of displaying the signal level, checking the balance, replenishing the account using a 3g modem. But since I didn’t want to install PCH on home machines for such trifles, I decided to rewrite the script for myself in Python, which is in any Linux desktop out of the box.
This script will work on any modems / phones that support USSD without encoding PDU. For modems requiring PDU-encoding commands, you need to write wrapper functions similar to the php-script from the above topic. I unfortunately do not have such a modem and I could not check it - because I did not write.
The operation on the ZTE MF100 3G modem (should work with mf620, mf622, mf626, mf628) and the Internet 3G tariff from Kyivstar has been verified.
The script itself ussd.py
#! / usr / bin / python
import binascii
import sys
f = open ( "/ dev / ttyUSB2" , "r +" )
data = ''
error = "Usage: python ussd.py action (code) \ r \ n Actions: balans, popolnit, data-status, 3g-data-status, signal"
if len ( sys . argv ) < 2 :
print error
sys . exit ( )
')
if sys . argv [ 1 ] == 'balans' :
print >> f, "AT + CUSD = 1, * 111 #, 15 \ r \ n "
while data [ : 5 ] ! = "+ CUSD" :
data = f. readline ( )
data = data [ 10 : - 6 ]
print binascii . unhexlify ( data )
elif sys . argv [ 1 ] == 'signal' :
print >> f, "AT + CSQ \ r \ n "
while data [ : 5 ] ! = "+ CSQ:" :
data = f. readline ( )
data = data [ 6 : - 5 ]
sig_str = - 113 + int ( data ) * 2
sig_per = int ( data ) * 100/31
print unicode ( sig_str ) + "dBm /" + unicode ( sig_per ) + "%"
elif sys . argv [ 1 ] == 'popolnit' :
print >> f, "AT + CUSD = 1, * 123 *" + sys . argv [ 2 ] + "#, 15 \ r \ n "
while data [ : 5 ] ! = "+ CUSD" :
data = f. readline ( )
data = data [ 10 : - 6 ]
print binascii . unhexlify ( data )
elif sys . argv [ 1 ] == 'data-status' :
print >> f, "AT + CUSD = 1, * 121 #, 15 \ r \ n "
while data [ : 5 ] ! = "+ CUSD" :
data = f. readline ( )
data = data [ 10 : - 6 ]
print binascii . unhexlify ( data )
elif sys . argv [ 1 ] == '3g-data-status' :
print >> f, "AT + CUSD = 1, * 122 #, 15 \ r \ n "
while data [ : 5 ] ! = "+ CUSD" :
data = f. readline ( )
data = data [ 10 : - 6 ]
print binascii . unhexlify ( data )
else :
print error
f. close
Making the script executable:
chmod + x ussd.py
Using:./ussd.py action (code)
Available actions: balans, popolnit, data-status, 3g-data-status, signal
When selecting the popolnit action, the second parameter is to pass the refill code to the script.
Example:./ussd.py popolnit 1234567890
The script is sharpened by Kyivstar, but I think it would be easy for anyone to replace the short request numbers with those used by your operator.
Sometimes the script “freezes”, as I understand it, this happens when it never waits for the right answer from the modem. I sin on poor coverage in my area. If you have a script hangs just interrupt it and restart. Suspensions stopped as soon as the minicom closed.
Another important point, most 3g-modems under Linux are defined as 3 devices: / dev / ttyUSB0, / dev / ttyUSB1, / dev / ttyUSB2. One is used for data transmission, the other is similar for some modem command service, the third provides a standard COM interface for management. In the script you need to specify the device COM interface, in some modems it is / dev / ttyUSB0, less often / dev / ttyUSB2.
Depending on the capabilities of the modem and the tariff, you can get SMS sending, mode switching (2G / 3G), disable virtual sd-rm, etc., from the USSD operator with requests and AT commands. Unfortunately for each model will have to pick up the team manually ...
Unfortunately, I almost don’t know the python, because most likely the script is written far from the most optimal way, if someone takes it to optimize (and even better arrange it all in a graphical shell), I will be grateful and update the topic.
UPD I forgot to tell one more thing, the other day I found some kind of opsos that provides Linux software to its modems. Modems are naturally standard Chinese branded opsos.
Here, for example, ZTE MF100 / MF62X is clearly visible, but unfortunately I could not get the software to work with my modem. Maybe someone more experienced will be able to buy it? For its work, you need the libqt3-mt package for the i386 architecture (otherwise it will not start)