Exemplo n.º 1
0
def sendSMS(theSmsMsg,theDestination,theTerminator,retry,timeOut):
#This function sends an SMS Message

  # Input Parameter Definitions
  #   theSmsMsg: The text SMS Message
  #   theTerminator: string or character at the end of AT Command
  #   retry:  How many times the command will attempt to retry if not successfully send 
  #   timeOut: number of [1/10 seconds] command could take to respond

  #Note that the 145 being sent in with the destination address is the "type" of destination address, with 145 including a "+" for international
  while (retry != -1):
    print 'AT+CMGS="' + str(theDestination) + '",145'

    res = MDM.send('AT+CMGS="' + str(theDestination) + '",145', 0)
    res = MDM.sendbyte(0x0d, 0)
    res = ATC.mdmResponse('\r\n>', timeOut)
    print res 

    res = MDM.send(theSmsMsg, 0)
    res = MDM.sendbyte(0x1a, 0)

    #Wait for AT command response
    res = ATC.mdmResponse(theTerminator, timeOut)
      
    #Did AT command respond without error?
    pos1 = res.rfind(theTerminator,0,len(res))
    if (pos1 != -1):
      retry = -1
      res = ATC.parseResponse(res)
    else:
      retry = retry - 1
     
    print res

  #If the function fails to find the proper response to the SMS send ('OK<cr><lf>') then we receive a timeout string: 'timeOut'  
  return res