neumotngayem
Posts: 11
Joined: Sat Jul 28, 2018 2:21 am

AT Command return has been corrupted

Thu Aug 02, 2018 2:04 am

Hi everyone, I am coding the python script for check balance of the sim on module GSM A6, here is my python code:

Code: Select all

port = serial.Serial("/dev/ttyAMA0",baudrate=9600,timeout=1)

port.write('AT+CMGF=0'+'\r\n')
time.sleep(2)
port.write('AT+CSCS="HEX"'+'\r\n')
time.sleep(2)
port.write('AT+CUSD=1,"*101#",15'+'\r\n')
time.sleep(60)
while True:
    if port.inWaiting() > 0:
        reply = port.readline()
        if '+CUSD:' in reply:
            reply = reply[reply.find(',"'):reply.find('",')]
            print reply
    else:
        break
port.flushInput()
port.flushOutput()
port.close()
What I get is like that:

Code: Select all

+CUSD: 1, "D8B41B344687DF20580C879BC56A��MN�&���
How can I fix that :?

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: AT Command return has been corrupted

Thu Aug 02, 2018 7:45 am

It's returning 7-bit data. You need to convert that to 8-bit to make sense of it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

neumotngayem
Posts: 11
Joined: Sat Jul 28, 2018 2:21 am

Re: AT Command return has been corrupted

Thu Aug 02, 2018 12:48 pm

DougieLawson wrote:
Thu Aug 02, 2018 7:45 am
It's returning 7-bit data. You need to convert that to 8-bit to make sense of it.
Can you suggest me how to do that or the key word to find the solution ?

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:27 pm

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

neumotngayem
Posts: 11
Joined: Sat Jul 28, 2018 2:21 am

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:33 pm

This is how to translate it, but the respone of my is corrupted when I read from serial :(
+CUSD: 1, "D8B41B344687DF20580C879BC56A��MN�&���

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:41 pm

Repeating your original question doesn't seem very productive...

What do you expect the returned data to say? What values or quantities are represented by the <?> placeholder symbols?

neumotngayem
Posts: 11
Joined: Sat Jul 28, 2018 2:21 am

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:46 pm

B.Goode wrote:
Thu Aug 02, 2018 1:41 pm
Repeating your original question doesn't seem very productive...

What do you expect the returned data to say? What values or quantities are represented by the <?> placeholder symbols?
oh no, this situation is like that, I try to get the response of the serial, this is the full respone:
+CUSD: 1, "D8B41B344687DF20580C879BC56AB8586EA6A02E873A500CE79AD56E64450CD4AC8741E7771A4445BFC369903D0C9A36A70A19A8590F83CEEF348818A687153350B31E0691D36334C85E0739D1E131688C7E2B68A0633A9C06D1E56910F2495500" ,15
But as you can see above this is corrupted, some time I can get the full response and some time I can't, I don't know what happend with that

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:50 pm

You need to decode it from 7-bit GSM USSD to 8-bit ASCII. It will then print without any errors.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

neumotngayem
Posts: 11
Joined: Sat Jul 28, 2018 2:21 am

Re: AT Command return has been corrupted

Thu Aug 02, 2018 1:56 pm

DougieLawson wrote:
Thu Aug 02, 2018 1:50 pm
You need to decode it from 7-bit GSM USSD to 8-bit ASCII. It will then print without any errors.
But how come I decode it when the orginal 7-bit GSM USSD data is corrupted already :(

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: AT Command return has been corrupted

Thu Aug 02, 2018 5:42 pm

The stuff you posted on here isn't corrupted. It decodes as:

Code: Select all

Xin chao 0188???????
TKC: 18.357d
1 Mua goi Thoai va SMS
2 Mua goi Data
3 Mua dich vu Nhac cho
4 Giai tri HOT
Note: I've redacted the bit that looks like your phone number.

Online decoder here: http://smstools3.kekekasvi.com/topic.php?id=288
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Python”