title: +CME ERROR: invalid paremeter
body: <p>I'm trying to send SMS from my RaspberryPi using my own script in python. I'm using serial port on GPIO on the RPi to communicate with GSM modem. I have selected TEXT MODE sms format, listed smses, etc and it all works fine until it comes to sending a sms. When I want to send it I get error like in the tittle.</p>
  
  <p>To quit sending a message I press esc button, press enter (to send it via serial) and it works great (modem sends back 'OK')
  I know that to send a message, after the message content I have to send ctrl-z. Ofc in linux when i press ctrl-z i stop the program so it's impossible to press those keys and then enter. Thats why i made a function to send sms where i put ctrl-z char/sign.</p>
  
  <p>When i run the program modem responds with an error like in the tittle(+CME ERROR: invalid paremeter or if you'd like the error code: +CME ERROR: 3518) I know this may seem stupid but I've been looking for an answer for two days and I've tried chr(26).encode(), "\x1a", "\x1A" (don't even know if there's a difference), I've tried to send it with a message content, separatly but nothing works</p>
  
  <p>I may do something wrong but I have no idea what. So I post some code and datasheet screen how to send a message.
  Sending a sms:</p>
  
  <pre><code>def sendSMS(self, phoneNumber=111111111, smsContent=""):
      # if phoneNumber==0:
      if phoneNumber!=111111111:
          print("Type phone number in: (without prefix +48): ", end="")
          phoneNumber = input()
          try:
              phoneNumber = int(phoneNumber)
          except Exception:
              print("Type in an integer")
              time.sleep(1)
              self.sendSMS()
      print("Type text message content (press ENTER to send): ")
      smsContent = str(input())
      char_CtrlZ = "\x1a"
      quote = "\""
      command = "AT+CMGS=" + quote + str(phoneNumber) + quote + "," + quote + "129" + quote
      message = smsContent + char_CtrlZ
      self.serialConnection.send(command)
      time.sleep(1)
      self.serialConnection.receive()
      time.sleep(1)
      if self.checkModemResponse()==True: #here I send empty string (few times, if needed) until modem responses with '&gt;'
          print("No '&gt;' in modem response")
          print("Message did not send")
      else:
          self.serialConnection.send(message, True, False)
          time.sleep(2)
          self.serialConnection.receive(True, True, True)
          time.sleep(1)
          if self.serialConnection.responseState=="COMPLETE_OK":
              print("Your message has been sent!")    
  
  def checkModemResponse(self, attempt=3):
      #I have 5 states of response: UNKNOWN; COMPLETE_OK - modem responses with OK; COMPLETE_ERROR - modem responses with ERROR; UNCOMPLETE - modem responses correctly but without ERROR or OK; EMPTY modem responds correctly but with empty string
      isUncomplete = True
      if self.serialConnection.responseState!="UNCOMPLETE":
          isUncomplete = False
          attempt -= 1
          if attempt &gt; 0:
              print("Trying again..")
              someString = "attempt: " + str(attempt)
              self.serialConnection.send(someString)
              time.sleep(1)
              self.serialConnection.receive(True, True, True)
              time.sleep(1)
              if self.serialConnection.responseState!="UNCOMPLETE":
                  self.checkModemResponse(attempt)
      return isUncomplete
  </code></pre>
  
  <p>And sending a command over serial:</p>
  
  <pre><code>def send(self, messageToSend, printWhatIsSent=True, addCR=True):
      if addCR==False:
          command = messageToSend
      else:
          command = messageToSend + "\r"
      if self.serialState==self.SERIAL_STATE[IDLE] and self.serialConnection.isOpen():
          self.responseState = self.RESPONSE_STATE[UNKNOWN]
          self.serialState = self.SERIAL_STATE[SENDING]
          commandToSendInBytes = self.str2byte(command)
          self.serialConnection.write(commandToSendInBytes)
          self.serialState = self.SERIAL_STATE[IDLE]
          if printWhatIsSent==True:
              print("&gt;&gt;&gt;&gt;&gt; command sent: " + messageToSend)
      else:
          print("!!!ERROR: COMMAND DID NOT SEND!!!")
      self.serialConnection.flushOutput()
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/ICQab.jpg" rel="nofollow">How to send an SMS: +CMGS datesheet screenshot</a></p>