code optimized
This commit is contained in:
@@ -46,7 +46,7 @@ extern int g_mqtt_port;
|
|||||||
|
|
||||||
// private variable definitions
|
// private variable definitions
|
||||||
static bool force_disconnected = false;
|
static bool force_disconnected = false;
|
||||||
static PubSubClient* emqx_client = NULL;
|
static PubSubClient* emqx_client = nullptr;
|
||||||
|
|
||||||
// private function declarations
|
// private function declarations
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ static PubSubClient* emqx_client = NULL;
|
|||||||
int connectToEMQXBroker(PubSubClient &mqtt_client) {
|
int connectToEMQXBroker(PubSubClient &mqtt_client) {
|
||||||
int retry_times = 0;
|
int retry_times = 0;
|
||||||
|
|
||||||
if (NULL == emqx_client) {
|
if (nullptr == emqx_client) {
|
||||||
emqx_client = &mqtt_client;
|
emqx_client = &mqtt_client;
|
||||||
}
|
}
|
||||||
emqx_client->setServer(g_mqtt_server.c_str(), g_mqtt_port);
|
emqx_client->setServer(g_mqtt_server.c_str(), g_mqtt_port);
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ void checkIot() {
|
|||||||
|
|
||||||
void iotCallback(char *topic, uint8_t *data, uint32_t length) {
|
void iotCallback(char *topic, uint8_t *data, uint32_t length) {
|
||||||
INFOF("Downstream message received, topic = %s, length = %d\n", topic, length);
|
INFOF("Downstream message received, topic = %s, length = %d\n", topic, length);
|
||||||
if (NULL != g_downstream_topic.c_str() && 0 == strcmp(topic, g_downstream_topic.c_str())) {
|
if (nullptr != g_downstream_topic.c_str() && 0 == strcmp(topic, g_downstream_topic.c_str())) {
|
||||||
handleIrisKitMessage((const char*) data, length);
|
handleIrisKitMessage((const char*) data, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ event_handler_t event_handler_table[] = {
|
|||||||
|
|
||||||
// public function definitions
|
// public function definitions
|
||||||
int getIRISKitVersion(char *buffer, int buffer_size) {
|
int getIRISKitVersion(char *buffer, int buffer_size) {
|
||||||
if (NULL == buffer) {
|
if (nullptr == buffer) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(buffer, 0, buffer_size);
|
memset(buffer, 0, buffer_size);
|
||||||
@@ -123,7 +123,7 @@ int authIrisKit(String credential_token,
|
|||||||
|
|
||||||
http_error_t http_ret = HTTP_ERROR_GENERIC;
|
http_error_t http_ret = HTTP_ERROR_GENERIC;
|
||||||
|
|
||||||
if (NULL != strstr(iris_server_address, "http://")) {
|
if (nullptr != strstr(iris_server_address, "http://")) {
|
||||||
protocol_prefix = true;
|
protocol_prefix = true;
|
||||||
}
|
}
|
||||||
if (protocol_prefix) {
|
if (protocol_prefix) {
|
||||||
@@ -185,7 +185,7 @@ bool downloadBin(int remote_id) {
|
|||||||
String download_bin_url;
|
String download_bin_url;
|
||||||
http_error_t http_ret = HTTP_ERROR_GENERIC;
|
http_error_t http_ret = HTTP_ERROR_GENERIC;
|
||||||
|
|
||||||
if (NULL != strstr(iris_server_address, "http://")) {
|
if (nullptr != strstr(iris_server_address, "http://")) {
|
||||||
protocol_prefix = true;
|
protocol_prefix = true;
|
||||||
}
|
}
|
||||||
if (protocol_prefix) {
|
if (protocol_prefix) {
|
||||||
@@ -223,7 +223,7 @@ void sendIrisKitHeartBeat() {
|
|||||||
void handleIrisKitMessage(const char* data, int length) {
|
void handleIrisKitMessage(const char* data, int length) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char* payload = (char*) malloc(length + 1);
|
char* payload = (char*) malloc(length + 1);
|
||||||
if (NULL != payload) {
|
if (nullptr != payload) {
|
||||||
strncpy(payload, data, length);
|
strncpy(payload, data, length);
|
||||||
payload[length] = '\0';
|
payload[length] = '\0';
|
||||||
INFOF("--> %s\n", payload);
|
INFOF("--> %s\n", payload);
|
||||||
@@ -238,7 +238,7 @@ void handleIrisKitMessage(const char* data, int length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != payload) {
|
if (nullptr != payload) {
|
||||||
free(payload);
|
free(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,11 +113,11 @@ void setup() {
|
|||||||
INFOF("Password is empty ? %s\n", iris_kit_settings.password.isEmpty() ? "yes" : "no");
|
INFOF("Password is empty ? %s\n", iris_kit_settings.password.isEmpty() ? "yes" : "no");
|
||||||
}
|
}
|
||||||
if (!iris_kit_settings.credential_token.isEmpty() &&
|
if (!iris_kit_settings.credential_token.isEmpty() &&
|
||||||
!iris_kit_settings.credential_token.equalsIgnoreCase("NULL") &&
|
!iris_kit_settings.credential_token.equalsIgnoreCase("nullptr") &&
|
||||||
!iris_kit_settings.server_address.isEmpty() &&
|
!iris_kit_settings.server_address.isEmpty() &&
|
||||||
!iris_kit_settings.server_address.equalsIgnoreCase("NULL") &&
|
!iris_kit_settings.server_address.equalsIgnoreCase("nullptr") &&
|
||||||
!iris_kit_settings.password.isEmpty() &&
|
!iris_kit_settings.password.isEmpty() &&
|
||||||
!iris_kit_settings.password.equalsIgnoreCase("NULL")) {
|
!iris_kit_settings.password.equalsIgnoreCase("nullptr")) {
|
||||||
iris_kit_settings_loaded = true;
|
iris_kit_settings_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ void setup() {
|
|||||||
loadIRPin(send_pin, recv_pin);
|
loadIRPin(send_pin, recv_pin);
|
||||||
|
|
||||||
// prepare MQTT connection params
|
// prepare MQTT connection params
|
||||||
if (NULL != strstr(iris_server_address, "iris.irext.net")) {
|
if (nullptr != strstr(iris_server_address, "iris.irext.net")) {
|
||||||
g_mqtt_server = String(MQTT_HOST_REL);
|
g_mqtt_server = String(MQTT_HOST_REL);
|
||||||
g_runtime_env = RUNTIME_RELEASE;
|
g_runtime_env = RUNTIME_RELEASE;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -32,31 +32,31 @@
|
|||||||
MD5Builder md5_builder;
|
MD5Builder md5_builder;
|
||||||
|
|
||||||
int split_string(const String source, char* parts[], const char* delimiter) {
|
int split_string(const String source, char* parts[], const char* delimiter) {
|
||||||
char* pch = NULL;
|
char* pch = nullptr;
|
||||||
char* copy = NULL;
|
char* copy = nullptr;
|
||||||
char* tmp = NULL;
|
char* tmp = nullptr;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
copy = strdup(source.c_str());
|
copy = strdup(source.c_str());
|
||||||
if (NULL == copy) {
|
if (nullptr == copy) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pch = strtok(copy, delimiter);
|
pch = strtok(copy, delimiter);
|
||||||
|
|
||||||
tmp = strdup(pch);
|
tmp = strdup(pch);
|
||||||
if (NULL == tmp) {
|
if (nullptr == tmp) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
parts[i++] = tmp;
|
parts[i++] = tmp;
|
||||||
|
|
||||||
while (pch) {
|
while (pch) {
|
||||||
pch = strtok(NULL, delimiter);
|
pch = strtok(nullptr, delimiter);
|
||||||
if (NULL == pch) break;
|
if (nullptr == pch) break;
|
||||||
|
|
||||||
tmp = strdup(pch);
|
tmp = strdup(pch);
|
||||||
if (NULL == tmp) {
|
if (nullptr == tmp) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user