MQTT把上海的服务站改为新加坡

描述:

要在国内测试新加坡设备,因为mqtt是就近原则,所以在国内测试肯定是连接的是上海的站点,所以需要在初始化MQTT时候修改下参数。在//begin bailong  //end

int mqtt_client(mqttClinetInfo * info)
{
    int rc = 0;
    void *pclient;
    int stack_used = 0;
    iotx_conn_info_pt pconn_info;
    iotx_mqtt_param_t mqtt_params;
    hal_os_thread_param_t task_parms = {0};

	//begin bailong
	int domain_type = 0;   
	domain_type = IOTX_CLOUD_REGION_SINGAPORE;  
	IOT_Ioctl(IOTX_IOCTL_SET_DOMAIN, (void *)&domain_type);
	//end

    /* Device AUTH */
    if (0 != IOT_SetupConnInfo(info->product_key, info->device_name, info->device_secret, (void **)&pconn_info)) {
        EXAMPLE_TRACE("AUTH request failed!");
        return -1;
    }
    /* Initialize MQTT parameter */
    memset(&mqtt_params, 0x0, sizeof(mqtt_params));
    mqtt_params.port = pconn_info->port;
    mqtt_params.host = pconn_info->host_name;
    mqtt_params.client_id = pconn_info->client_id;
    mqtt_params.username = pconn_info->username;
    mqtt_params.password = pconn_info->password;
    mqtt_params.pub_key = pconn_info->pub_key;
    mqtt_params.request_timeout_ms = 2000;
	//bejin jian 2020.3.16   put 0=>1
    mqtt_params.clean_session = 1;
	//end
    mqtt_params.keepalive_interval_ms = 60000;
    mqtt_params.read_buf_size = MQTT_MSGLEN;
    mqtt_params.write_buf_size = MQTT_MSGLEN;
    mqtt_params.handle_event.h_fp = event_handle;
    mqtt_params.handle_event.pcontext = NULL;


    /* Construct a MQTT client with specify parameter 使用指定参数构造MQTT客户机*/
    pclient = IOT_MQTT_Construct(&mqtt_params);
    if (NULL == pclient) {
        EXAMPLE_TRACE("MQTT construct failed");
        return -1;
    }
    pubclient = pclient;

    EXAMPLE_TRACE("TEST CASE");

    task_parms.stack_size = 6144;
    task_parms.name = "thread_message_receive";
    rc = HAL_ThreadCreate(&g_thread_receive, thread_message_receive, (void *)pclient, &task_parms, &stack_used);
    if (rc != 0) {
        goto do_exit;
    }

	//start publish thread
    initPublishThread(pclient);

    while (!gIsmqttThreadExit) {
        HAL_SleepMs(1000);
    }

    gIsResponseThreadExit = 1;
    gIsReceiveThreadExit = 1;
    HAL_SleepMs(5000);
    
do_exit:

    HAL_ThreadDelete(g_thread_response);
    HAL_ThreadDelete(g_thread_receive);
    IOT_MQTT_Destroy(&pclient);
    return rc;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值