# API | MQTT

## MQTT

MQTT[\[1\]](#references) (MQ Telemetry Transport atau Message Queue Telemetry Transport) merupakan standar ISO (ISO/IEC PRF 20922)[\[2\]](#references) berbasis publish-subscribe yang ringan dan dapat bekerja pada protokol TCP/IP. Ada 5 metode MQTT yaitu **Connect, Disconnect, Subscribe, Unsubscribe, dan Publish.**

* **Connect:** Menunggu sampai koneksi dibangun dengan server .
* **Disconnect:** Menunggu client MQTT untuk menyelesaikan tugasnya, dan juga menunggu pemutusan sesi TCP/IP.
* **Subscribe:** Meminta server untuk unsubscribe pada satu atau banyak topik.
* **Unsubscribe:** Meminta server untuk unsubscribe pada satu atau banyak topik.
* **Publish:** Kembali ke thread aplikasi setelah melempar request ke client MQTT.

<figure><img src="/files/JtgtARp70UwsbhswCwCt" alt=""><figcaption><p>Architecture of MQTT Communication</p></figcaption></figure>

### **Topic** <a href="#mqtt-topic" id="mqtt-topic"></a>

Komunikasi MQTT didasari oleh topik. Topik digunakan untuk memisahkan satu kanal komunikasi dengan kanal lainnya. Spesifikasi teknis oneM2M sudah menyediakan topik khusus yang harus digunakan untuk komunikasi MQTT. Publikasi harus dilakukan pada topik yang spesifik dan respons juga akan diberikan pada topik berbeda yang sudah disediakan sebelumnya.

### **Publish/Request topic**

Bentuk topik request:

<mark style="color:red;">`/oneM2M/req/your-access-key/antares-cse/choose-a-serialization-format`</mark>

### **Subscribe/Response topic**

Bentuk topik respons:

<mark style="color:red;">`/oneM2M/resp/antares-cse/your-access-key/choose-a-serialization-format`</mark>

### **Note**

<mark style="color:red;">`your-access-key`</mark> adalah access key akun anda. <mark style="color:red;">`choose-a-serialization-format`</mark> dapat berisi 2 nilai:

* <mark style="color:red;">`xml`</mark> untuk format XML
* <mark style="color:red;">`json`</mark> untuk format JSON

### **MQTT Broker** <a href="#mqtt-broker" id="mqtt-broker"></a>

<table><thead><tr><th width="195">Field</th><th>Value</th></tr></thead><tbody><tr><td><mark style="color:red;"><code>Host</code></mark></td><td>mqtt.antares.id</td></tr><tr><td><mark style="color:red;"><code>Port</code></mark></td><td>1883</td></tr></tbody></table>

### **MQTT Payload** <a href="#mqtt-payload" id="mqtt-payload"></a>

Payload yang dikirim ke topik MQTT adalah RequestPrimitive dan ResponsePrimitive yang telah dilakukan serialisasi. Data-data dikirimkan pada RequestPrimitive dan yang nantinya akan diterima oleh ResponsePrimitive.

Beberapa parameter utamanya adalah:

<table data-header-hidden><thead><tr><th width="213.33333333333331"></th><th width="211"></th><th></th></tr></thead><tbody><tr><td><strong>Singkatan Parameter</strong></td><td><strong>Nama parameter</strong></td><td><strong>Kegunaan</strong></td></tr><tr><td><mark style="color:red;"><code>fr</code></mark></td><td>From</td><td>Sumber request</td></tr><tr><td><mark style="color:red;"><code>to</code></mark></td><td>To</td><td>Penerima request</td></tr><tr><td><mark style="color:red;"><code>op</code></mark></td><td>Operation</td><td>Operasi untuk melakukan perintah <code>(</code><mark style="color:red;"><code>CREATE, RETRIEVE</code></mark><code>, ...)</code></td></tr><tr><td><mark style="color:red;"><code>rqi</code></mark></td><td>Request Identifier</td><td>ID korelasi antara request dan response</td></tr><tr><td><mark style="color:red;"><code>pc</code></mark></td><td>Primitive Content</td><td>Konten request (contoh: resource untuk dibuat)</td></tr><tr><td><mark style="color:red;"><code>ty</code></mark></td><td>Type</td><td>Tipe resource untuk dibuat</td></tr><tr><td><mark style="color:red;"><code>rsc</code></mark></td><td>Response Status Code</td><td>Kode status respons oneM2M</td></tr></tbody></table>

Berikut adalah beberapa operation value:

<table data-header-hidden><thead><tr><th width="346"></th><th></th></tr></thead><tbody><tr><td><strong>Operation</strong></td><td><strong>Value</strong></td></tr><tr><td><mark style="color:red;"><code>CREATE</code></mark></td><td>1</td></tr><tr><td><mark style="color:red;"><code>RETRIEVE</code></mark></td><td>2</td></tr><tr><td><mark style="color:red;"><code>UPDATE</code></mark></td><td>3</td></tr><tr><td><mark style="color:red;"><code>DELETE</code></mark></td><td>4</td></tr><tr><td><mark style="color:red;"><code>NOTIFY</code></mark></td><td>5</td></tr><tr><td><mark style="color:red;"><code>CREATE</code></mark></td><td>6</td></tr></tbody></table>

{% content-ref url="/spaces/SG57S3sc1YOZETuRdW3k/pages/cWIKmFJIXK5emstoxum2" %}
[Broken mention](broken://spaces/SG57S3sc1YOZETuRdW3k/pages/cWIKmFJIXK5emstoxum2)
{% endcontent-ref %}

{% content-ref url="/spaces/SG57S3sc1YOZETuRdW3k/pages/fUvecBeX9myJLHWZobUF" %}
[Broken mention](broken://spaces/SG57S3sc1YOZETuRdW3k/pages/fUvecBeX9myJLHWZobUF)
{% endcontent-ref %}

### **Referensi** <a href="#references" id="references"></a>

1. ["MQTT 3.1.1 specification"](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html). [OASIS](https://en.wikipedia.org/wiki/OASIS_\(organization\)). December 10, 2015. Retrieved April 25, 2017.
2. ["ISO/IEC 20922:2016 Information technology -- Message Queuing Telemetry Transport (MQTT) v3.1.1".](https://www.iso.org/standard/69466.html)iso.org.[International Organization for Standardization.](https://en.wikipedia.org/wiki/International_Organization_for_Standardization) June 15, 2016.


---

# 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.antares.id/api-or-mqtt.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.
