Advertisement
Guest User

Read USSD Response Python GsmModem

a guest
Oct 26th, 2015
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. from __future__ import print_function
  2. import logging
  3. PORT = 'COM11'
  4. BAUDRATE = 921600
  5. USSD_STRING = '*111#'
  6. PIN = None # SIM card PIN (if any)
  7.  
  8. from gsmmodem.modem import GsmModem
  9.  
  10. def main():
  11.     print('Initializing modem...')
  12.     modem = GsmModem(PORT, BAUDRATE)
  13.     modem.connect(PIN)
  14.     modem.waitForNetworkCoverage(10)
  15.     print('Sending USSD string: {0}'.format(USSD_STRING))
  16.     response = modem.sendUssd(USSD_STRING) # response type: gsmmodem.modem.Ussd
  17.     print('USSD reply received: {0}'.format(response.message))
  18.     if response.sessionActive:
  19.         print('Closing USSD session.')
  20.         # At this point, you could also reply to the USSD message by using response.reply()
  21.         response.cancel()
  22.     else:
  23.         print('USSD session was ended by network.')
  24.     modem.close()
  25.  
  26. if __name__ == '__main__':
  27.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement