MQTT Access
About 4 min
MQTT Access
FastBee open-source edition includes a built-in MQTT Broker based on Netty. No external EMQX deployment is required.
Workflow
- Create and publish an MQTT product, note the product ID, device number, MQTT credentials
- Connect using the correct
clientId,userName,passwordformat - After connecting, publish
/info/postfirst, then/property/postor/event/post - Verify the data pipeline via device detail page, event logs, and command logs
Connection Info
| Parameter | TCP | WebSocket |
|---|---|---|
| Address | Server IP | ws://ServerIP:8083/mqtt |
| Port | 1883 | 8083 |
| Protocol | MQTT 3.1.1 | MQTT over WebSocket |
Device Authentication
Tips
- Auth type:
S= simple,E= encrypted - Device authorization code must not be empty when enabled
userIddetermines device ownership- Device number can be platform-created or device MAC/IMEI (auto-registered)
Simple Authentication (recommended for testing)
clientId = S&deviceNumber&productId&userId
userName = MQTT username
password = MQTT password
password = MQTT password&authCode (when device auth enabled)Example:
clientId = "S&D68329VL588&2&1"
userName = "fastbee"
password = "PHYFED93WSFF1DAS"Encrypted Authentication (recommended for production)
clientId = E&deviceNumber&productId&userId
userName = MQTT username
password = AES-CBC encrypted(MQTT password&expireTimestamp&authCode(optional))- AES-CBC mode, IV:
wumei-smart-open, output: Base64 - Expire timestamp in milliseconds, recommended within 24 hours
Example:
clientId = "E&D68329VL588&2&1"
userName = "fastbee"
password = "/W2A/4MK+9cEGBhyBDgr2K5c62DAjAK4m0b5pvwxX6FFMzI3h1pUmaDY3BH1P2mI"AES Encryption Details
| Parameter | Value |
|---|---|
| Mode | CBC |
| Padding | pkcs5padding |
| Block size | 128 bit |
| IV | wumei-smart-open |
| Output | Base64 |
| Key | Product secret |
| Plaintext | MQTT password&expireTime&authCode(optional) |
Subscribe Topics (Platform → Device)
| Topic | Description |
|---|---|
/{productId}/{deviceNum}/function/get | Platform commands (property set, function invoke) |
/{productId}/{deviceNum}/info/get | Device info request (publish info upon receipt) |
/{productId}/{deviceNum}/monitor/get | Real-time monitoring request (count & interval) |
/{productId}/{deviceNum}/ntp/get | NTP time sync (optional) |
/{deviceNum}/http/upgrade/set | OTA upgrade via HTTPS |
/{deviceNum}/fetch/upgrade/set | OTA upgrade via binary |
Publish Topics (Device → Platform)
| Topic | Description |
|---|---|
/{productId}/{deviceNum}/property/post | Property/function data (real-time display & storage) |
/{productId}/{deviceNum}/event/post | Events |
/{productId}/{deviceNum}/info/post | Device info |
/{productId}/{deviceNum}/monitor/post | Real-time monitoring (display only, no storage) |
/{productId}/{deviceNum}/ntp/post | NTP time sync (optional) |
/{deviceNum}/http/upgrade/reply | OTA upgrade reply via HTTPS |
/{deviceNum}/fetch/upgrade/reply | OTA upgrade reply via binary |
Tips
{productId}is the product ID (not product number), found in product detail page{deviceNum}is the device number, must match exactly
Data Format
All device-platform communication uses JSON.
Publish Properties/Events — /property/post, /event/post
[{
"id": "temperature",
"value": "27.43",
"remark": "Normal"
}, {
"id": "switch",
"value": "1",
"remark": "Turned on"
}]id: Thing model identifier, unique within the productvalue: Passed as string; boolean:"0"/"1"; enum: enum key; array: comma-separatedremark: Optional note, visible in device logs
Platform Commands — /function/get
[{
"id": "gear",
"value": "1",
"remark": "Scene triggered"
}]Device Info — /info/post
{
"rssi": -43,
"firmwareVersion": 1.2,
"status": 3,
"userId": 1,
"longitude": 0,
"latitude": 0
}| Field | Description |
|---|---|
| rssi | Signal strength (excellent [-55~0], good [-70~-55], fair [-85~-70], poor [-100~-85]) |
| firmwareVersion | Firmware version |
| status | Device status, fixed at 3 (online) |
| userId | User ID |
Real-time Monitoring — /monitor/get, /monitor/post
Platform sends monitoring request:
{ "count": 60, "interval": 1000 }Device reports data per count and interval:
[{ "id": "temperature", "value": "27.43", "remark": "" }]NTP Time Sync — /ntp/post, /ntp/get
Device publishes:
{ "deviceSendTime": "1592361428000" }Platform replies:
{
"deviceSendTime": "1592361428000",
"serverRecvTime": "1592366463548",
"serverSendTime": "1592366463548"
}Device time = (serverRecvTime + serverSendTime + deviceRecvTime - deviceSendTime) / 2
Thing Model Identifier Rules
- All identifiers must be unique within a product; use alphanumeric characters
- Object sub-model ID format:
parentId_childId - Array identifiers start with
array_index(two-digit index, e.g.,array_00_power_switch), max 100 elements
Device AP Provisioning (WiFi only, optional)
Device opens hotspot at 192.168.4.1, mobile app sends WiFi credentials.
Detect Device
GET http://192.168.4.1/statusHTTP 200 means device detected.
Configure
POST http://192.168.4.1/config?SSID=wifi_name&password=wifi_pass&userId=1| Parameter | Description |
|---|---|
| SSID | WiFi name (required) |
| password | WiFi password (required) |
| userId | User ID (required) |
| deviceNum | Device number (optional) |
| authCode | Auth code (optional) |
HTTP 200 = success, 500 = failure.
Testing with MQTTX
- Download MQTTX
- Create connection:
- Host:
mqtt://ServerIP, Port:1883 - Client ID:
S&deviceNumber&productId&1 - Username: MQTT username
- Password: MQTT password
- Host:
- Subscribe to
/{productId}/{deviceNum}/function/get - Publish device info to
/{productId}/{deviceNum}/info/post - Publish property data to
/{productId}/{deviceNum}/property/post - Check device status and data on the platform console
Checklist
| Step | Check | Expected Result |
|---|---|---|
| 1 | Product published | Product status is "published" |
| 2 | MQTTX connected | Device shows online |
| 3 | /info/post | Signal, version fields updated |
| 4 | /property/post | Property values displayed |
| 5 | /event/post | Events appear in log |
| 6 | /function/get | Device receives commands |
| 7 | Reply results | Platform status refreshes |
| 8 | Rules/Scenes | Rules, scenes, alerts triggered |
Troubleshooting
Connection Refused
- Server port
1883open - Built-in MQTT Broker running
clientIdformat correct (S&deviceNumber&productId&userId)- Device authorization code enabled and included
- Device not disabled
Device Online but No Data
- Topic is
/{productId}/{deviceNum}/property/post productIdis product ID (not product number)deviceNummatches exactly- Payload is JSON array format
idmatches thing model identifiervaluematches data type
Platform Commands Not Received
- Device subscribed to
/{productId}/{deviceNum}/function/get - Device still online
- Thing model is writable
- User has device permission
Rules or Alerts Not Triggered
- Device data visible in platform
- Scene/rule bindings correct
- Condition expression matches data type
- Alert configuration enabled
Rule Script Conversion
For devices using custom data formats, write conversion logic in Rule Scripts to transform data into the platform standard format. See Rule Scripts.
