Data Transmission

Last Updated on : 2024-11-20 08:51:44download

The following code block uses the gateway as an example to describe the process of data sending.

static void __send_result_cb(SEND_ST_T st, dev_send_data_t *msg)
{
    switch(st) {
        case SEND_ST_OK: {
            //TODO: Data is sent successfully.
            break;
        }
        default: {
            //TODO: Failed to send the data.
            break;
        }
    }
}

static void send_data_demo(void)
{
    dev_send_data_t send_data;

        memset(&send_data, 0, sizeof(dev_send_data_t));

    send_data.zcl_id = 0;  /// The user-defined ID, which is returned in the sending callback.
    send_data.qos = QOS_1; /// Data packet will be sent again if no acknowledgement is received.
    send_data.direction = ZCL_DATA_DIRECTION_SERVER_TO_CLIENT;
    send_data.command_id = CMD_REPORT_ATTRIBUTES_COMMAND_ID;       /// The command used to report property values.
    send_data.addr.mode = SEND_MODE_GW;                            /// Send data to the gateway.
    send_data.addr.type.gw.cluster_id = CLUSTER_ON_OFF_CLUSTER_ID; /// The on/off property.
    send_data.addr.type.gw.src_ep = 1; /// The endpoint.
    send_data.delay_time = 0;   /// The timer for delaying packet sending.
    send_data.random_time = 0;  /// The time range for random sending.
    send_data.data.zg.attr_sum = 1;  /// The number of properties to be reported.
    send_data.data.zg.attr[0].attr_id = ATTR_ON_OFF_ATTRIBUTE_ID; /// The status of the on/off property.
    send_data.data.zg.attr[0].type = ATTR_BOOLEAN_ATTRIBUTE_TYPE; /// The data type of the property.
    send_data.data.zg.attr[0].value_size = 1;                     /// The data length of the property.
    send_data.data.zg.attr[0].value[0] = 1; /// 1 means ON. 0 means OFF.
    dev_zigbee_send_data(&send_data, __send_result_cb, 1000); /// Send the data packet. `1000` indicates that the maximum duration of packet retransmission is one second.
}