From 106fbd7cf73a83e73a25f006dde5681524cd45f6 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Sat, 3 Feb 2024 14:06:52 +0800 Subject: [PATCH] updated unix format ending --- src/IRISKit.cpp | 3 +++ src/IRISKit.h | 3 +++ src/IRISKitIoT.cpp | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/IRISKit.cpp b/src/IRISKit.cpp index 6fbd8aa..0121f73 100644 --- a/src/IRISKit.cpp +++ b/src/IRISKit.cpp @@ -54,6 +54,7 @@ extern int g_app_id; // public variable definitions int credential_init_retry = 0; +int g_runtime_env = RUNTIME_RELEASE; iris_kit_settings_t iriskit_settings; bool iris_kit_settings_loaded = false; @@ -199,6 +200,7 @@ void setup() { // prepare MQTT connection params if (NULL != strstr(iris_server_address, "iris.irext.net")) { g_mqtt_server = String(MQTT_HOST_REL); + g_runtime_env = RUNTIME_RELEASE; } else { String iris_server_address_dev = iriskit_settings.server_address; int delim = iris_server_address_dev.indexOf(':'); @@ -207,6 +209,7 @@ void setup() { } else { g_mqtt_server = iris_server_address_dev; } + g_runtime_env = RUNTIME_DEBUG; } g_mqtt_client_id = g_device_name; diff --git a/src/IRISKit.h b/src/IRISKit.h index 2a46469..2dca701 100644 --- a/src/IRISKit.h +++ b/src/IRISKit.h @@ -24,6 +24,9 @@ #ifndef IRIS_KIT_H #define IRIS_KIT_H +#define RUNTIME_RELEASE (0) +#define RUNTIME_DEBUG (1) + typedef struct { String server_address; String credential_token; diff --git a/src/IRISKitIoT.cpp b/src/IRISKitIoT.cpp index 91dfaff..14745ff 100644 --- a/src/IRISKitIoT.cpp +++ b/src/IRISKitIoT.cpp @@ -39,6 +39,12 @@ #define TOPIC_DOWNSTREAM_REL "/user/iris_kit_downstream" #define TOPIC_UPSTREAM_REL "/user/iris_kit_upstream" + +// external variable declarations +extern int g_runtime_env; + + +// public variable definitions String g_mqtt_server = ""; String g_product_key = ""; String g_device_name = ""; @@ -53,9 +59,13 @@ int g_mqtt_port = 1883; int g_app_id = 0; + +// private variable definitions static bool downstream_topic_subscribed = false; static ep_state_t endpoint_state = FSM_IDLE; + +// private function declarations static int connectToMQTTBroker(); static void irisIrextIoTCallback(char *topic, uint8_t *data, uint32_t length); @@ -64,14 +74,16 @@ static int iot_retry = 0; static PubSubClient mqtt_client(wifi_client); + +// public function definitions int connectToIrextIoT() { downstream_topic_subscribed = false; int conn_ret = -1; - if (g_product_key.equals(IRIS_KIT_PK_DEV)) { + if (g_runtime_env == RUNTIME_DEBUG) { g_upstream_topic = "/" + g_product_key + "/" + g_device_name + TOPIC_UPSTREAM_DEV; g_downstream_topic = "/" + g_product_key + "/" + g_device_name + TOPIC_DOWNSTREAM_DEV; - } else if (g_product_key.equals(IRIS_KIT_PK_REL)) { + } else if (g_runtime_env == RUNTIME_RELEASE) { g_upstream_topic = "/" + g_product_key + "/" + g_device_name + TOPIC_UPSTREAM_REL; g_downstream_topic = "/" + g_product_key + "/" + g_device_name + TOPIC_DOWNSTREAM_REL; } else { @@ -125,6 +137,8 @@ void checkIrextIoT() { } } + +// private function definitions static int connectToMQTTBroker() { int retry_times = 0;