> For the complete documentation index, see [llms.txt](https://docs.eseye.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eseye.com/smartconnect/at-command-reference/mqtt-at-commands/emqpubopen-create-a-publish-message-topic.md).

# EMQPUBOPEN – create a publish message topic

Create and view publish message topics, which will enable you to publish data to things in the cloud.

{% hint style="info" %}
The topic name depends on the MQTT `<topicsuffix>` parameter, unless a token is used. For more information, see the \[MQTT] section, [Using the AnyNet SMARTconnect™ configuration file](/smartconnect/getting-started/using-the-anynet-smartconnect-tm-configuration-file.md).
{% endhint %}

You can use the following tokens to construct the topic name:

* `$t` – returns the cloud thingName
* `$i` – returns the device International Mobile Equipment Identity (IMEI) number

For example, `status/$i` publishes as `status/<IMEI>`

{% hint style="info" %}
You can only include one token in a topic.
{% endhint %}

| Type      | Syntax                                      | Response                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------- | ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Test**  | `AT+EMQPUBOPEN=?`                           | <p><code>+EMQPUBOPEN: (0-7),\<topic></code></p><p><code>OK</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **Read**  | `AT+EMQPUBOPEN?`                            | <p>List of publish topics.</p><p><code>0: \<publishtopic0>/<\[mqtt] topicsuffix></code></p><p><code>1: \<publishtopic1>/<\[mqtt] topicsuffix></code></p><p><code>OK</code></p><p>where:</p><ul><li>0, 1, and so on are the index numbers</li><li><code>\<publishtopicn></code> is the unique name for each publish index</li><li><p><code><\[mqtt] topicsuffix></code> is the appended topic path. For more information, see <a href="/smartconnect/getting-started/using-the-anynet-smartconnect-tm-configuration-file.md">topicsuffix</a>.</p><p><code><\[mqtt] topicsuffix></code> may comprise of <code>$i</code> (IMEI) or <code>$t</code> (cloud thingName).</p><p><code>$t</code> has the following maximum lengths:</p><ul><li>AWS – 128 characters</li><li>Google – 255 characters</li></ul><p><strong>Note:</strong> The sum of <code>\<publishtopicn></code> and <code><\[mqtt] topicsuffix></code> must not exceed the maximum size allowed by the MQTT broker, which is 256 characters for both AWS and Google.</p></li><li>The Quectel module does not report empty topics.</li></ul> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **Write** | <p><code>AT+EMQPUBOPEN=(0-7),"\<topic>/\[$t | $i]"</code></p><p>where:</p><ul><li><code>(0-7)</code> is a publish index number in the range from 0, up to and including 7.</li><li><code>\<topic></code> is the publish topic title with a maximum length of 256 characters (including /cloudThingName or /IMEI). Topic titles cannot contain special characters.</li><li><code>$t</code> or <code>$i</code> are optional values, described above.</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | <p><code>OK</code></p><p><code>+EMQPUBOPEN: (0-7),\<status></code></p><p>where</p><ul><li><code>(0-7)</code> is the publish index number you selected from the range</li><li><p><code>\<status></code> is:</p><ul><li><code>0</code> – successfully installed the publish topic</li><li><code>-2</code> – publish index already in use</li></ul></li></ul><p>or</p><p><code>+ETM ERROR: \<errormessage></code> – returned for an AT command-specific error.</p><p>or</p><p><code>ERROR</code> – returned when a command is invalid, for example a parameter is missing or incorrect</p><p><strong>Tip:</strong> Check you have sent the <code>AT+ETMSTATE="startmqtt"</code> command to enable MQTT.</p> |

#### Examples

```
AT+EMQPUBOPEN=0,"PublishToCloud0/$i"
OK

+EMQPUBOPEN: 0,0

AT+EMQPUBOPEN=1,"PublishToCloud1"
OK

+EMQPUBOPEN: 1,0

AT+EMQPUBOPEN?
0: PublishToCloud0/862061040777777
1: PublishToCloud1/AWSthingName

OK

AT+EMQPUBLISH=0,1,"{\"imei\":\"$i\",\"user\":\"1\",\"sys\":\"128\",\"dia\":\"112\",\"pul\":\"075\",\"ano\":\"0\",\"time\":\"2023/11/30,20:10:12-20\",\"ver\":\"BP01_2.0\",\"devdata\":{\"r\":$r,\"rat\":\"$a\",\"mcc\":$c,\"mnc\":$n,\"imsi\":$s,\"batt\":87}}"
OK
:SEND OK
```

In the last example, the MQTT broker receives:

```
{
"imei": "867730056224474",
"user": "1",
"sys": "128",
"dia": "112",
"pul": "075",
"ano": "0",
"time": "2023/11/30,20:10:12-20",
"ver": "BP01_2.0",
"devdata": {
  "r": -68,
  "rat": "eMTC",
  "mcc": 310,
  "mnc": 230,
  "imsi": 302760007540320,
  "batt": 87
  }
}
```

{% hint style="success" %}
For useful AWS information regarding maximum lengths, see: [AWS IoT Core endpoints and quotas](https://docs.aws.amazon.com/general/latest/gr/iot-core.html).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.eseye.com/smartconnect/at-command-reference/mqtt-at-commands/emqpubopen-create-a-publish-message-topic.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
