Skip to content

Commit

Permalink
Merge branch 'master-mirror' into 'master' (merge request !17)
Browse files Browse the repository at this point in the history
fix: 1. 修复WiFi配网可能获取不到token回复的bug 2. sample增加网络断连超时的log 3. 更新版本到v3.1.9
fix:
1. 修复WiFi配网可能获取不到token回复的bug
2. sample增加网络断连超时的log
3. 更新版本到v3.1.9
  • Loading branch information
esma committed Aug 30, 2021
2 parents 93674d6 + 2fbf71f commit c375055
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 42 deletions.
74 changes: 45 additions & 29 deletions include/exports/qcloud_iot_export_gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ typedef struct {
GatewayEventHandleFun event_handler; /* event handler for gateway user*/
} GatewayInitParam;

/* The structure of subdevice bindinfo */
typedef struct _SubdevBindInfo {
char product_id[MAX_SIZE_OF_PRODUCT_ID + 1];
char device_name[MAX_SIZE_OF_DEVICE_NAME + 1];
struct _SubdevBindInfo *next;
} SubdevBindInfo;

/* The structure of subdevice bindlist */
typedef struct _SubdevBindList {
SubdevBindInfo *bindlist_head;
int bind_num;
} SubdevBindList;

typedef struct _gw_change_notify {
char *devices;
int status;
} gw_change_notify_t;

/* gateway automation struct */
typedef struct {
void *client;
void *user_data;
int (*set_automation_callback)(char *automation_id, int mation_status, char *params, void *user_data);
int (*del_automation_callback)(char *automation_id, void *user_data);
} QCLOUD_IO_GATEWAY_AUTOMATION_T;

