Use topic-based message routing to establish M2M communication
Last Updated: Sep 19, 2019
This topic describes how to use the topic-based message routing service of IoT Platform
to build an M2M communication architecture. A connection between a smart lamp and
a mobile app is used as an example.
Background information
The following figure shows the procedure to control the smart lamp through the mobile
app.
In the IoT Platform console, register a product and device for the mobile app.
In the preceding figure, the ProductKey and DeviceName parameters for the mobile app
are set to al987654321 and ControlApp respectively.
When a user registers the mobile app with your server, your server sends the device
information to the mobile app. This way, the mobile app can connect to IoT Platform
as a device.
Call the CreateTopicRouteTable operation to create a message routing relationship between the app topic and the
smart lamp topic.
Set the SrcTopic parameter to the topic of the app: /al987654321/ControlApp/user/update.
Set the DstTopics parameter to the topic of the smart lamp: /al123456789/light/user/set.
Develop the mobile app.
In this example, the mobile app and IoT Platform use HTTPS to communicate with each
other.
The user scans the QR code to bind the app to the smart lamp.
After the app sends a request to the server to bind a device, the server binds the
smart lamp and returns the device name. The returned name is specified by the deviceName
parameter. In this example, the smart lamp device is named light.
The user sends control commands through the app.
The topic to which the app sends commands is /al987654321/ControlApp/user/update. Only JSON format commands are supported.
IoT Platform routes commands to the topic of the smart lamp device based on the defined
message routing relationship. The topic is /al123456789/light/user/set.
After receiving the commands, the smart lamp device performs the corresponding operations.
Note You can configure the app to notify your server to delete the message routing relationship
and your server calls the DeleteTopicRouteTable operation to delete the message routing relationship. After the routing relationship
is deleted, the app no longer controls the smart lamp.