# MQTT+AWS IoT Core

Follow these detailed steps to establish a secure connection and send data from your Ruuvi Gateway to AWS IoT Core using MQTT. This setup uses MQTT over SSL/TLS for encrypted data transmission, ensuring secure communication.

1. **Select MQTT Transport Type**:
   * For the transport type, choose **"MQTT over SSL"**. This option encrypts the data, providing a secure connection to AWS IoT Core.
2. **Configure Server Address**:
   * Input your AWS endpoint as the **Server Address**. You can find your unique AWS endpoint in the AWS IoT Core console under the Settings section.
3. **Set Communication Port**:
   * Specify **8883** as the port. This is the standard port for MQTT over SSL, ensuring encrypted communication.
4. **Configure Client ID**:
   * Input the **Client ID** provided by AWS, which uniquely identifies your Ruuvi Gateway. You will find this ID in the AWS IoT Core console, formatted as **"iotconsole-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"**. The Client ID ensures AWS IoT Core correctly recognizes and manages your device's connection.
5. **Important: Disable Retained Messages**:
   * Due to AWS's policy, enabling retained messages can cause AWS IoT Core to immediately close the connection upon receiving the Last Will and Testament (LWT) message. Therefore, it is crucial to **disable the use of retained messages** to maintain a stable connection. This step prevents potential disruptions and ensures continuous data transmission to AWS IoT Core.
6. **Configure SSL/TLS Certificates**:
   * Enable **"Use client SSL certificate"**.
     * Upload the **Client Certificate File** (.crt) and the **Client Private Key File** (.key) provided by AWS when you registered your device.
   * Enable **"Use custom SSL certificate for the server"**.
     * Upload the **Server SSL Certificate**. This is usually the Amazon Root CA 1 certificate available from AWS documentation.
7. **Select Data Format**:
   * Choose the preferred format for the data you are sending to AWS IoT Core. Options typically include:
     * **Raw Data**: Sends the data as collected by sensors without processing.
     * **Decoded Data**: Sends data that has been processed or formatted.
     * **Both**: Sends both raw and decoded data, providing comprehensive information.

<figure><img src="/files/BARXSFLHxy1mFUQLVSEg" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ruuvi.com/ruuvi-gateway-firmware/examples/mqtt+aws-iot-core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