#define DEFAULT_GATEWAY_INIT_PARAMS \
{ \
DEFAULT_MQTTINIT_PARAMS, NULL, NULL \
Expand Down Expand Up @@ -189,24 +215,6 @@ int IOT_Gateway_Yield(void *client, uint32_t timeout_ms);
*/
void *IOT_Gateway_Get_Mqtt_Client(void *client);

/* The structure of subdevice bindinfo */
typedef struct _SubdevBindInfo {
char product_id[MAX_SIZE_OF_PRODUCT_ID + 1];
char device_name[MAX_SIZE_OF_DEVICE_NAME + 1];
struct _SubdevBindInfo *next;
} SubdevBindInfo;

/* The structure of subdevice bindlist */
typedef struct _SubdevBindList {
SubdevBindInfo *bindlist_head;
int bind_num;
} SubdevBindList;

typedef struct _gw_change_notify {
char *devices;
int status;
} gw_change_notify_t;

#ifdef MULTITHREAD_ENABLED
/**
* @brief Start the default yield thread to read and handle gateway msg
Expand All @@ -233,13 +241,7 @@ void IOT_Gateway_Stop_Yield_Thread(void *pClient);
*/
bool IOT_Gateway_Get_Yield_Status(void *pClient, int *exit_code);

/* gateway automation struct */
typedef struct {
void *client;
void *user_data;
int (*set_automation_callback)(char *automation_id, int mation_status, char *params, void *user_data);
int (*del_automation_callback)(char *automation_id, void *user_data);
} QCLOUD_IO_GATEWAY_AUTOMATION_T;
#endif

/**
* @brief automation local execution log report
Expand Down Expand Up @@ -278,10 +280,24 @@ int IOT_Gateway_GetAutoMationList(void *client);
* @return >= QCLOUD_RET_SUCCESS is success other is failed
*/
int IOT_Gateway_EnableLocalAutoMation(void *client, QCLOUD_IO_GATEWAY_AUTOMATION_T *automation);

#endif

int IOT_Gateway_Subdev_GetBindList(void *client, GatewayParam *param, SubdevBindList *subdev_bindlist);
/**
* @brief get sub-device bind list from cloud platform
*
* @param client handle to gateway client
* @param param gateway parameters
* @param subdev_bindlist output subdev bind list
*
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
*/
int IOT_Gateway_Subdev_GetBindList(void *client, GatewayParam *param, SubdevBindList *subdev_bindlist);
/**
* @brief destory sub dev bind list
*
* @param subdev_bindlist input subdev bind list pointer, ref IOT_Gateway_Subdev_GetBindList
* output param subdev_bindlist
*
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
*/
void IOT_Gateway_Subdev_DestoryBindList(SubdevBindList *subdev_bindlist);

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion include/qcloud_iot_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
#include "platform.h"

/* IoT C-SDK version info */
#define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.8"
#define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.9"

/**************** QCloud IoT C-SDK constants begin ************************/

Expand Down
9 changes: 8 additions & 1 deletion samples/asr/asr_data_template_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("Exit loop caused of errCode: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/file_manage/file_mqtt_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/mqtt/mqtt_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/ota/ota_mqtt_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/raw_data/raw_data_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/resource/resource_mqtt_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/scenarized/light_data_template_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,14 @@ int main(int argc, char **argv)
continue;
}
if (rc != QCLOUD_RET_SUCCESS) {
Log_e("Exit loop caused of errCode: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
9 changes: 8 additions & 1 deletion samples/wifi_config/wifi_config_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,14 @@ int main(int argc, char **argv)
HAL_SleepMs(1000);
continue;
} else if (rc != QCLOUD_RET_SUCCESS && rc != QCLOUD_RET_MQTT_RECONNECTED) {
Log_e("exit with error: %d", rc);
if (rc == QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT) {
Log_e(
"exit. mqtt reconnect timeout! Please check the network connection, or try to increase "
"MAX_RECONNECT_WAIT_INTERVAL(%d)",
MAX_RECONNECT_WAIT_INTERVAL);
} else {
Log_e("exit with error: %d", rc);
}
break;
}

Expand Down
26 changes: 22 additions & 4 deletions sdk_src/wifi_config/qcloud_wifi_config_device_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static int sg_bind_reply_code = -1;
typedef struct {
bool sub_ready;
bool send_ready;
bool reply_ready;
int reply_code;
} TokenHandleData;

Expand Down Expand Up @@ -120,6 +121,7 @@ static void _on_message_callback(void *pClient, MQTTMessage *message, void *user
if (code_json) {
TokenHandleData *app_data = (TokenHandleData *)userData;
app_data->reply_code = code_json->valueint;
app_data->reply_ready = true;
Log_d("token reply code = %d", code_json->valueint);

sg_bind_reply_code = app_data->reply_code;
Expand Down Expand Up @@ -228,7 +230,8 @@ static int _send_token_wait_reply(void *client, DeviceInfo *dev_info, TokenHandl

wait_cnt = 3;
publish_token:
ret = _publish_token_msg(client, dev_info, sg_token_str);
app_data->reply_ready = false;
ret = _publish_token_msg(client, dev_info, sg_token_str);
if (ret < 0 && (wait_cnt-- > 0)) {
Log_e("Client publish token failed: %d", ret);
if (IOT_MQTT_IsConnected(client)) {
Expand All @@ -255,6 +258,16 @@ static int _send_token_wait_reply(void *client, DeviceInfo *dev_info, TokenHandl
ret = QCLOUD_ERR_FAILURE;
}

wait_cnt = 10;
while (!app_data->reply_ready && (wait_cnt-- > 0)) {
IOT_MQTT_Yield(client, 1000);
Log_i("wait for bind token replay result...");
}
ret = 0;
if (!app_data->reply_ready) {
Log_e("Client publish token timeout");
ret = QCLOUD_ERR_FAILURE;
}
return ret;
}

Expand Down Expand Up @@ -348,9 +361,10 @@ static int _mqtt_send_token(void)

// token handle data
TokenHandleData app_data;
app_data.sub_ready = false;
app_data.send_ready = false;
app_data.reply_code = 404;
app_data.sub_ready = false;
app_data.send_ready = false;
app_data.reply_ready = false;
app_data.reply_code = 404;

sg_bind_reply_code = app_data.reply_code;

Expand Down Expand Up @@ -398,6 +412,10 @@ int qiot_device_bind(void)
Log_i("WIFI_MQTT_CONNECT_SUCCESS");
PUSH_LOG("WIFI_MQTT_CONNECT_SUCCESS");
}
if (sg_bind_reply_code != 0) {
PUSH_LOG("device bind error. reply code: %d", sg_bind_reply_code);
return QCLOUD_ERR_FAILURE;
}
return ret;
}

Expand Down

0 comments on commit c375055

Please sign in to comment.