faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
384 stars 302 forks source link

Fix / Improve USSD error handling #43

Open jthurner opened 9 years ago

jthurner commented 9 years ago

According to the GSM spec, USSD responses can have the following status codes:

0 no further user action required (network initiated USSD-Notify, or no further information needed after mobile initiated operation) 1 further user action required (network initiated USSD-Request, or further information needed after mobile initiated operation) 2 USSD terminated by network 3 other local client has responded 4 operation not supported 5 network time out

I've never seen 0 or 3, but the 4s and 5s don't have any message text fields (e.g. +CUSD: 4). This response isn't matched by the cusd regex, which leads to a nullpointer exception in parseCusdResponse.

Also, having access to the statuscodes would be nice, to be able to differentiate between a network timeout and unsopperted operation.

I've made a rough patch which changes the second regex group to optional (improvements welcome...), adds the statuscode as variable to USSD() and changes sessionActive to a property.

However, I am unsure how to adapt this if block. It looks to me like that is basically setting the message to the last CUSD indication with statuscode !=2. Is that really intended behaviour? Because in the "normal" case, statuscode 2 is what you get for succesfull "oneshot" USSD commands (e.g. checking credit).

appsquareco commented 9 years ago

Hi jthurner, When i call the modem.sendUssd() method. Below is the output.

DEBUG: write: AT+CUSD=1,*126#,15
DEBUG: response: ['OK']
DEBUG: notification: ['+CME ERROR: 261']
DEBUG: Unhandled unsolicited modem notification: ['+CME ERROR: 261']

CME ERROR: 261 ( ss not executed ) Any idea what's going on? Thanks.

When i test it on a phone. The USSD code seems to be working by returning the card balance.

marutichintan commented 8 years ago

The AT command should be AT+CUSD=1,"*126#",15