-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. 设备信息新增设备类型,支持网关场景。 3. 新增设备动态注册功能及示例。
- Loading branch information
yougaliu
committed
Mar 11, 2020
1 parent
9664d19
commit 6e4e6a9
Showing
19 changed files
with
1,110 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
/* #undef AUTH_MODE_CERT */ | ||
#define AUTH_MODE_KEY | ||
/* #undef AUTH_WITH_NOTLS */ | ||
#define GATEWAY_ENABLED | ||
/* #undef GATEWAY_ENABLED */ | ||
/* #undef COAP_COMM_ENABLED */ | ||
#define OTA_MQTT_CHANNEL | ||
/* #undef SYSTEM_COMM */ | ||
/* #undef EVENT_POST_ENABLED */ | ||
/* #undef ACTION_ENABLED*/ | ||
/* #undef DEV_DYN_REG_ENABLED */ | ||
/* #undef ACTION_ENABLED */ | ||
#define DEV_DYN_REG_ENABLED | ||
/* #undef LOG_UPLOAD */ | ||
/* #undef IOT_DEBUG */ | ||
/* #undef DEBUG_DEV_INFO_USED */ | ||
/* #undef AT_TCP_ENABLED */ | ||
/* #undef AT_UART_RECV_IRQ */ | ||
/* #undef AT_OS_USED */ | ||
/* #undef AT_DEBUG */ | ||
/* #undef OTA_USE_HTTPS */ | ||
/* #undef GATEWAY_ENABLED*/ | ||
#define OTA_USE_HTTPS | ||
/* #undef GATEWAY_ENABLED */ | ||
/* #undef MULTITHREAD_ENABLED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making IoT Hub available. | ||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#ifndef QLCOUD_IOT_EXPORT_DYNREG_H_ | ||
#define QLCOUD_IOT_EXPORT_DYNREG_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "qcloud_iot_export.h" | ||
|
||
/** | ||
* @brief Do dynamic register/create device | ||
* | ||
* @param pDevInfo In: device info with [ProductId, ProductKey, DeviceName] | ||
* Out: device info with [ProductId, DeviceName, DeviceSecret or Device cert/key file] | ||
* | ||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure | ||
*/ | ||
int IOT_DynReg_Device(DeviceInfo *pDevInfo); | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //QLCOUD_IOT_EXPORT_DYNREG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making IoT Hub available. | ||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#include "utils_getopt.h" | ||
#include "qcloud_iot_export.h" | ||
#include "qcloud_iot_import.h" | ||
|
||
#ifdef AUTH_MODE_CERT | ||
/* NULL cert file */ | ||
#define QCLOUD_IOT_NULL_CERT_FILENAME "YOUR_DEVICE_CERT_FILE_NAME" | ||
/* NULL key file */ | ||
#define QCLOUD_IOT_NULL_KEY_FILENAME "YOUR_DEVICE_PRIVATE_KEY_FILE_NAME" | ||
#else | ||
/* NULL device secret */ | ||
#define QCLOUD_IOT_NULL_DEVICE_SECRET "YOUR_IOT_PSK" | ||
#endif | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
int c; | ||
while ((c = utils_getopt(argc, argv, "c:")) != EOF) | ||
switch (c) { | ||
case 'c': | ||
if (HAL_SetDevInfoFile(utils_optarg)) | ||
return -1; | ||
break; | ||
|
||
default: | ||
HAL_Printf("usage: %s [options]\n" | ||
" [-c <config file for DeviceInfo>] \n" | ||
, argv[0]); | ||
|
||
return -1; | ||
} | ||
|
||
|
||
//init log level | ||
IOT_Log_Set_Level(eLOG_DEBUG); | ||
|
||
int ret; | ||
DeviceInfo sDevInfo; | ||
bool infoNullFlag = false; | ||
|
||
memset((char *)&sDevInfo, 0, sizeof(DeviceInfo)); | ||
|
||
ret = HAL_GetDevInfo(&sDevInfo); | ||
|
||
#ifndef GATEWAY_ENABLED | ||
sDevInfo.dev_type = eCOMMON_DEV; | ||
#else | ||
sDevInfo.dev_type = eGW_SUB_DEV; | ||
#endif | ||
|
||
#ifdef AUTH_MODE_CERT | ||
/* just demo the cert/key files are empty */ | ||
if (!strcmp(sDevInfo.dev_cert_file_name, QCLOUD_IOT_NULL_CERT_FILENAME) | ||
|| !strcmp(sDevInfo.dev_key_file_name, QCLOUD_IOT_NULL_KEY_FILENAME)) { | ||
Log_d("dev Cert not exist!"); | ||
infoNullFlag = true; | ||
} else { | ||
Log_d("dev Cert exist"); | ||
} | ||
#else | ||
/* just demo the PSK is empty */ | ||
if (!strcmp(sDevInfo.device_secret, QCLOUD_IOT_NULL_DEVICE_SECRET)) { | ||
Log_d("dev psk not exist!"); | ||
infoNullFlag = true; | ||
} else { | ||
Log_d("dev psk exist"); | ||
} | ||
#endif | ||
|
||
/* device cert/key files or PSK is empty, do dynamic register to fetch */ | ||
if (infoNullFlag) { | ||
if (QCLOUD_RET_SUCCESS == IOT_DynReg_Device(&sDevInfo)) { | ||
ret = HAL_SetDevInfo(&sDevInfo); | ||
if (QCLOUD_RET_SUCCESS != ret) { | ||
Log_e("devices info save fail"); | ||
} else { | ||
#ifdef AUTH_MODE_CERT | ||
Log_d("dynamic register success, productID: %s, devName: %s, CertFile: %s, KeyFile: %s", \ | ||
sDevInfo.product_id, sDevInfo.device_name, sDevInfo.dev_cert_file_name, sDevInfo.dev_key_file_name); | ||
#else | ||
Log_d("dynamic register success,productID: %s, devName: %s, device_secret: %s", \ | ||
sDevInfo.product_id, sDevInfo.device_name, sDevInfo.device_secret); | ||
#endif | ||
} | ||
} else { | ||
Log_e("%s dynamic register fail", sDevInfo.device_name); | ||
} | ||
} | ||
|
||
return ret; | ||
} |
Oops, something went wrong.