文档

lv_message_publish_cb

更新时间:

调用该接口,在该函数回调中,发送SDK所需要发送的物联网消息。

接口详情

typedef int (*lv_message_publish_cb)(const lv_message_publish_param_s *message)

接口中相关参数说明如下。

参数

类型

说明

message

const lv_message_publish_param_s*

消息结构体。

示例代码

说明

示例代码仅供参考,完整内容,请参见SDK中的实际代码。

//Demo中定义了回调函数linkkit_message_publish_cb,作为lv_message_publish_cb的实现
callback.message_publish_cb = linkkit_message_publish_cb;

//Demo中定义了回调函数linkkit_message_publish_cb
int linkkit_message_publish_cb(const lv_message_publish_param_s *param) {
    iotx_mqtt_topic_info_t topic_msg;

    /* Initialize topic information */
    memset(&topic_msg, 0x0, sizeof(iotx_mqtt_topic_info_t));
    topic_msg.qos = param->qos;
    topic_msg.retain = 0;
    topic_msg.dup = 0;
    topic_msg.payload = param->message;
    topic_msg.payload_len = strlen(param->message);
    int rc = IOT_MQTT_Publish(NULL, param->topic, &topic_msg);
    if (rc < 0) {
        printf("Publish msg error:%d\n", rc);
        return -1;
    }

    return 0;
}