
`$broadcast/rxd/${ProductId}/${DeviceName}`, where ${ProductId} and ${DeviceName}` represent the specific product ID and device name.ProductId and the Payload of the broadcast message. Then, all online devices that have subscribed to the broadcast topic under the product will receive the broadcast message with the Payload.airConditioner1, airConditioner2, and other devices as instructed in Device Interconnection.CMakeLists.txt to ensure that the following options exist:set(BUILD_TYPE "release")set(COMPILE_TOOLS "gcc")set(PLATFORM "linux")set(FEATURE_MQTT_COMM_ENABLED ON)set(FEATURE_BROADCAST_ENABLED ON)set(FEATURE_AUTH_MODE "KEY")set(FEATURE_AUTH_WITH_NOTLS OFF)set(FEATURE_DEBUG_DEV_INFO_USED OFF)
./cmake_build.sh
broadcast_sample is in the output/release/bin folder.airConditioner1 device created above in a JSON file aircond_device_info1.json:{"auth_mode":"KEY","productId":"KL4J2****8","deviceName":"airConditioner1","key_deviceinfo":{"deviceSecret":"zOZXUaycuwlePt****8dBA=="}}
airConditioner2 device in another JSON file aircond_device_info2.json:{"auth_mode":"KEY","productId":"KL4J2****8","deviceName":"airConditioner2","key_deviceinfo":{"deviceSecret":"+IiVNsyKRh0AW****IE07A=="}}
broadcast_sample demobroadcast_sample demo, and you will see that all the demos subscribe to the $broadcast/rxd/${productID}/${deviceName} topic and are in the waiting status.
The output of the airConditioner1 device is as follows:./broadcast_sample -c ./aircond_device_info1.json -l 100INF|2020-08-03 22:50:28|qcloud_iot_device.c|iot_device_info_set(50): SDK_Ver: 3.2.0, Product_ID: KL4J2****8, Device_Name: airConditioner1DBG|2020-08-03 22:50:28|HAL_TLS_mbedtls.c|HAL_TLS_Connect(200): Setting up the SSL/TLS structure...DBG|2020-08-03 22:50:28|HAL_TLS_mbedtls.c|HAL_TLS_Connect(242): Performing the SSL/TLS handshake...DBG|2020-08-03 22:50:28|HAL_TLS_mbedtls.c|HAL_TLS_Connect(243): Connecting to /KL4J2****8.iotcloud.tencentdevices.com/8883...INF|2020-08-03 22:50:28|HAL_TLS_mbedtls.c|HAL_TLS_Connect(265): connected with /KL4J2****8.iotcloud.tencentdevices.com/8883...INF|2020-08-03 22:50:28|mqtt_client.c|IOT_MQTT_Construct(113): mqtt connect with id: 9**** successINF|2020-08-03 22:50:28|broadcast_sample.c|main(197): Cloud Device Construct SuccessDBG|2020-08-03 22:50:28|mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(142): topicName=$broadcast/rxd/KL4J2****8/airConditioner1|packet_id=*****INF|2020-08-03 22:50:28|broadcast_sample.c|_mqtt_event_handler(49): subscribe success, packet-id=*****DBG|2020-08-03 22:50:28|broadcast.c|_broadcast_event_callback(37): broadcast topic subscribe success
airConditioner2 device is as follows:./broadcast_sample -c ./aircond_device_info2.json -l 100INF|2020-08-03 22:51:24|qcloud_iot_device.c|iot_device_info_set(50): SDK_Ver: 3.2.0, Product_ID: KL4J2****8, Device_Name: airConditioner2DBG|2020-08-03 22:51:24|HAL_TLS_mbedtls.c|HAL_TLS_Connect(200): Setting up the SSL/TLS structure...DBG|2020-08-03 22:51:24|HAL_TLS_mbedtls.c|HAL_TLS_Connect(242): Performing the SSL/TLS handshake...DBG|2020-08-03 22:51:24|HAL_TLS_mbedtls.c|HAL_TLS_Connect(243): Connecting to /KL4J2****8.iotcloud.tencentdevices.com/8883...INF|2020-08-03 22:51:24|HAL_TLS_mbedtls.c|HAL_TLS_Connect(265): connected with /KL4J2****8.iotcloud.tencentdevices.com/8883...INF|2020-08-03 22:51:25|mqtt_client.c|IOT_MQTT_Construct(113): mqtt connect with id: f**** successINF|2020-08-03 22:51:25|broadcast_sample.c|main(197): Cloud Device Construct SuccessDBG|2020-08-03 22:51:25|mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(142): topicName=$broadcast/rxd/KL4J2****8/airConditioner2|packet_id=*****INF|2020-08-03 22:51:25|broadcast_sample.c|_mqtt_event_handler(49): subscribe success, packet-id=******DBG|2020-08-03 22:51:25|broadcast.c|_broadcast_event_callback(37): broadcast topic subscribe success
PublishBroadcastMessage to send a broadcast messageairConditioner1 device, and you can see that the message sent by the server has been received.DBG|2020-08-03 22:55:32|broadcast.c|_broadcast_message_cb(25): topic=$broadcast/rxd/KL4J2****8/airConditioner1INF|2020-08-03 22:55:32|broadcast.c|_broadcast_message_cb(26): len=6, topic_msg=closedINF|2020-08-03 22:55:32|broadcast_sample.c|_broadcast_message_handler(134): broadcast message=closed
airConditioner2 device, and you can see that the message sent by the server has also been received.DBG|2020-08-03 22:55:32|broadcast.c|_broadcast_message_cb(25): topic=$broadcast/rxd/KL4J2****8/airConditioner2INF|2020-08-03 22:55:32|broadcast.c|_broadcast_message_cb(26): len=6, topic_msg=closedINF|2020-08-03 22:55:32|broadcast_sample.c|_broadcast_message_handler(134): broadcast message=closed
Feedback