IoT Platform supports broadcast communication. You can broadcast a message to all devices under a product. In this case, the devices do not need to subscribe to a broadcast topic to receive the message. You can also broadcast a message to all devices that subscribe to a specified topic. A device must be online to receive the message that is sent by the server. This article describes how to configure Link SDK for C to achieve broadcast communication.

Prerequisites

Background information

  • For more information about broadcast communication, see Broadcast messages.
  • IoT Platform provides the PubBroadcast operation to achieve broadcast communication. For more information, see PubBroadcast.

Process

The application program calls the API operations of Link SDK for C to connect with IoT Platform over MQTT, and then receive and respond to broadcast messages sent by IoT Platform.

The following figure shows the process. In this example, the demos/mqtt_broadcast_demo.c application program is used.

Process

To use this feature, you must establish an MQTT connection. For more information about the related API operations, see aiot_mqtt_api.h.

Usage notes

  • Messages can be broadcasted only to online devices in a product.
  • When you broadcast a message to specified online devices, you must specify the broadcast topic to which the devices subscribe. In this case, you can call the PubBroadcast operation once per second.
  • When you broadcast a message to all online devices, the devices do not need to subscribe to a broadcast topic. In this case, you can call the PubBroadcast operation once per minute.
  • The size of a message body can be up to 64 KB.

Examples