MQTT参数命令
<p>[TOC]</p>
<table>
<thead>
<tr>
<th>4G喇叭</th>
<th>4G开关</th>
<th>WiFi喇叭</th>
<th>WiFi开关</th>
</tr>
</thead>
<tbody>
<tr>
<td><font color="green"><strong>&radic;</strong></font></td>
<td><font color="green"><strong>&radic;</strong></font></td>
<td><font color="green"><strong>&radic;</strong></font></td>
<td><font color="green"><strong>&radic;</strong></font></td>
</tr>
</tbody>
</table>
<p>支持此功能的设备类型:<font color="green"><strong>&radic;</strong></font>-支持 <font color="red"><strong>&times;</strong></font>-不支持</p>
<h2>获取MQTT参数(getMqtt)</h2>
<p><strong>简要描述</strong>
获取MQTT参数。</p>
<p><strong>命令参数</strong></p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必须</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>method</td>
<td>是</td>
<td>string</td>
<td>getMqtt</td>
</tr>
<tr>
<td>frameId</td>
<td>否</td>
<td>string</td>
<td>帧ID</td>
</tr>
</tbody>
</table>
<p><strong>命令示例</strong></p>
<pre><code>{
&quot;method&quot;: &quot;getMqtt&quot;,
&quot;frameId&quot;: &quot;1745396239780&quot;
}</code></pre>
<p><strong>应答参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>method</td>
<td>string</td>
<td>getMqtt</td>
</tr>
<tr>
<td>result</td>
<td>string</td>
<td>返回结果。ok-成功;其他-具体失败原因</td>
</tr>
<tr>
<td>mqttParams</td>
<td>object</td>
<td>mqtt参数对象</td>
</tr>
<tr>
<td>imei</td>
<td>string</td>
<td>设备imei</td>
</tr>
<tr>
<td>frameId</td>
<td>string</td>
<td>同命令frameId</td>
</tr>
<tr>
<td>timestamp</td>
<td>int</td>
<td>秒级时间戳,WiFi款不支持</td>
</tr>
</tbody>
</table>
<ul>
<li>mqttParams - mqtt参数对象说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>host</td>
<td>string</td>
<td>MQTT 服务器地址(如域名或 IP,例:mqtt.example.com)</td>
</tr>
<tr>
<td>port</td>
<td>int</td>
<td>MQTT 服务器端口(例:1883 或 8883(SSL))</td>
</tr>
<tr>
<td>username</td>
<td>string</td>
<td>MQTT 服务器连接用户名</td>
</tr>
<tr>
<td>password</td>
<td>string</td>
<td>MQTT 服务器连接密码</td>
</tr>
<tr>
<td>clientID</td>
<td>string</td>
<td>客户端唯一标识,<code>%imei%</code> 为设备 IMEI 动态替换字段</td>
</tr>
<tr>
<td>cleanSession</td>
<td>bool</td>
<td>是否启用干净会话(<code>true</code> 表示清除历史会话状态;<code>false</code> 表示保留)</td>
</tr>
<tr>
<td>keepAlive</td>
<td>int</td>
<td>心跳间隔时间(秒),用于维持与服务器的连接</td>
</tr>
<tr>
<td>subscribeTopic</td>
<td>string</td>
<td>设备订阅消息的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>subscribeQos</td>
<td>int</td>
<td>订阅主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>publishTopic</td>
<td>string</td>
<td>设备发布消息的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>publishQos</td>
<td>int</td>
<td>发布主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>publishRetain</td>
<td>bool</td>
<td>发布消息时是否设为保留消息(<code>true</code> 表示保留,<code>false</code> 表示不保留)</td>
</tr>
<tr>
<td>willTopic</td>
<td>string</td>
<td>遗嘱消息发送的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>willQos</td>
<td>string</td>
<td>遗嘱主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>willRetain</td>
<td>bool</td>
<td>遗嘱消息是否设为保留消息(<code>true</code> 保留,<code>false</code> 不保留)</td>
</tr>
<tr>
<td>will</td>
<td>string</td>
<td>遗嘱消息内容,<code>%imei%</code> 动态替换为设备 IMEI(设备异常离线时发送至 <code>willTopic</code>)</td>
</tr>
</tbody>
</table>
<p><strong>应答示例</strong></p>
<pre><code>{
&quot;mqttParams&quot;: {
&quot;password&quot;: &quot;********&quot;,
&quot;host&quot;: &quot;********&quot;,
&quot;clientID&quot;: &quot;%imei%&quot;,
&quot;publishRetain&quot;: false,
&quot;cleanSession&quot;: true,
&quot;username&quot;: &quot;********&quot;,
&quot;willQos&quot;: 1,
&quot;publishQos&quot;: 1,
&quot;will&quot;: &quot;{\&quot;method\&quot;:\&quot;close\&quot;,\&quot;imei\&quot;:\&quot;%imei%\&quot;}&quot;,
&quot;port&quot;: 10000,
&quot;publishTopic&quot;: &quot;/iot/server/iot-board/%imei%&quot;,
&quot;subscribeTopic&quot;: &quot;/iot/client/iot-board/%imei%&quot;,
&quot;subscribeQos&quot;: 1,
&quot;willRetain&quot;: false,
&quot;willTopic&quot;: &quot;/iot/server/iot-board/%imei%&quot;,
&quot;keepAlive&quot;: 30
},
&quot;imei&quot;: &quot;864536072949900&quot;,
&quot;method&quot;: &quot;getMqtt&quot;,
&quot;timestamp&quot;: 1745478194,
&quot;result&quot;: &quot;ok&quot;,
&quot;frameId&quot;: &quot;1745478194596&quot;
}</code></pre>
<p><strong>备注</strong>
无</p>
<h2>设置MQTT参数(setMqtt)</h2>
<p><strong>简要描述</strong>
设置MQTT参数。</p>
<p><strong>命令参数</strong></p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必须</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>method</td>
<td>是</td>
<td>string</td>
<td>setMqtt</td>
</tr>
<tr>
<td>mqttParams</td>
<td>是</td>
<td>object</td>
<td>mqtt参数对象</td>
</tr>
<tr>
<td>frameId</td>
<td>否</td>
<td>string</td>
<td>帧ID</td>
</tr>
</tbody>
</table>
<ul>
<li>mqttParams - mqtt参数对象说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数名</th>
<th>必须</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>host</td>
<td>是</td>
<td>string</td>
<td>MQTT 服务器地址(如域名或 IP,例:mqtt.example.com)</td>
</tr>
<tr>
<td>port</td>
<td>是</td>
<td>int</td>
<td>MQTT 服务器端口(例:1883 或 8883(SSL))</td>
</tr>
<tr>
<td>username</td>
<td>是</td>
<td>string</td>
<td>MQTT 服务器连接用户名</td>
</tr>
<tr>
<td>password</td>
<td>是</td>
<td>string</td>
<td>MQTT 服务器连接密码</td>
</tr>
<tr>
<td>clientID</td>
<td>是</td>
<td>string</td>
<td>客户端唯一标识,<code>%imei%</code> 为设备 IMEI 动态替换字段</td>
</tr>
<tr>
<td>cleanSession</td>
<td>是</td>
<td>bool</td>
<td>是否启用干净会话(<code>true</code> 表示清除历史会话状态;<code>false</code> 表示保留)</td>
</tr>
<tr>
<td>keepAlive</td>
<td>是</td>
<td>int</td>
<td>心跳间隔时间(秒),用于维持与服务器的连接</td>
</tr>
<tr>
<td>subscribeTopic</td>
<td>是</td>
<td>string</td>
<td>设备订阅消息的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>subscribeQos</td>
<td>是</td>
<td>int</td>
<td>订阅主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>publishTopic</td>
<td>是</td>
<td>string</td>
<td>设备发布消息的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>publishQos</td>
<td>是</td>
<td>int</td>
<td>发布主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>publishRetain</td>
<td>是</td>
<td>bool</td>
<td>发布消息时是否设为保留消息(<code>true</code> 表示保留,<code>false</code> 表示不保留)</td>
</tr>
<tr>
<td>willTopic</td>
<td>是</td>
<td>string</td>
<td>遗嘱消息发送的主题,<code>%imei%</code> 动态替换为设备 IMEI</td>
</tr>
<tr>
<td>willQos</td>
<td>是</td>
<td>string</td>
<td>遗嘱主题的 QoS 等级(0/1/2,WiFi设备只支持0/1)</td>
</tr>
<tr>
<td>willRetain</td>
<td>是</td>
<td>bool</td>
<td>遗嘱消息是否设为保留消息(<code>true</code> 保留,<code>false</code> 不保留)</td>
</tr>
<tr>
<td>will</td>
<td>是</td>
<td>string</td>
<td>遗嘱消息内容,<code>%imei%</code> 动态替换为设备 IMEI(设备异常离线时发送至 <code>willTopic</code>)</td>
</tr>
</tbody>
</table>
<p><strong>命令示例</strong></p>
<pre><code>{
&quot;method&quot;: &quot;setMqtt&quot;,
&quot;reboot&quot;: true,
&quot;mqttParams&quot;: {
&quot;host&quot;: &quot;mqtt.xxxxxx.com&quot;,
&quot;port&quot;: 8200,
&quot;username&quot;: &quot;test&quot;,
&quot;password&quot;: &quot;test&quot;,
&quot;clientID&quot;: &quot;clientID&quot;,
&quot;publishTopic&quot;: &quot;pubTopic&quot;,
&quot;subscribeTopic&quot;: &quot;subTopic&quot;,
&quot;willTopic&quot;: &quot;willTopic&quot;,
&quot;will&quot;: &quot;{\&quot;method\&quot;:\&quot;close\&quot;,\&quot;imei\&quot;:\&quot;%imei%\&quot;}&quot;,
&quot;keepAlive&quot;: 30,
&quot;cleanSession&quot;: true,
&quot;publishQos&quot;: 2,
&quot;subscribeQos&quot;: 2,
&quot;willQos&quot;: 2,
&quot;publishRetain&quot;: false,
&quot;willRetain&quot;: false
},
&quot;method&quot;: &quot;setMqtt&quot;,
&quot;frameId&quot;: &quot;1745478194596&quot;
}</code></pre>
<p><strong>应答参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>method</td>
<td>string</td>
<td>setMqtt</td>
</tr>
<tr>
<td>result</td>
<td>string</td>
<td>返回结果。ok-成功;其他-具体失败原因</td>
</tr>
<tr>
<td>imei</td>
<td>string</td>
<td>设备imei</td>
</tr>
<tr>
<td>frameId</td>
<td>string</td>
<td>同命令frameId</td>
</tr>
<tr>
<td>timestamp</td>
<td>int</td>
<td>秒级时间戳,WiFi款不支持</td>
</tr>
</tbody>
</table>
<p><strong>应答示例</strong></p>
<pre><code>{
&quot;method&quot;: &quot;setMqtt&quot;,
&quot;result&quot;: &quot;ok&quot;,
&quot;imei&quot;: &quot;1745396239780&quot;,
&quot;frameId&quot;: &quot;1745396239780&quot;,
&quot;timestamp&quot;: 1745396759
}</code></pre>
<p><strong>备注</strong>
无</p>