title: How to connect a sim800l to a broker with SSL?
body: <p>I am trying to connect to an a mosquito broker hosted on AWS, on port 8883, but so far I have not been successful.
  I am using the TinyGSM and PubSubClient libraries.</p>
  <p>The GSM module is connected to the internet and works perfectly in a broker without SSL. But when I try to switch to SSL, he can't connect and the MQTT client returns -2. But this error is not very clear, as you can see <a href="https://github.com/knolleary/pubsubclient/blob/2d228f2f862a95846c65a8518c79f48dfc8f188c/src/PubSubClient.h#L47" rel="nofollow noreferrer">here</a> in the PubSub documentation.</p>
  <blockquote>
  <p>#define MQTT_CONNECT_FAILED         -2</p>
  </blockquote>
  <p>These are the AT commands that it performs to try to connect to the broker</p>
  <pre><code>AT+CIPRXGET=4,0
  
  +CIPRXGET: 4,0,0
  
  OK
  AT+CIPSTATUS=0
  
  +CIPSTATUS: 0,0,&quot;TCP&quot;,&quot;3.13.162.221&quot;,&quot;8883&quot;,&quot;CLOSED&quot;
  
  OK
  * Trying to connect to the MQTT Broker: &lt;broker_url&gt;
  AT+CIPCLOSE=0,1
  
  ERROR
  AT+CIPSSL=1
  
  OK
  AT+CIPSTART=0,&quot;TCP&quot;,&lt;broker_url&gt;,8883
  
  OK
  Failed to reconnect to the broker.
  Status: -2
  </code></pre>
  <p>Some useful parts of the code</p>
  <pre><code>void setupGSM() {
    SerialMon.println(&quot;Setup GSM...&quot;);
    
    modem.sendAT(&quot;+SSLOPT=1,1&quot;);
    if (modem.waitResponse() != 1) {
      SerialMon.printf(&quot;modem +SSLOPT=1,1 failed&quot;);
    }
    while (!modem.gprsConnect(APN, APN_USER, APN_KEY)) {
      SerialMon.println(&quot;GPRS Connection Failed&quot;);
      modem.restart();
      delay(1000);
    }
    SerialMon.println(&quot;GPRS Connection Success&quot;);
  }
  
  void reconnectMQTT() {
    while (!MQTT.connected()) {
      SerialMon.print(&quot;* Trying to connect to the MQTT Broker: &quot;);
      SerialMon.println(BROKER_MQTT);
      initMQTT();
  
      if (MQTT.connect(ID_MQTT, MQTT_USERNAME, MQTT_KEY)) {
        SerialMon.println(&quot;Successfully connected to the MQTT broker!&quot;);
        MQTT.subscribe(RECEIVED_CREDITS);
      }
      else {
        SerialMon.println(&quot;Failed to reconnect to the broker.&quot;);
        SerialMon.print(&quot;Status: &quot;);
        SerialMon.println(MQTT.state());
        delay(2000);
      }
    }
  }
  </code></pre>
  <p>The question is, how can I connect to an MQTT broker with SSL using the sim800l module?</p>
  <p><strong>Info</strong>: <br>
  Modem: SIMCOM_SIM800L R14.18<br>
  Main processor board: TTGO-T-Call ESP32<br>
  TinyGSM Version: 0.10.5<br></p>