IoT Platform supports broadcast communication. That is, IoT Platform allows a server to broadcast a message to multiple devices under a product. The devices only need to subscribe the broadcast topic to receive the broadcast message sent by the server. This topic describes how to configure broadcast communication.


You have multiple thermometers connected to IoT Platform, and need to send the same precision setting command to all these thermometers from your server.

All the devices subscribe to the same broadcast topic, and the server calls the PubBroadcast operation to publish the message to this topic.

Prepare the development environment

In this example, both the devices and the server use Java SDKs, so you need to prepare the Java development environment first. You can download Java tools at Java official website and install the Java development environment.

Add the following Maven dependencies to import the device SDK (Link Kit Java SDK) and IoT SDK:

 < dependency>

Create a product and devices

  1. Log on to the IoT Platform console.
  2. In the left-side navigation pane, choose Devices > Products.
  3. Click Create Product to create a thermometer product.

    For more information, see Create a product.

  4. In the left-side navigation pane, choose Devices and add two thermometer devices under the thermometer product that has been created.

    For more information, see Create multiple devices at a time.

Configure the device SDK

Connect the device SDK to IoT Platform and subscribe to the broadcast topic.

  • Connect the device SDK to IoT Platform.
    • Configure device authentication information.
      final String productKey = "XXXXXX";
      final String deviceName = "XXXXXX";
      final String deviceSecret = "XXXXXXXXX";
      final String region = "XXXXXX";

      productKey, deviceName, and deviceSecret: device authentication information. You can obtain the values of these parameters on the device details page in the IoT Platform console.

      region: the ID of the region where the device is located. For more information about region IDs, see Regions and zones.

    • Set connection initialization parameters, including MQTT connection information, device information, and initial device status.
      LinkKitInitParams params = new LinkKitInitParams();
      // Configure MQTT connection information. Link Kit uses MQTT as the underlying protocol. 
      IoTMqttClientConfig config = new IoTMqttClientConfig();
      config.productKey = productKey;
      config.deviceName = deviceName;
      config.deviceSecret = deviceSecret;
      config.channelHost = productKey + ".iot-as-mqtt." + region + "";
      // Configure device information.
      DeviceInfo deviceInfo = new DeviceInfo();
      deviceInfo.productKey = productKey;
      deviceInfo.deviceName = deviceName;
      deviceInfo.deviceSecret = deviceSecret;
      // Register the initial device status.
      Map<String, ValueWrapper> propertyValues = new HashMap<String, ValueWrapper>();
      params.mqttClientConfig = config;
      params.deviceInfo = deviceInfo;
      params.propertyValues = propertyValues;
    • Initialize the connection.
      // Initialize the connection and set the callback that is called when the initialization is successful.
      LinkKit.getInstance().init(params, new ILinkKitConnectListener() {
           public void onError(AError aError) {
               System.out.println("Init error:" + aError);
           // Set the callback that is called when the initialization is successful.
           public void onInitDone(InitResult initResult) {
               System.out.println("Init done:" + initResult);
  • Subscribe to the broadcast topic. Set the onInitDone callback to send a subscription request.

    You do not need to create the broadcast topic in advance. Instead, directly enter the broadcast topic in the format of /broadcast/${productKey}/Custom field.

    In this example, the broadcast topic is "/broadcast/" + productKey + "/userDefine".

    Note The same broadcast topic must be configured in the device SDK and IoT SDK.
    public void onInitDone(InitResult initResult) {
          // Set the broadcast topic to which the device subscribes. You do not need to create this topic in the IoT Platform console.
         MqttSubscribeRequest request = new MqttSubscribeRequest();
         request.topic = "/broadcast/" + productKey + "/userDefine";
         request.isSubscribe = true;
         // Send a subscription request and set the callbacks that are called when the subscription succeeds and fails, respectively.
         LinkKit.getInstance().subscribe(request, new IConnectSubscribeListener() {
             public void onSuccess() {
             public void onFailure(AError aError) {
         // Set the listener for listening to subscribed messages.
         IConnectNotifyListener notifyListener = new IConnectNotifyListener() {
             // Define the callback that is called when a subscribed message is received.
             public void onNotify(String connectId, String topic, AMessage aMessage) {
                     "received message from " + topic + ":" + new String((byte[])aMessage.getData()));
             public boolean shouldHandle(String s, String s1) {
                 return false;
             public void onConnectStateChange(String s, ConnectState connectState) {
         // Register the listener for listening to subscribed messages.

Configure the IoT SDK

Configure the IoT SDK to send a broadcast message.

  • Configure identity verification information.
     String regionId = "The ID of the region where the device is located";
     String accessKey = "The AccessKey ID of your Alibaba Cloud account";
     String accessSecret = "The AccessKey Secret of your Alibaba Cloud account";
     final String productKey = "The key of the product";
  • Configure the IoT SDK to call the PubBroadcast operation to publish a broadcast message.
    // Construct a client.
     DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKey, accessSecret);
     IAcsClient client = new DefaultAcsClient(profile);
     PubBroadcastRequest request = new PubBroadcastRequest();
     // Set the topic to which the broadcast message is published. This topic must be same as the broadcast topic to which the device subscribes.
     request.setTopicFullName("/broadcast/" + productKey + "/userDefine");
     // Set the message content. The message content must be encoded in Base64. Otherwise, the message content will be garbled characters.
  • Publish the broadcast message.
    try {
        PubBroadcastResponse response = client.getAcsResponse(request);
        System.out.println("broadcast pub success?:" + response.getSuccess());
    } catch (Exception e) {


Verify that the message broadcast by the IoT SDK to devices is "{\"accuracy\":0.001,\"time\":now}".

In logs of the two thermometers, verify that the message {"accuracy":0.001,"time":now} is received.

Appendix: demo

Click here to download and view the complete demo for this example.