diff --git a/lib/AliyunIoTSDK/.piopm b/lib/aliyun_iot_sdk/.piopm similarity index 100% rename from lib/AliyunIoTSDK/.piopm rename to lib/aliyun_iot_sdk/.piopm diff --git a/lib/AliyunIoTSDK/CHANGES.txt b/lib/aliyun_iot_sdk/CHANGES.txt similarity index 100% rename from lib/AliyunIoTSDK/CHANGES.txt rename to lib/aliyun_iot_sdk/CHANGES.txt diff --git a/lib/AliyunIoTSDK/LICENSE.txt b/lib/aliyun_iot_sdk/LICENSE.txt similarity index 100% rename from lib/AliyunIoTSDK/LICENSE.txt rename to lib/aliyun_iot_sdk/LICENSE.txt diff --git a/lib/AliyunIoTSDK/README.md b/lib/aliyun_iot_sdk/README.md similarity index 100% rename from lib/AliyunIoTSDK/README.md rename to lib/aliyun_iot_sdk/README.md diff --git a/lib/AliyunIoTSDK/keywords.txt b/lib/aliyun_iot_sdk/keywords.txt similarity index 100% rename from lib/AliyunIoTSDK/keywords.txt rename to lib/aliyun_iot_sdk/keywords.txt diff --git a/lib/AliyunIoTSDK/library.json b/lib/aliyun_iot_sdk/library.json similarity index 100% rename from lib/AliyunIoTSDK/library.json rename to lib/aliyun_iot_sdk/library.json diff --git a/lib/AliyunIoTSDK/library.properties b/lib/aliyun_iot_sdk/library.properties similarity index 100% rename from lib/AliyunIoTSDK/library.properties rename to lib/aliyun_iot_sdk/library.properties diff --git a/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp b/lib/aliyun_iot_sdk/src/aliyun_iot_sdk.cpp similarity index 98% rename from lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp rename to lib/aliyun_iot_sdk/src/aliyun_iot_sdk.cpp index 15dc151..ec12650 100644 --- a/lib/AliyunIoTSDK/src/AliyunIoTSDK.cpp +++ b/lib/aliyun_iot_sdk/src/aliyun_iot_sdk.cpp @@ -1,6 +1,6 @@ /** * - * Filename: AliyunIoTSDK.cpp + * Filename: aliyun_iot_sdk.cpp * * Description: basic SDK for ESP32 * @@ -10,10 +10,11 @@ * **/ -#include "AliyunIoTSDK.h" #include #include +#include "aliyun_iot_sdk.h" + #define CHECK_INTERVAL 30000 #define MESSAGE_BUFFER_SIZE 10 #define MQTT_CONNECT_RETRY_MAX 3 @@ -148,12 +149,12 @@ int AliyunIoTSDK::mqttCheckConnect() { return mqttStatus; } -int AliyunIoTSDK::begin(Client &espClient, +int AliyunIoTSDK::begin(PubSubClient &mqttClient, const char *_productKey, const char *_deviceName, const char *_deviceSecret, const char *_region) { - client = new PubSubClient(espClient); + client = new PubSubClient(mqttClient); productKey = _productKey; deviceName = _deviceName; deviceSecret = _deviceSecret; diff --git a/lib/AliyunIoTSDK/src/AliyunIoTSDK.h b/lib/aliyun_iot_sdk/src/aliyun_iot_sdk.h similarity index 97% rename from lib/AliyunIoTSDK/src/AliyunIoTSDK.h rename to lib/aliyun_iot_sdk/src/aliyun_iot_sdk.h index 84fcc2d..ec33946 100644 --- a/lib/AliyunIoTSDK/src/AliyunIoTSDK.h +++ b/lib/aliyun_iot_sdk/src/aliyun_iot_sdk.h @@ -1,6 +1,6 @@ /** * - * Filename: AliyunIoTSDK.h + * Filename: aliyun_iot_sdk.h * * Description: header file of basic SDK for ESP32 * @@ -58,13 +58,13 @@ public: /** * Initialize and connect to AliyunIoT - * @param espClient : WiFi client + * @param mqttClient : PubSubClient * @param _productKey : AliyunIoT product key * @param _deviceName : AliyunIoT device name * @param _deviceSecret : AliyunIoT device secret * @param _region : AliyunIoT region */ - static int begin(Client &espClient, + static int begin(PubSubClient &mqttClient, const char *_productKey, const char *_deviceName, const char *_deviceSecret, diff --git a/lib/AliyunIoTSDK/如何使用 arduino-aliyun-iot-sdk 2 行代码接入物联网平台.md b/lib/aliyun_iot_sdk/如何使用 arduino-aliyun-iot-sdk 2 行代码接入物联网平台.md similarity index 100% rename from lib/AliyunIoTSDK/如何使用 arduino-aliyun-iot-sdk 2 行代码接入物联网平台.md rename to lib/aliyun_iot_sdk/如何使用 arduino-aliyun-iot-sdk 2 行代码接入物联网平台.md diff --git a/lib/IRext/include/ir_ac_apply.h b/lib/irext/include/ir_ac_apply.h similarity index 100% rename from lib/IRext/include/ir_ac_apply.h rename to lib/irext/include/ir_ac_apply.h diff --git a/lib/IRext/include/ir_ac_binary_parse.h b/lib/irext/include/ir_ac_binary_parse.h similarity index 100% rename from lib/IRext/include/ir_ac_binary_parse.h rename to lib/irext/include/ir_ac_binary_parse.h diff --git a/lib/IRext/include/ir_ac_build_frame.h b/lib/irext/include/ir_ac_build_frame.h similarity index 100% rename from lib/IRext/include/ir_ac_build_frame.h rename to lib/irext/include/ir_ac_build_frame.h diff --git a/lib/IRext/include/ir_ac_control.h b/lib/irext/include/ir_ac_control.h similarity index 100% rename from lib/IRext/include/ir_ac_control.h rename to lib/irext/include/ir_ac_control.h diff --git a/lib/IRext/include/ir_ac_parse_forbidden_info.h b/lib/irext/include/ir_ac_parse_forbidden_info.h similarity index 100% rename from lib/IRext/include/ir_ac_parse_forbidden_info.h rename to lib/irext/include/ir_ac_parse_forbidden_info.h diff --git a/lib/IRext/include/ir_ac_parse_frame_info.h b/lib/irext/include/ir_ac_parse_frame_info.h similarity index 100% rename from lib/IRext/include/ir_ac_parse_frame_info.h rename to lib/irext/include/ir_ac_parse_frame_info.h diff --git a/lib/IRext/include/ir_ac_parse_parameter.h b/lib/irext/include/ir_ac_parse_parameter.h similarity index 100% rename from lib/IRext/include/ir_ac_parse_parameter.h rename to lib/irext/include/ir_ac_parse_parameter.h diff --git a/lib/IRext/include/ir_decode.h b/lib/irext/include/ir_decode.h similarity index 100% rename from lib/IRext/include/ir_decode.h rename to lib/irext/include/ir_decode.h diff --git a/lib/IRext/include/ir_defs.h b/lib/irext/include/ir_defs.h similarity index 100% rename from lib/IRext/include/ir_defs.h rename to lib/irext/include/ir_defs.h diff --git a/lib/IRext/include/ir_tv_control.h b/lib/irext/include/ir_tv_control.h similarity index 100% rename from lib/IRext/include/ir_tv_control.h rename to lib/irext/include/ir_tv_control.h diff --git a/lib/IRext/include/ir_utils.h b/lib/irext/include/ir_utils.h similarity index 100% rename from lib/IRext/include/ir_utils.h rename to lib/irext/include/ir_utils.h diff --git a/lib/IRext/ir_ac_apply.c b/lib/irext/ir_ac_apply.c similarity index 100% rename from lib/IRext/ir_ac_apply.c rename to lib/irext/ir_ac_apply.c diff --git a/lib/IRext/ir_ac_binary_parse.c b/lib/irext/ir_ac_binary_parse.c similarity index 100% rename from lib/IRext/ir_ac_binary_parse.c rename to lib/irext/ir_ac_binary_parse.c diff --git a/lib/IRext/ir_ac_build_frame.c b/lib/irext/ir_ac_build_frame.c similarity index 100% rename from lib/IRext/ir_ac_build_frame.c rename to lib/irext/ir_ac_build_frame.c diff --git a/lib/IRext/ir_ac_control.c b/lib/irext/ir_ac_control.c similarity index 100% rename from lib/IRext/ir_ac_control.c rename to lib/irext/ir_ac_control.c diff --git a/lib/IRext/ir_ac_parse_forbidden_info.c b/lib/irext/ir_ac_parse_forbidden_info.c similarity index 100% rename from lib/IRext/ir_ac_parse_forbidden_info.c rename to lib/irext/ir_ac_parse_forbidden_info.c diff --git a/lib/IRext/ir_ac_parse_frame_info.c b/lib/irext/ir_ac_parse_frame_info.c similarity index 100% rename from lib/IRext/ir_ac_parse_frame_info.c rename to lib/irext/ir_ac_parse_frame_info.c diff --git a/lib/IRext/ir_ac_parse_parameter.c b/lib/irext/ir_ac_parse_parameter.c similarity index 100% rename from lib/IRext/ir_ac_parse_parameter.c rename to lib/irext/ir_ac_parse_parameter.c diff --git a/lib/IRext/ir_decode.c b/lib/irext/ir_decode.c similarity index 100% rename from lib/IRext/ir_decode.c rename to lib/irext/ir_decode.c diff --git a/lib/IRext/ir_tv_control.c b/lib/irext/ir_tv_control.c similarity index 100% rename from lib/IRext/ir_tv_control.c rename to lib/irext/ir_tv_control.c diff --git a/lib/IRext/ir_utils.c b/lib/irext/ir_utils.c similarity index 100% rename from lib/IRext/ir_utils.c rename to lib/irext/ir_utils.c diff --git a/src/aliot_client.cpp b/src/aliot_client.cpp new file mode 100644 index 0000000..7684240 --- /dev/null +++ b/src/aliot_client.cpp @@ -0,0 +1,67 @@ +/** + * + * Copyright (c) 2020-2024 IRbaby-IRext + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "defines.h" + +#include "serials.h" +#include "iot_hub.h" +#include "ir_baby.h" + +#include "aliyun_iot_sdk.h" + +#include "aliot_client.h" + +// external variable declarations +extern String g_mqtt_server; +extern String g_product_key; +extern String g_device_name; +extern String g_device_secret; + +extern String g_mqtt_client_id; +extern String g_mqtt_user_name; +extern String g_mqtt_password; +extern String g_upstream_topic; +extern String g_downstream_topic; +extern int g_mqtt_port; + +extern String g_aliot_region; + + +// private variable definitions +static bool force_disconnected = false; +static AliyunIoTSDK iot; + + +// public function definitions +int connectToAliyunIoT(PubSubClient &mqtt_client) { + + if (0 == iot.begin(mqtt_client, g_product_key.c_str(), g_device_name.c_str(), g_device_secret.c_str(), g_aliot_region.c_str())) { + sendIrisKitConnect(); + } + INFOLN("Aliyun IoT connected"); + return 0; +} + +void aliotKeepAlive() { + iot.loop(); +} \ No newline at end of file diff --git a/src/aliot_client.h b/src/aliot_client.h new file mode 100644 index 0000000..d75afc2 --- /dev/null +++ b/src/aliot_client.h @@ -0,0 +1,35 @@ +/** + * + * Copyright (c) 2020-2024 IRbaby-IRext + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "aliyun_iot_sdk.h" + +#ifndef IRIS_KIT_ALIOT_CLIENT_H +#define IRIS_KIT_ALIOT_CLIENT_H + +int connectToAliot(PubSubClient &mqtt_client); + +int disconnectFromAliot(PubSubClient &mqtt_client); + +#endif // IRIS_KIT_ALIOT_CLIENT_H \ No newline at end of file diff --git a/src/iot_hub.cpp b/src/iot_hub.cpp index c14985d..9d1c985 100644 --- a/src/iot_hub.cpp +++ b/src/iot_hub.cpp @@ -49,6 +49,8 @@ String g_mqtt_user_name = ""; String g_mqtt_password = ""; String g_upstream_topic = ""; String g_downstream_topic = ""; + +String g_aliot_region = "cn-shanghai"; int g_mqtt_port = 1883; int g_app_id = 0; diff --git a/src/ir_baby.cpp b/src/ir_baby.cpp index 95bb2d0..a31fc6a 100644 --- a/src/ir_baby.cpp +++ b/src/ir_baby.cpp @@ -104,7 +104,7 @@ String getDeviceID() { return device_id; } -int registerIrisKit(String credential_token, +int authIrisKit(String credential_token, String password, String& product_key, String& device_name, @@ -160,10 +160,9 @@ int registerIrisKit(String credential_token, int resultCode = http_response_doc["status"]["code"]; if (0 == resultCode) { INFOLN("response valid, try getting entity"); - device_secret = (const char*) http_response_doc["entity"]["deviceSecret"]; + device_secret = (const char*) http_response_doc["entity"]["deviceToken"]; app_id = (int) http_response_doc["entity"]["appId"]; - INFOF("HTTP response deserialized, PK = %s, DN = %s, DS = %s\n", - product_key.c_str(), device_name.c_str(), device_secret.c_str()); + INFOF("HTTP response deserialized, PK = %s, DN = %s, DS = %s\n", product_key.c_str(), device_name.c_str(), device_secret.c_str()); ret = 0; } else { INFOF("response invalid, code = %d\n", resultCode); diff --git a/src/ir_baby.h b/src/ir_baby.h index 987332b..005cfae 100644 --- a/src/ir_baby.h +++ b/src/ir_baby.h @@ -29,7 +29,7 @@ #define PASSWORD_MAX (64) // web http call URL list -#define GET_IRIS_KIT_ACCOUNT_SUFFIX "/irext-collect/credentials/auth_iris_kit_account" +#define GET_IRIS_KIT_ACCOUNT_SUFFIX "/irext-collect/credentials/auth_iris_kit" #define LOAD_ALIOT_ACCOUNT_SUFFIX "/irext-collect/aliot/load_account" #define DOWNLOAD_BIN_SUFFIX "/irext-collect/download" #define DOWNLOAD_PREFIX "http://irext-debug.oss-cn-hangzhou.aliyuncs.com/irda_" @@ -52,7 +52,7 @@ int getIRISKitVersion(char *buffer, int buffer_size); String getDeviceID(); -int registerIrisKit(String credential_token, +int authIrisKit(String credential_token, String password, String& product_key, String& device_name, diff --git a/src/iris_kit.cpp b/src/iris_kit.cpp index 187604c..cbfd96a 100644 --- a/src/iris_kit.cpp +++ b/src/iris_kit.cpp @@ -160,12 +160,12 @@ void setup() { do { if (WiFi.status() == WL_CONNECTED) { - if (0 == registerIrisKit(iris_credential_token, - iris_password, - g_product_key, - g_device_name, - g_device_secret, - g_app_id)) { + if (0 == authIrisKit(iris_credential_token, + iris_password, + g_product_key, + g_device_name, + g_device_secret, + g_app_id)) { break; } }