implemented aliyun on PubSubClient(untested)
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "serials.h"
|
||||
#include "iot_hub.h"
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
|
||||
#include "aliyun_iot_sdk.h"
|
||||
|
||||
@@ -45,6 +45,7 @@ extern String g_downstream_topic;
|
||||
extern int g_mqtt_port;
|
||||
|
||||
extern String g_aliot_region;
|
||||
extern String g_aliot_instance_id;
|
||||
|
||||
|
||||
// private variable definitions
|
||||
@@ -55,7 +56,8 @@ 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())) {
|
||||
if (0 == iot.begin(mqtt_client, g_product_key.c_str(), g_device_name.c_str(), g_device_secret.c_str(),
|
||||
g_aliot_instance_id.c_str(), g_aliot_region.c_str())) {
|
||||
sendIrisKitConnect();
|
||||
}
|
||||
INFOLN("Aliyun IoT connected");
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "serials.h"
|
||||
#include "iot_hub.h"
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
|
||||
#include "emq_client.h"
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "serials.h"
|
||||
#include "iot_hub.h"
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
#include "global.h"
|
||||
|
||||
#include "emq_client.h"
|
||||
@@ -43,6 +43,7 @@ String g_mqtt_server = "";
|
||||
String g_product_key = "";
|
||||
String g_device_name = "";
|
||||
String g_device_secret = "";
|
||||
String g_device_token = "";
|
||||
|
||||
String g_mqtt_client_id = "";
|
||||
String g_mqtt_user_name = "";
|
||||
@@ -51,6 +52,7 @@ String g_upstream_topic = "";
|
||||
String g_downstream_topic = "";
|
||||
|
||||
String g_aliot_region = "cn-shanghai";
|
||||
String g_aliot_instance_id = "iot-060a2sie";
|
||||
int g_mqtt_port = 1883;
|
||||
|
||||
int g_app_id = 0;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "global.h"
|
||||
#include "serials.h"
|
||||
#include "user_settings.h"
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
#include "http_client.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef IRIS_KIT_IR_H
|
||||
#define IRIS_KIT_IR_H
|
||||
#ifndef IRIS_KIT_EMIT_H
|
||||
#define IRIS_KIT_EMIT_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <IRsend.h>
|
||||
@@ -54,4 +54,4 @@ bool saveIR(String file_name);
|
||||
|
||||
void initAC(String);
|
||||
|
||||
#endif // IRIS_KIT_IR_H
|
||||
#endif // IRIS_KIT_EMIT_H
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "http_client.h"
|
||||
#include "ir_emit.h"
|
||||
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
|
||||
|
||||
extern StaticJsonDocument<1024> http_request_doc;
|
||||
@@ -109,6 +109,7 @@ int authIrisKit(String credential_token,
|
||||
String& product_key,
|
||||
String& device_name,
|
||||
String& device_secret,
|
||||
String& device_token,
|
||||
int& app_id) {
|
||||
int ret = -1;
|
||||
int tsi = -1;
|
||||
@@ -160,9 +161,11 @@ int authIrisKit(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"]["deviceToken"];
|
||||
// for aliot connection, use deviceToken as deviceSecret
|
||||
device_token = (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, DT = %s\n",
|
||||
product_key.c_str(), device_name.c_str(), device_secret.c_str(), device_token.c_str());
|
||||
ret = 0;
|
||||
} else {
|
||||
INFOF("response invalid, code = %d\n", resultCode);
|
||||
@@ -57,6 +57,7 @@ int authIrisKit(String credential_token,
|
||||
String& product_key,
|
||||
String& device_name,
|
||||
String& device_secret,
|
||||
String& device_token,
|
||||
int& app_id);
|
||||
|
||||
void sendIrisKitConnect();
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "iot_hub.h"
|
||||
#include "http_client.h"
|
||||
#include "global.h"
|
||||
#include "ir_baby.h"
|
||||
#include "iris_client.h"
|
||||
#include "serials.h"
|
||||
#include "user_settings.h"
|
||||
#include "utils.h"
|
||||
@@ -48,6 +48,7 @@ extern String g_mqtt_server;
|
||||
extern String g_product_key;
|
||||
extern String g_device_name;
|
||||
extern String g_device_secret;
|
||||
extern String g_device_token;
|
||||
extern String g_mqtt_client_id;
|
||||
extern String g_mqtt_password;
|
||||
extern int g_app_id;
|
||||
@@ -165,6 +166,7 @@ void setup() {
|
||||
g_product_key,
|
||||
g_device_name,
|
||||
g_device_secret,
|
||||
g_device_token,
|
||||
g_app_id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user