MQTT parameters tweak

This commit is contained in:
strawmanbobi
2024-01-12 10:54:31 +08:00
parent f81a3f6b2e
commit 573a94e84f
4 changed files with 25 additions and 9 deletions

View File

@@ -87,7 +87,7 @@ void setup() {
INFOLN("██║██╔══██╗██║╚════██║"); INFOLN("██║██╔══██╗██║╚════██║");
INFOLN("██║██║ ██║██║███████║"); INFOLN("██║██║ ██║██║███████║");
INFOLN("╚═╝╚═╝ ╚═╝╚═╝╚══════╝"); INFOLN("╚═╝╚═╝ ╚═╝╚═╝╚══════╝");
INFOLN("== IRIS Kit [1.3.0] Powered by IRBaby =="); INFOLN("== IRIS Kit [1.3.0_r1] Powered by IRBaby ==");
// try loading saved iriskit settings // try loading saved iriskit settings
iriskit_settings.credential_token.clear(); iriskit_settings.credential_token.clear();

View File

@@ -61,6 +61,7 @@ char iris_password[PASSWORD_MAX] = { 0 };
static int processEvent(String event_name, String product_key, String device_name, String content); static int processEvent(String event_name, String product_key, String device_name, String content);
static String buildConnect(); static String buildConnect();
static String buildHeartBeat(); static String buildHeartBeat();
static int handleConnected(String product_key, String device_name, String content);
static int handleHartBeat(String product_key, String device_name, String content); static int handleHartBeat(String product_key, String device_name, String content);
static int handleEmit(String product_key, String device_name, String content); static int handleEmit(String product_key, String device_name, String content);
static int handleNotifyStatus(String product_key, String device_name, String content); static int handleNotifyStatus(String product_key, String device_name, String content);
@@ -69,16 +70,20 @@ static int hb_count = 0;
// private variable definitions // private variable definitions
event_handler_t event_handler_table[] = { event_handler_t event_handler_table[] = {
{
"__connected",
handleConnected,
},
{ {
"__hb_response", "__hb_response",
handleHartBeat, handleHartBeat,
}, },
{ {
"__emitCode", "__emit_code",
handleEmit, handleEmit,
}, },
{ {
"__notifyStatus", "__notify_status",
handleNotifyStatus, handleNotifyStatus,
} }
}; };
@@ -111,6 +116,7 @@ int authIrisKitAccount(String credential_token,
String fetch_credential_url; String fetch_credential_url;
String request_data = ""; String request_data = "";
String response_data = ""; String response_data = "";
String device_name_temp = "";
http_error_t http_ret = HTTP_ERROR_GENERIC; http_error_t http_ret = HTTP_ERROR_GENERIC;
@@ -136,7 +142,10 @@ int authIrisKitAccount(String credential_token,
return -1; return -1;
} }
product_key = credential_token.substring(0, tsi); product_key = credential_token.substring(0, tsi);
device_name = credential_token.substring(tsi + 1); device_name_temp = credential_token.substring(tsi + 1);
tsi = device_name_temp.indexOf(",");
device_name = device_name_temp.substring(0, tsi);
http_request_doc.clear(); http_request_doc.clear();
http_request_doc["deviceID"] = getDeviceID(); http_request_doc["deviceID"] = getDeviceID();
http_request_doc["credentialToken"] = credential_token; http_request_doc["credentialToken"] = credential_token;
@@ -202,7 +211,7 @@ void sendIrisKitConnect() {
} }
void sendIrisKitHeartBeat() { void sendIrisKitHeartBeat() {
INFOLN("send iris kit heart beat[%d]", hb_count++); INFOF("send iris kit heart beat[%d]\n", hb_count++);
String heartBeatMessage = buildHeartBeat(); String heartBeatMessage = buildHeartBeat();
sendData(g_upstream_topic.c_str(), (uint8_t*) heartBeatMessage.c_str(), heartBeatMessage.length()); sendData(g_upstream_topic.c_str(), (uint8_t*) heartBeatMessage.c_str(), heartBeatMessage.length());
} }
@@ -268,6 +277,10 @@ static String buildHeartBeat() {
return heartBeatMessage; return heartBeatMessage;
} }
static int handleConnected(String product_key, String device_name, String content) {
return 0;
}
static int handleHartBeat(String product_key, String device_name, String content) { static int handleHartBeat(String product_key, String device_name, String content) {
INFOF("received heartbeat : %s, %s\n", product_key.c_str(), device_name.c_str()); INFOF("received heartbeat : %s, %s\n", product_key.c_str(), device_name.c_str());
return 0; return 0;

View File

@@ -86,6 +86,7 @@ int connectToIrextIoT() {
g_mqtt_server.c_str(), g_mqtt_port, g_mqtt_server.c_str(), g_mqtt_port,
g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length()); g_mqtt_client_id.c_str(), g_mqtt_user_name.c_str(), g_mqtt_password.length());
mqtt_client.setBufferSize(1024);
mqtt_client.setServer(g_mqtt_server.c_str(), g_mqtt_port); mqtt_client.setServer(g_mqtt_server.c_str(), g_mqtt_port);
mqtt_client.setCallback(irisIrextIoTCallback); mqtt_client.setCallback(irisIrextIoTCallback);
conn_ret = connectToMQTTBroker(); conn_ret = connectToMQTTBroker();
@@ -119,8 +120,10 @@ void* getSession() {
} }
void checkIrextIoT() { void checkIrextIoT() {
if (mqtt_client.connected()) {
sendIrisKitHeartBeat(); sendIrisKitHeartBeat();
} }
}
static int connectToMQTTBroker() { static int connectToMQTTBroker() {
int retry_times = 0; int retry_times = 0;

View File

@@ -52,7 +52,7 @@ typedef unsigned char uint8_t;
/* ----------------- iot settings -----------------*/ /* ----------------- iot settings -----------------*/
#define MQTT_HOST_REL "iot.irext.net" #define MQTT_HOST_REL "iot.irext.net"
#define MQTT_CHECK_INTERVALS (30) #define MQTT_CHECK_INTERVALS (120)
#define MQTT_CONNECT_WAIT_TIME (20000) #define MQTT_CONNECT_WAIT_TIME (20000)
#define MQTT_RETRY_DELAY (5000) #define MQTT_RETRY_DELAY (5000)
#define MQTT_RETRY_MAX (5) #define MQTT_RETRY_MAX (5)