updated iris-kit mqtt to aliot

This commit is contained in:
strawmanbobi
2024-02-18 14:47:28 +08:00
parent 4d54cb273a
commit 95297411a9
9 changed files with 546 additions and 85 deletions

View File

@@ -22,7 +22,6 @@
*/
#include "defines.h"
#include "serials.h"
#include "iot_hub.h"
#include "iris_client.h"
@@ -54,14 +53,17 @@ static AliyunIoTSDK iot;
// public function definitions
int connectToAliyunIoT(PubSubClient &mqtt_client) {
int connectToAliot(PubSubClient &mqtt_client) {
String aliot_client_id = g_product_key + "." + g_device_name;
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();
int res = iot.begin(mqtt_client, aliot_client_id.c_str(), 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());
if (0 == res) {
INFOLN("Aliyun IoT connected");
} else {
ERRORLN("Failed to connect to Aliyun IoT");
}
INFOLN("Aliyun IoT connected");
return 0;
return res;
}
void aliotKeepAlive() {

View File

@@ -30,6 +30,6 @@
int connectToAliot(PubSubClient &mqtt_client);
int disconnectFromAliot(PubSubClient &mqtt_client);
void aliotKeepAlive();
#endif // IRIS_KIT_ALIOT_CLIENT_H

View File

@@ -30,9 +30,11 @@
#include "global.h"
#include "emq_client.h"
#include "aliot_client.h"
#include "iris_kit.h"
#include "iot_hub.h"
// external variable declarations
extern int g_runtime_env;
@@ -88,13 +90,19 @@ int connectToIrextIoT() {
return -1;
}
// g_mqtt_user_name act as clientId for aliot and as userName for EMQX
g_mqtt_user_name = getDeviceID();
INFOF("Try connecting to IRext IoT %s:%d, client_id = %s, user_name = %s, password.size = %d\n",
g_mqtt_server.c_str(), g_mqtt_port,
g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length());
INFOF("Try connecting to AliyunIoT, product_key = %s, device_name = %s, device_secret = %s\n",
g_product_key.c_str(), g_device_name.c_str(), g_device_token.c_str());
conn_ret = connectToAliot(mqtt_client);
conn_ret = connectToEMQXBroker(mqtt_client);
if (0 != conn_ret) {
INFOF("Try connecting to IRext IoT %s:%d, client_id = %s, user_name = %s, password.size = %d\n",
g_mqtt_server.c_str(), g_mqtt_port,
g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length());
conn_ret = connectToEMQXBroker(mqtt_client);
}
if (0 != conn_ret) {
ERRORLN("Something may went wrong with your credential, please retry connect to Wifi...");

View File

@@ -26,6 +26,7 @@
#include <Arduino.h>
#include <LittleFS.h>
#include <Ticker.h>
#include <WiFiUdp.h>
#include "defines.h"
#include "ir_emit.h"
@@ -54,6 +55,8 @@ extern String g_mqtt_password;
extern int g_app_id;
// public variable definitions
const unsigned long utcOffsetInMilliSeconds = 3600 * 1000;
int credential_init_retry = 0;
int g_runtime_env = RUNTIME_RELEASE;
iris_kit_settings_t iriskit_settings;
@@ -66,6 +69,7 @@ static Ticker disableIRTask; // disable IR receive
static Ticker disableRFTask; // disable RF receive
static Ticker saveDataTask; // save data
// private function declarations
static void wifiReset();