This topic describes common messaging issues and solutions for communication between devices, the IoT Platform, and servers.
Handling duplicate messages
QoS level 1 guarantees at-least-once delivery, so a device may receive duplicate messages. These duplicates will have the same message ID, which a device can use for deduplication. IoT Platform also minimizes sending duplicate QoS level 1 messages.
MQTT device fails to receive data
If a device fails to receive data, check the following to identify the cause:
-
Verify that the device is subscribed to the correct topic. An MQTT device can only receive messages from topics to which it has subscribed.
-
If the device intermittently misses messages: Check for time-consuming logic in your device application's callback. If present, move this logic to a separate thread to avoid blocking the callback.
-
Ensure the application subscribes to the topic during its initialization. Messages sent before the subscription is complete may be lost.
-
To receive QoS 1 messages sent while the device was offline, set the MQTT connection parameter cleanSession to false (that is, cleanSession must be false).
Message storage
After a message is published to a topic, IoT Platform immediately forwards it to devices subscribed to that topic.
-
QoS 0 message: IoT Platform does not store it.
-
QoS 1 message: IoT Platform stores it for 7 days.
Device data retention period
-
QoS 0 messages: IoT Platform does not retain them.
-
QoS 1 messages: IoT Platform retains them for 7 days.
You can view communication logs for the past 7 days in the IoT Platform console on the page for your instance. For more information, see Log Service.
Slow or timed-out message delivery
An unstable network connection is a common cause of this issue.
To test the device's network connectivity:
-
Log on to the IoT Platform console.
-
On the Overview page, find the instance and click its ID or alias.
-
In the left-side navigation pane, choose Devices > Devices.
-
On the Devices page, search for the device by its DeviceName or alias.
-
In the Actions column for the device, click View.
-
On the Device Information tab, click Test next to Real-time Delay.
-
Click OK to begin the test.
Repeat steps 6 and 7 to gather more data. Consistently high latency indicates an unstable network connection.
Support for will and retained messages
Yes. IoT Platform supports will and retained messages with MQTT 5.0. For more information, see MQTT 5.0 features that are supported by IoT Platform.
Server-side message retrieval
A server can retrieve device messages in two ways.
-
Server-side subscription: Use IoT Platform's server-side subscription to subscribe to one or more message types. Based on your subscription settings, IoT Platform forwards messages of the specified types from all devices under a product to your server. IoT Platform supports the following types of server-side subscription:
-
AMQP server-side subscription: Use an AMQP SDK to receive device messages that IoT Platform forwards.
-
MNS server-side subscription: Use an MNS SDK to receive device messages that IoT Platform forwards to a Simple Message Queue (formerly MNS) (SMQ) queue.
-
-
Data forwarding: Use data forwarding to route data from specified devices to a Simple Message Queue (formerly MNS) (SMQ) queue or a Message Queue for Apache RocketMQ queue based on data forwarding rules. Your server consumes the messages using an MNS SDK or a Message Queue for Apache RocketMQ SDK. For more information, see Overview of data forwarding.
Console messages not received by SMQ queues
IoT Platform does not forward messages sent from the console or via a cloud API to Simple Message Queue (formerly MNS) (SMQ) queues because it considers them server-side messages. Only messages that originate from a device, such as upstream device messages, notifications of device status changes, and device tag changes, are routed to SMQ queues.
How to identify the source topic
Messages in a Simple Message Queue (formerly MNS) (SMQ) have the following format:
{
"messageid": "12345",
"messagetype": "status/upload",
"topic": "null/topic",
"payload": {},
"timestamp": 1469564576
}
The topic field identifies the source topic.
Send commands to devices
You can call the following IoT Platform APIs to send messages to devices:
|
API |
Description |
|
Sends a message to a specified device using a custom topic. |
|
|
Sends a message to multiple devices of a specified product using a custom topic. |
|
|
Broadcasts messages to online devices of a specified product. You can target all online devices or only those that subscribe to a specific topic. |
|
|
Sends a request message to a specified device and returns a response synchronously. |
|
|
Sets the value of a Thing Specification Language (TSL) property for a specified device. |
|
|
Sets the value of a Thing Specification Language (TSL) property for multiple devices of a specified product. |
|
|
Invokes a specified Thing Specification Language (TSL) service on a single device. |
|
|
Invokes a specified Thing Specification Language (TSL) service on multiple devices of a specified product. |
Device-to-device communication
Yes, devices in the same instance can communicate with each other.
Use the data forwarding or message routing feature to forward messages from one device's topic to another, enabling communication between them.
-
You can forward data from a device topic, such as a topic for reporting thing model data, to other topics. For more information, see Forward data to other topics.
-
To connect a smart light with a mobile app via data forwarding, see M2M communication between devices by using data forwarding.
-
To connect a smart light with a mobile app via message routing, see M2M communication between devices by using message routing.
QoS 2 message failure
IoT Platform supports QoS 0 and QoS 1, but does not support QoS 2.
For details, see the MQTT protocol specification.
Device connection and status synchronization
Subscribe to device status update messages using server-side subscription to keep device connection and status information in sync.
For more information, see Server-side subscription.
Visualizing device data
-
You can use server-side subscription or Data Forwarding to forward device data to your server or database. Then, you can build your own data visualization solution.
For more information, see server-side subscription and Data Forwarding (New Version).
-
Use a server-side SDK for IoT Platform to call APIs, retrieve data reported by devices, and then build your own data visualization solution.
The following APIs are available to retrieve device data:
API
Description
Queries the property snapshots for a specified device.
Queries the raw property snapshots reported by a device, including properties that passed and failed thing model validation.
Queries the raw property records reported by a device, including those that passed and failed thing model validation.
Queries the raw event records reported by a device, including events that passed and failed thing model validation.
Queries the raw records of service calls initiated by a device, including calls that passed and failed thing model validation.
Queries the desired property values of a device.
Queries data for a single property of a device within a specified time range.
Queries data for multiple properties of a device within a specified time range.
Queries a device's event records.
Queries a device's service call records.
Queries the time series data stored in the data service.
Queries the snapshot data of the time series data stored in the data service.
Publish hexadecimal messages via API
In the IoT Platform console, you cannot send hexadecimal messages using online debug, the device simulator, or the topic list tab on a device's details page.
You can use the Pub, BatchPub, or PubBroadcast APIs to send hexadecimal messages. The MessageContent parameter must be the Base64-encoded original message, which can be a string or a hexadecimal byte array.
After your business server sends a message via an API, IoT Platform automatically Base64-decodes the message before forwarding it to the device.
Export device data
IoT Platform stores QoS 0 messages for up to 1 day and QoS 1 messages for up to 7 days.
You can use the data storage feature of Data Service to store offline device data and time-series data. Offline data includes platform system tables, time-series tables, snapshot tables, and custom storage tables. Device time-series data includes Thing Model data (properties, services, and events) reported by devices and custom topic data configured using time-series data storage rules. For more information, see Configure Data Storage.
-
To retrieve device data, use APIs to query the data and push it to your own server.
-
Custom topic data
-
Query time-series data: QueryDevicesHotStorageData.
-
Query snapshot data: QueryDevicesHotStorageDataStatus.
-
-
Thing Model data
-
All property snapshots of a device or digital twin node: QueryDevicePropertyStatus.
-
Snapshot of original properties reported by a device (all properties that pass or fail Thing Model validation): QueryDeviceOriginalPropertyStatus.
-
Records of original properties reported by a device (all properties that pass or fail Thing Model validation): QueryDeviceOriginalPropertyData.
-
Records of original events reported by a device (all events that pass or fail Thing Model validation): QueryDeviceOriginalEventData.
-
Records of original services invoked by a device (all services that pass or fail Thing Model validation): QueryDeviceOriginalServiceData.
-
-
Data from storage tables in Data Service
-
Query data in platform system tables and time-series or snapshot tables: CreateDownloadDataJob and GetDownloadFile.
-
-
Data APIs in Data Service
Run a query task using a Data Service API to retrieve specific data from a data source: ListAnalyticsData.
-
-
If you need to store device data for extended periods, reduce storage costs, or perform further data processing (such as SQL analysis, and Data API), you can back up device data sources. After you enable data backup for a product, IoT Platform automatically creates corresponding time-series/snapshot tables for the product in offline storage. These tables include the product property time-series table, product property snapshot table, and product event table.
AMQP subscription for hexadecimal data
Yes.
Follow these steps to forward hexadecimal data:
-
Configure the device to upload data in hexadecimal format by using a custom topic. For more information, see Use custom topics to communicate.
-
Configure message forwarding to subscribe to device-reported messages on a custom topic.
-
Configure AMQP server-side subscription: In Alibaba Cloud IoT Platform, set the Push Message Type to Device-reported Messages.
-
Forward data to an AMQP server-side consumer group: In the message parser, use the
payload('binary')function to convert the device-reported data to a binary variable for pass-through.For more information about functions supported by the Data Forwarding parser, see Function list.
-
-
Use an AMQP client SDK to consume custom messages from the device.
Alibaba Cloud IoT Platform provides sample code for AMQP SDKs in the following languages:
The AMQP client SDKs for Python 3 and PHP use the STOMP protocol to communicate with Alibaba Cloud IoT Platform. When you use these SDKs, you must Base64-encode the payload before pushing it. Otherwise, the payload may be truncated.
For detailed instructions on using the SDKs, see AMQP client connection.
Consumer group and AMQP message queue mapping
Yes.
Up to 128 AMQP clients can consume messages from a single AMQP message queue.
Mapping a device to a single AMQP queue
Yes.
Use the Rule Engine to configure data forwarding to a consumer group that subscribes to an AMQP server. In the message forwarding parser, use functions such as topic(number) or deviceName() in an if statement to select a device and forward its messages to the AMQP message queue.
Here is a sample parser script:
// Get the device's message payload and parse it as JSON.
var data = payload("json");
// Get the device name.
var dn = deviceName();
// If the message is from 'device01', forward its data.
if (dn == 'device01') {
writeAmqp(1000, data, "Debug");
}
To learn more about parser scripts, see Script syntax. For instructions on configuring a message forwarding parser, see Forward data to a consumer group that subscribes to an AMQP server.
Notify apps of device online status
The server-side subscription feature of IoT Platform allows you to receive device status change messages. To use this feature, deploy and start an AMQP client on the server that hosts your app or mini program.
The implementation is as follows:
-
Configure AMQP server-side subscription: In the IoT Platform console, configure a server-side subscription consumer group to push device status change messages.
-
AMQP client integration: On the server that hosts your app or mini program, deploy and start an AMQP client to connect to IoT Platform.
For information about the data format of device status change messages, see Device Online/Offline Status. After the AMQP client receives messages, you must implement the logic to display them in your app or mini program.
-
Device Connection: After a device connects to IoT Platform, the platform forwards its status information to the AMQP client for consumption.
Message not received after a Pub API call
The device is not subscribed to the topic specified in the Pub API call.
A device must be subscribed to a topic to receive messages from it. To subscribe the device, call the SubscribeTopic API.
Subscribe to and view topics
-
A device must actively subscribe to topics. Upon successful subscription, the topics appear in the Topic List on the Device details page for your instance in the IoT Platform console.
-
If a device has not subscribed to any topics, the Topic List tab on its details page will be empty.
Subscribe to topics
A device can subscribe to topics in the following ways:
-
If you use the C Link SDK (versions 3.1, 3.2, and 4.x) or the Python Link SDK provided by IoT Platform, your device automatically subscribes to basic communication topics and Thing Model topics that have subscribe permission.
After you create a custom topic with subscribe permission, you can use the following APIs in the SDK to subscribe to the custom topic:
-
For C Link SDK versions 3.1 and 3.2: IOT_MQTT_Subscribe.
-
For C Link SDK version 4.x: aiot_mqtt_sub.
-
For Python Link SDK: lk.subscribe_topic(topic, qos=1) .
If you enable proxy subscription when you create a custom topic, IoT Platform automatically subscribes the device to that topic when the device establishes a connection.
To add a custom topic, see Use custom topics to communicate.
-
-
Start device simulator: When you use the device simulator feature provided by IoT Platform, the device automatically subscribes to basic communication topics and Thing Model topics.
After you create a custom topic with subscribe permission, you can use the upstream command debugging feature to subscribe to it.
-
Use MQTT.fx to connect to IoT Platform: After the device is online, use the Subscribe feature to subscribe to device topics.
-
SubscribeTopic: After a device connects to IoT Platform, call this API to subscribe to device topics.
After you create a custom topic with subscribe permission, you can call the SubscribeTopic API to subscribe to the topic.
View subscribed topics
Choose one of the following methods:
-
View subscribed topics for a device in the IoT Platform console.
-
Call the QueryDeviceSubTopic API to query the device's subscribed topics.
Why can't AMQP subscriptions receive RRPC messages?
RRPC communication is a synchronous process: the server-side sends a request to a device and waits for a response. IoT Platform does not support AMQP server-side subscriptions for RRPC communication messages.
For more information about RRPC communication, see MQTT synchronous communication (RRPC).
Standard JSON format for custom topics
IoT Platform does not enforce a specific data format for communication over custom topics. You define the format.
For information about the topics and the required Alink JSON format for communication between devices and IoT Platform, see the Alink protocol documentation.
If you set the data format to passthrough/custom when you create a Product, you must configure message parsing. This configuration parses custom-formatted payloads, which devices send over a custom topic, into JSON format. For more information, see Custom topic message parsing.
Thing model communication error: "5092 - property not found"
This error means a property in an uplink or downlink message is not defined in the thing model.
Possible causes:
-
The property is not defined in the thing model. Go to the IoT Platform console to review the property definitions and add the required property. See Add a thing model.
-
The property is defined in a custom module. For uplink and downlink communication, you must prefix the property with the custom module's identifier in the following format:
{tsl.functionBlockId}:{tsl.properties.identifier}.
For details on thing model fields, see TSL field reference for the thing model. For more information on message-related error codes, see Error codes in the cloud runtime log.
Property setting: device response error 6335
The thing model specifies an empty response for the property setting method. Therefore, when IoT Platform sends a property setting command to a device, the data field in the device response message must be empty. If the data is not empty, an error occurs.
For more information about error codes, see error codes in cloud-side run logs.
Topic matching for devices
Yes. The topics of a physical device must match those of its corresponding device in the product.
Cross-device topic subscription
No. A device can only subscribe to its own topics.
Receive messages from all devices
You can use AMQP server-side subscription for your server to receive device messages. For more information, see Use AMQP server-side subscription.
Subscription failure with a shared device certificate
-
Only one device can use a device certificate at a time. The hardware device and the MQTT client must use different device certificates to connect to IoT Platform.
-
A device can only subscribe to its own topics and cannot publish messages to the topics of other devices.
-
You can use Data Forwarding or topic-based message routing to forward messages from one device's topic to another, which enables communication between the devices.
For example:
-
To forward device data from a topic used for reporting thing model data to other topics, see Forward data to other topics.
-
To connect a smart light to a mobile app using Data Forwarding, see M2M device communication based on message forwarding.
-
To connect a smart light to a mobile app using topic-based message routing, see M2M device communication based on Topic message routing.
-
Operation permissions for topics
-
IoT Platform predefines the operation permissions for basic and thing model topics, and you cannot modify them. To view these permissions, follow these steps:
-
Log in to the IoT Platform console.
-
In the upper-left corner of the console, select the region where your instance is located.
-
On the Instance Overview tab, under All Environments, find your instance and click its card.
-
In the left-side navigation pane, choose .
-
On the Product page, find your product and click View in the Actions column.
-
On the Product details page, click the Topic category list tab. You can then view the topic lists on the Basic topic and Thing model topic tabs.
The Operation permission column in the topic list shows the Publish and Subscribe permissions for each topic.
The table on the Thing model topic tab contains the Function, Topic category, Operation permission, and Description columns. This table lists the topic paths (such as
/sys/${productKey}/${deviceName}/thing/event/property/post) and their corresponding publish or subscribe permissions for functions including report property, set property, report event, and invoke service.
-
-
Use the QueryProductTopic API to query the details of a product's custom Topic categories.
Export cloud-side run logs
No, you cannot.
-
You can activate Log Service and then enable the transfer of cloud-side run logs in the IoT Platform console. This lets you export the logs to a Logstore in Log Service for long-term storage. For instructions, see Transfer cloud-side run logs.
After you enable the log transfer feature, Log Service automatically creates the following resources to store your logs. You can then view the transferred cloud-side run logs in Log Service.
-
Project:
iot-log-${uid}-${regionId}. In this format,${uid}is your Alibaba Cloud account ID, and${regionId}is the region ID of your IoT Platform service. -
Logstore: iot-logs.
-
IoT Platform: Deliver a single device message to multiple servers
For an AMQP server-side subscription, a consumer group is mapped to a single AMQP message queue. If you start multiple consumers and bind them to the same consumer group, each device message is delivered to only one of them at random. To send a copy of every message to each consumer, bind each consumer to a different consumer group.
For more information, see the following topics:
-
Configure an AMQP server-side consumer group: Configure an AMQP server-side subscription or Forward data to a consumer group.
-
Start an AMQP consumer on your server: Connect an AMQP client.
Broadcast messages to multiple devices
The IoT platform's PubBroadcast interface allows you to publish a broadcast message to multiple online devices within a specific product. You can target all online devices or only those that subscribe to a specified topic.
IoT Platform server-side subscription error 9203
This error occurs because the AMQP client or Simple Message Queue (formerly MNS) (SMQ) client for the server-side subscription is offline. To connect the AMQP client, see Connect an AMQP client. To connect the MNS client, see Develop an MNS consumer client.
Device subscription frequency
While a device only needs to subscribe once, we recommend subscribing every time it powers on. This ensures the corresponding callback in your code is triggered.
Sending messages before subscription
No. A device receives messages from a communication topic only after subscribing to it. For details, see Use communication topics.
Connect a client and subscribe to property changes
-
Configure an AMQP server-side subscription: In IoT Platform, set the Message Type to Device-reported Messages.
-
Use an AMQP client SDK to connect to IoT Platform and receive subscribed Device-reported Messages containing device property data.
Alibaba Cloud IoT Platform provides AMQP client SDK sample code in the following languages:
The AMQP client SDKs for Python 3 and PHP use the STOMP protocol to communicate with IoT Platform. When using these SDKs, you must Base64-encode the message content before pushing it. Otherwise, the message content may be truncated.
For detailed instructions on using the SDKs, see AMQP client connection instructions.
Cross-account authorization
-
Use
device distributionto distribute devices from a sourceinstanceto a targetinstancein anotheraccount. The targetaccountcan then view data from these devices. For usage limits and detailed instructions, see device distribution.