Esempio n. 1
0
static int MqttSample_CmdDisconnect(struct MqttSampleContext *ctx)
{
    int err;
    err = Mqtt_PackDisconnectPkt(ctx->mqttbuf);
    if(MQTTERR_NOERROR != err) {
        printf("Critical bug: failed to pack the disconnect packet.\n");
        return -1;
    }

    return 1;
}
/**
  * @brief 设备主动断开MQTT连接
  * @param  ctx:上下文变量
  * @retval ret:0,成功,<0 失败
  **/
static int MqttSample_CmdDisconnect(struct MqttSampleContext *ctx)
{
    int err;
    printf("%s %d\n", __func__, __LINE__);
    err = Mqtt_PackDisconnectPkt(ctx->mqttbuf);
    if(MQTTERR_NOERROR != err)
    {
        printf("Critical bug: failed to pack the disconnect packet.\n");
        return -1;
    }
    Mqtt_SendPkt(ctx->mqttctx, ctx->mqttbuf, 0);
    MqttBuffer_Reset(ctx->mqttbuf);
    return 1;
}