Skip to content

MQTT Access ​

FastBee open-source edition includes a built-in MQTT Broker developed on Netty, so no external EMQX deployment is required. This article describes how devices connect to the platform via the MQTT protocol.

Connection Workflow ​

  1. Create and publish an MQTT product in Product Management, and confirm the product ID, device number, MQTT username, and password
  2. Connect the device or MQTTX to the MQTT service using the agreed clientId, userName, and password
  3. After connecting, publish /info/post first, then /property/post or /event/post
  4. On the platform side, verify the closed loop via Running Status, Event Logs, and Command Logs on the device detail page

Connection Info ​

ParameterTCPWebSocket
AddressServer IPws://ServerIP:8083/mqtt
Port18838083
ProtocolMQTT 3.1.1MQTT over WebSocket

Device Authentication ​

提示

  • Auth type: S = Simple Authentication, E = Encrypted Authentication
  • When the product has device authorization code enabled, the authorization code must not be empty
  • The user ID is the ID of the logged-in user; devices using different user IDs belong to different users
  • The device number can be a platform-created number or a unique code such as the device MAC/IMEI (the platform auto-registers the device)
clientId = S&deviceNumber&productId&userId
userName = MQTT username
password = MQTT password
password = MQTT password&authCode (when device authorization is enabled)

Example:

clientId = "S&D68329VL588&2&1"
userName = "fastbee"
password = "PHYFED93WSFF1DAS"
clientId = E&deviceNumber&productId&userId
userName = MQTT username
password = AES encrypted(MQTT password&expireTimestamp&authCode(optional))
  • The password is AES-CBC encrypted with the product secret (IV: wumei-smart-open, output: Base64)
  • The expiration timestamp is accurate to milliseconds; within 24 hours is recommended

Example:

clientId = "E&D68329VL588&2&1"
userName = "fastbee"
password = "/W2A/4MK+9cEGBhyBDgr2K5c62DAjAK4m0b5pvwxX6FFMzI3h1pUmaDY3BH1P2mI"

AES Encryption Details ​

AES-CBC encryption mode is used. For testing, you can use the online encryption/decryption tool:

ParameterValue
ModeCBC
Paddingpkcs5padding
Block size128 bit
IVwumei-smart-open
OutputBase64
KeyProduct secret
PlaintextMQTT password&expireTime&authCode(optional)

Subscribe Topics (Platform → Device) ​

TopicDescription
/{productId}/{deviceNum}/function/getSubscribe to platform commands (property set, function invoke)
/{productId}/{deviceNum}/info/getSubscribe to device info requests (publish device info upon receipt)
/{productId}/{deviceNum}/monitor/getSubscribe to real-time monitoring requests (returns count and interval)
/{productId}/{deviceNum}/ntp/getSubscribe to time sync (optional)
/{deviceNum}/http/upgrade/setSubscribe to OTA upgrades via HTTPS
/{deviceNum}/fetch/upgrade/setSubscribe to OTA upgrades via binary package

Publish Topics (Device → Platform) ​

TopicDescription
/{productId}/{deviceNum}/property/postPublish property/function data (real-time display and storage)
/{productId}/{deviceNum}/event/postPublish events
/{productId}/{deviceNum}/info/postPublish device info
/{productId}/{deviceNum}/monitor/postPublish real-time monitoring data (real-time charts only, not stored)
/{productId}/{deviceNum}/ntp/postPublish time sync (optional)
/{deviceNum}/http/upgrade/replyReply to OTA upgrades via HTTPS
/{deviceNum}/fetch/upgrade/replyReply to OTA upgrades via binary package

提示

  • {productId} is the product ID (not the product number), found on the product detail page
  • {deviceNum} is the device number and must match the platform device exactly

Data Format ​

Devices and the platform exchange data in JSON format.

Publish Properties/Functions/Events — /property/post, /event/post ​

json
[{
    "id": "temperature",
    "value": "27.43",
    "remark": "Temperature normal"
}, {
    "id": "switch",
    "value": "1",
    "remark": "Switch turned on"
}]
  • id: Thing model identifier, viewable on the product detail page, unique within the product
  • value: Passed as a string; boolean uses "0"/"1"; enum uses the enum key; array is comma-separated
  • remark: Note information, viewable in device logs

Subscribe to Platform Commands — /function/get ​

json
[{
    "id": "gear",
    "value": "1",
    "remark": "Scene linkage triggered"
}, {
    "id": "switch",
    "value": "0",
    "remark": "Scheduled off"
}]

Publish Device Info — /info/post ​

