title: Raspberry Pi (Python): Send SMS using SIM800L
body: <ul>
  <li>Raspberry Pi 3 </li>
  <li>Python 2.7</li>
  <li><a href="https://i.stack.imgur.com/VRJkb.jpg" rel="nofollow noreferrer">Sim800L</a></li>
  </ul>
  
  <p>Hi!
  I am getting errors connecting to the gsm module</p>
  
  <p>Here's the code I got from <a href="http://www.rhydolabz.com/wiki/?p=10450" rel="nofollow noreferrer">rhydolabz</a></p>
  
  <pre><code>import serial
  import RPi.GPIO as GPIO     
  import os, time
  
  GPIO.setmode(GPIO.BOARD)   
  
  # Enable Serial Communication
  port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
  
  # Transmitting AT Commands to the Modem
  # '\r\n' indicates the Enter key
  
  port.write('AT'+'\r\n')
  rcv = port.read(10)
  print rcv
  time.sleep(1)
  
  port.write('ATE0'+'\r\n')      # Disable the Echo
  rcv = port.read(10)
  print rcv
  time.sleep(1)
  
  port.write('AT+CMGF=1'+'\r\n')  # Select Message format as Text mode
  rcv = port.read(10)
  print rcv
  time.sleep(1)
  
  port.write('AT+CNMI=2,1,0,0,0'+'\r\n')   # New SMS Message Indications
  rcv = port.read(10)
  print rcv
  time.sleep(1)
  
  # Sending a message to a particular Number
  
  port.write('AT+CMGS="+6xxxxxxxxx68"'+'\r\n')
  rcv = port.read(10)
  print rcv
  time.sleep(1)
  
  port.write('Hello User'+'\r\n')  # Message
  rcv = port.read(10)
  print rcv
  
  port.write("\x1A") # Enable to send SMS
  for i in range(10):
      rcv = port.read(10)
      print rcv
  </code></pre>
  
  <p>Here are the errors:</p>
  
  <pre><code>OSError: [Errno 11] Resource temporarily unavailable
  
  raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
  serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)
  
  raise SerialException('write failed: %s' % (v,))
  serial.serialutil.SerialException: write failed: [Errno 5] Input/output error
  </code></pre>
  
  <p>Sometimes It sends</p>
  
  <pre><code>Hello User
  Login incorrect
  raspberrypi login:
  </code></pre>
  
  <p>Sometimes</p>
  
  <pre><code>&gt;
  &gt;
  &gt; 
  (100+ more '&gt;')
  Hello User
  </code></pre>
  
  <p>but almost always it doesn't connect and it gives Error 11</p>
  
  <p>Have you experience this too?
  Is there a way I can wait for the gsm to connect before I proceed on sending a message?</p>