tried to support aliot again(untested)
This commit is contained in:
@@ -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 <PubSubClient.h>
|
||||
#include <SHA256.h>
|
||||
|
||||
#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;
|
||||
@@ -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,
|
||||
67
src/aliot_client.cpp
Normal file
67
src/aliot_client.cpp
Normal file
@@ -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();
|
||||
}
|
||||
35
src/aliot_client.h
Normal file
35
src/aliot_client.h
Normal file
@@ -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 <Arduino.h>
|
||||
|
||||
#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
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -160,7 +160,7 @@ void setup() {
|
||||
|
||||
do {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
if (0 == registerIrisKit(iris_credential_token,
|
||||
if (0 == authIrisKit(iris_credential_token,
|
||||
iris_password,
|
||||
g_product_key,
|
||||
g_device_name,
|
||||
|
||||
Reference in New Issue
Block a user