json
{
    "rssi": -43,
    "firmwareVersion": 1.2,
    "status": 3,
    "userId": 1,
    "longitude": 0,
    "latitude": 0,
    "summary": {
        "name": "FastBee",
        "chip": "ESP32"
    }
}
FieldDescription
rssiSignal strength (excellent [-55~0], good [-70~-55], fair [-85~-70], poor [-100~-85])
firmwareVersionFirmware version number
statusDevice status, fixed at 3 (online)
userIdUser ID
longitude/latitudeOptional, device location
summaryOptional, device summary information

Real-time Monitoring — /monitor/get, /monitor/post ​

The platform sends a monitoring request:

json
{
    "count": 60,
    "interval": 1000
}

The device reports data at the specified count and interval:

json
[{
    "id": "temperature",
    "value": "27.43",
    "remark": ""
}]

Time Sync — /ntp/post, /ntp/get ​

The device publishes:

json
{
    "deviceSendTime": "1592361428000"
}

The platform replies:

json
{
    "deviceSendTime": "1592361428000",
    "serverRecvTime": "1592366463548",
    "serverSendTime": "1592366463548"
}

Device current time = (serverRecvTime + serverSendTime + deviceRecvTime - deviceSendTime) / 2

Thing Model Identifier Rules ​

  • All identifiers must be unique within a product; use letters and numbers primarily and avoid special characters
  • Object sub-model ID format: parentId_childId
  • Array identifiers start with array_index (two-digit index, e.g. array_00_power_switch), and the array length must not exceed 100

Device AP Provisioning (optional, WiFi devices only) ​

The device opens a hotspot (address 192.168.4.1), and the mobile side passes configuration information through the device's web service.

Detect Device ​

GET http://192.168.4.1/api/wifi/status

HTTP 200 means the device is detected; the response includes device info and the current network state.

Configuration API ​

POST http://192.168.4.1/api/wifi/config?SSID=wifi_name&password=wifi_pass&userId=1
ParameterDescription
SSIDWiFi name (required, lowercase ssid alias accepted)
passwordWiFi password (required, pwd alias accepted)
userIdUser ID (required)
deviceNumDevice number (optional)
extraProduct number (optional)

HTTP 200 means provisioning succeeded (the device then automatically switches to STA mode), 400 means required parameters are missing, and 500 means saving failed. See "Network Configuration · Mobile AP Provisioning API" for full endpoint details.

Testing with MQTTX ​

  1. Download the MQTTX client
  2. Create a connection:
    • Host: mqtt://ServerIP, Port: 1883
    • Client ID: S&deviceNumber&productId&1
    • Username: MQTT username
    • Password: MQTT password
  3. Subscribe to /{productId}/{deviceNum}/function/get
  4. Publish device info to /{productId}/{deviceNum}/info/post
  5. Publish property data to /{productId}/{deviceNum}/property/post
  6. Observe the device online status and running data on the platform console

Acceptance Checklist ​

StepCheckExpected Result
1Product publishedProduct status is "published"
2MQTTX connectedDevice detail shows online
3/info/postDevice info, signal, and version fields updated
4/property/postRunning status shows thing model property values
5/event/postReported events appear in the event log
6/function/getDevice receives commands after the platform delivers them
7Reply resultsDevice replies with the command result; platform status refreshes
8Rules/ScenesRelated rules, scenes, and alerts can be triggered

Common Errors ​

Connection Refused ​

  1. Whether server port 1883 is open
  2. Whether the built-in MQTT Broker is running
  3. Whether the clientId format is correct (S&deviceNumber&productId&userId)
  4. Whether the product has device authorization code enabled
  5. Whether the device is disabled

Device Online but Properties Not Refreshing ​

  1. Whether the publish topic is /{productId}/{deviceNum}/property/post
  2. Whether productId is the product ID (not the product number)
  3. Whether deviceNum matches the device number exactly
  4. Whether the message body is in JSON array format
  5. Whether id matches the thing model identifier exactly
  6. Whether value matches the data type

Platform Commands Not Received by Device ​

  1. Whether the device is subscribed to /{productId}/{deviceNum}/function/get
  2. Whether the device is still online
  3. Whether the thing model is a writable function or a deliverable property
  4. Whether the user has device detail and command delivery permissions

Rules or Alerts Not Triggered ​

  1. Whether device data has entered the platform's running status
  2. Whether the products, devices, and variables bound to the scene or rule are correct
  3. Whether the condition expression matches the reported value type
  4. Whether the alert configuration is enabled

Rule Script Conversion ​

If a device uses a custom data format, you can write conversion logic in Rule Scripts to transform the raw data into the platform standard format. See Rule Scripts.

FastBee | fastbee.cn