- Curated guides under docs/; trim China-only integration docs and screenshots - Root and main README set aligned with westernized product positioning - LICENSE text update where applicable
5.8 KiB
MQTT Gateway Deployment Tutorial
The xiaozhi-esp32-server project can be combined with the open-source xiaozhi-mqtt-gateway project for simple modification to enable xiaozhi hardware MQTT+UDP connection.
Preparation
Check the version number at the bottom of your control console homepage to confirm whether your control console version is 0.7.7 or above. If not, you need to upgrade the control console.
Prepare your mqtt-websocket connection address for xiaozhi-server. Based on your original websocket address, add the characters ?from=mqtt_gateway to get the mqtt-websocket connection address.
- If you are using source code deployment, your
mqtt-websocketaddress is:
ws://127.0.0.1:8000/xiaozhi/v1?from=mqtt_gateway
- If you are using docker deployment, your
mqtt-websocketaddress is
ws://your_host_lan_IP:8000/xiaozhi/v1?from=mqtt_gateway
Step 1: Deploy MQTT Gateway
- Clone the modified xiaozhi-mqtt-gateway project:
git clone https://ghfast.top/https://github.com/lapy/xiaozhi-mqtt-gateway.git
cd xiaozhi-mqtt-gateway
- Install dependencies:
npm install
npm install -g pm2
- Configure
config.json:
cp config/mqtt.json.example config/mqtt.json
- Edit the configuration file config/mqtt.json, replace the
mqtt-websocketaddress from the preparation phase intochat_servers. For example, the source code deployment ofxiaozhi-serveris configured as follows:
{
"production": {
"chat_servers": [
"ws://127.0.0.1:8000/xiaozhi/v1?from=mqtt_gateway"
]
},
"debug": false,
"max_mqtt_payload_size": 8192,
"mcp_client": {
"capabilities": {
},
"client_info": {
"name": "xiaozhi-mqtt-client",
"version": "1.0.0"
},
"max_tools_count": 128
}
}
- Create a
.envfile in the project root directory and set the following environment variables:
PUBLIC_IP=your-IP # Server public IP
MQTT_PORT=1883 # MQTT server port
UDP_PORT=8884 # UDP server port
API_PORT=8007 # Management API port
MQTT_SIGNATURE_KEY=test # MQTT signature key
Please note the PUBLIC_IP configuration, ensure it matches the actual public IP address, or use domain name if available.
MQTT_SIGNATURE_KEY is the key used for MQTT connection authentication. It's recommended to set it to something more complex, preferably 8+ characters with both uppercase and lowercase letters. This key will be used later.
- Do not use simple passwords like
123456,test, etc. - Do not use simple passwords like
123456,test, etc. - Do not use simple passwords like
123456,test, etc.
- Start MQTT Gateway
# Start service
pm2 start ecosystem.config.js
# View logs
pm2 logs xz-mqtt
When you see the following logs, it means the MQTT gateway has started successfully:
0|xz-mqtt | 2025-09-11T12:14:48: MQTT server is listening on port 1883
0|xz-mqtt | 2025-09-11T12:14:48: UDP server is listening on x.x.x.x:8884
If you need to restart the MQTT gateway, execute the following command:
pm2 restart xz-mqtt
Step 2: Configure Smart Control Panel
- At the top of the Smart Control Panel, click
Parameter Management, search forserver.mqtt_gateway, click edit, and fill in thePUBLIC_IP+:+MQTT_PORTyou set in the.envfile. Similar to this
192.168.0.7:1883
-
At the top of the Smart Control Panel, click
Parameter Management, search forserver.mqtt_signature_key, click edit, and fill in theMQTT_SIGNATURE_KEYyou set in the.envfile. -
At the top of the Smart Control Panel, click
Parameter Management, search forserver.udp_gateway, click edit, and fill in thePUBLIC_IP+:+UDP_PORTyou set in the.envfile. Similar to this
192.168.0.7:8884
- At the top of the Smart Control Panel, click
Parameter Management, search forserver.mqtt_manager_api, click edit, and fill in thePUBLIC_IP+:+UDP_PORTyou set in the.envfile. Similar to this
192.168.0.7:8007
After completing the above configuration, you can use the curl command to verify whether your OTA address will distribute MQTT configuration. Change the http://localhost:8002/xiaozhi/ota/ below to your OTA address
curl 'http://localhost:8003/xiaozhi/ota/' \
-H 'Content-Type: application/json' \
-H 'Client-Id: 7b94d69a-9808-4c59-9c9b-704333b38aff' \
-H 'Device-Id: 11:22:33:44:55:66' \
--data-raw $'{\n "application": {\n "version": "1.0.1",\n "elf_sha256": "1"\n },\n "board": {\n "mac": "11:22:33:44:55:66"\n }\n}'
If the returned content contains mqtt related configuration, it means the configuration is successful. Similar to this
{"server_time":{"timestamp":1757567894012,"timeZone":"Asia/Shanghai","timezone_offset":480},"activation":{"code":"460609","message":"http://xiaozhi.server.com\n460609","challenge":"11:22:33:44:55:66"},"firmware":{"version":"1.0.1","url":"http://xiaozhi.server.com:8003/xiaozhi/otaMag/download/NOT_ACTIVATED_FIRMWARE_THIS_IS_A_INVALID_URL"},"websocket":{"url":"ws://192.168.4.23:8000/xiaozhi/v1/"},"mqtt":{"endpoint":"192.168.0.7:1883","client_id":"GID_default@@@11_22_33_44_55_66@@@7b94d69a-9808-4c59-9c9b-704333b38aff","username":"eyJpcCI6IjA6MDowOjA6MDowOjA6MSJ9","password":"Y8XP9xcUhVIN9OmbCHT9ETBiYNE3l3Z07Wk46wV9PE8=","publish_topic":"device-server","subscribe_topic":"devices/p2p/11_22_33_44_55_66"}}
Step 3: Restart Xiaozhi Device
Since MQTT information needs to be distributed through the OTA address, you only need to ensure that you can normally connect to the server's OTA address, then restart and wake up.
After waking up, pay attention to the mqtt-gateway logs to confirm if there are successful connection logs.
pm2 logs xz-mqtt