changed to Aliot shared instance
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
8
.idea/iris-kit.iml
generated
Normal file
8
.idea/iris-kit.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/iris-kit.iml" filepath="$PROJECT_DIR$/.idea/iris-kit.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
23
.vscode/settings.json
vendored
23
.vscode/settings.json
vendored
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"array": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"ranges": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"random": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"memory_resource": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"*.tcc": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"string.h": "c",
|
|
||||||
"arduino.h": "c"
|
|
||||||
},
|
|
||||||
"C_Cpp.errorSquiggles": "disabled"
|
|
||||||
}
|
|
||||||
@@ -46,7 +46,6 @@ extern String g_downstream_topic;
|
|||||||
extern int g_mqtt_port;
|
extern int g_mqtt_port;
|
||||||
|
|
||||||
extern String g_aliot_region;
|
extern String g_aliot_region;
|
||||||
extern String g_aliot_instance_id;
|
|
||||||
|
|
||||||
|
|
||||||
// private variable definitions
|
// private variable definitions
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ StaticJsonDocument<1024> send_msg_doc;
|
|||||||
StaticJsonDocument<1024> http_request_doc;
|
StaticJsonDocument<1024> http_request_doc;
|
||||||
StaticJsonDocument<1024> http_response_doc;
|
StaticJsonDocument<1024> http_response_doc;
|
||||||
StaticJsonDocument<2048> emit_code_doc;
|
StaticJsonDocument<2048> emit_code_doc;
|
||||||
|
StaticJsonDocument<1024> status_notify_doc;
|
||||||
|
|
||||||
WiFiManager wifi_manager;
|
WiFiManager wifi_manager;
|
||||||
WiFiClient wifi_client;
|
WiFiClient wifi_client;
|
||||||
|
|||||||
@@ -54,12 +54,12 @@ String g_upstream_topic = "";
|
|||||||
String g_downstream_topic = "";
|
String g_downstream_topic = "";
|
||||||
|
|
||||||
String g_aliot_region = "cn-shanghai";
|
String g_aliot_region = "cn-shanghai";
|
||||||
String g_aliot_instance_id = "iot-060a2sie";
|
|
||||||
int g_mqtt_port = 1883;
|
int g_mqtt_port = 1883;
|
||||||
|
|
||||||
int g_app_id = 0;
|
int g_app_id = 0;
|
||||||
mqtt_type_t g_mqtt_type = MQTT_TYPE_MAX;
|
mqtt_type_t g_mqtt_type = MQTT_TYPE_MAX;
|
||||||
boolean g_subscribed = false;
|
boolean g_subscribed = false;
|
||||||
|
unsigned long last_check_time = 0UL;
|
||||||
|
|
||||||
// private variable definitions
|
// private variable definitions
|
||||||
static bool downstream_topic_subscribed = false;
|
static bool downstream_topic_subscribed = false;
|
||||||
@@ -135,10 +135,14 @@ void irextIoTKeepAlive() {
|
|||||||
emqxClientKeepAlive();
|
emqxClientKeepAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_mqtt_client.connected()) {
|
unsigned long current_time = millis();
|
||||||
g_mqtt_client.unsubscribe(g_downstream_topic.c_str());
|
|
||||||
g_subscribed = false;
|
if (current_time - last_check_time > 10000) {
|
||||||
connectToIrextIoT();
|
if (!g_mqtt_client.connected()) {
|
||||||
|
g_mqtt_client.unsubscribe(g_downstream_topic.c_str());
|
||||||
|
g_subscribed = false;
|
||||||
|
connectToIrextIoT();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ extern StaticJsonDocument<1024> http_request_doc;
|
|||||||
extern StaticJsonDocument<1024> http_response_doc;
|
extern StaticJsonDocument<1024> http_response_doc;
|
||||||
extern StaticJsonDocument<1024> iris_msg_doc;
|
extern StaticJsonDocument<1024> iris_msg_doc;
|
||||||
extern StaticJsonDocument<1024> iris_ind_doc;
|
extern StaticJsonDocument<1024> iris_ind_doc;
|
||||||
extern StaticJsonDocument<1024> emit_code_doc;
|
extern StaticJsonDocument<2048> emit_code_doc;
|
||||||
|
extern StaticJsonDocument<1024> status_notify_doc;
|
||||||
|
|
||||||
extern String g_product_key;
|
extern String g_product_key;
|
||||||
extern String g_device_name;
|
extern String g_device_name;
|
||||||
@@ -279,6 +280,20 @@ static String buildHeartBeat() {
|
|||||||
return heartBeatMessage;
|
return heartBeatMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String buildTestResponse() {
|
||||||
|
String testResponseBeatMessage = "";
|
||||||
|
|
||||||
|
iris_msg_doc.clear();
|
||||||
|
iris_msg_doc["eventName"] = String(EVENT_NOTIFY_RESP);
|
||||||
|
iris_msg_doc["productKey"] = g_product_key;
|
||||||
|
iris_msg_doc["deviceName"] = g_device_name;
|
||||||
|
iris_msg_doc["appId"] = g_app_id;
|
||||||
|
iris_msg_doc["resp"] = String(NOTIFY_RESP_TEST);
|
||||||
|
serializeJson(iris_msg_doc, testResponseBeatMessage);
|
||||||
|
|
||||||
|
return testResponseBeatMessage;
|
||||||
|
}
|
||||||
|
|
||||||
static int handleConnected(String product_key, String device_name, String content) {
|
static int handleConnected(String product_key, String device_name, String content) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -304,6 +319,23 @@ 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) {
|
||||||
INFOF("received emit code : %s, %s, %s\n", product_key.c_str(), device_name.c_str(), content.c_str());
|
INFOF("received status change notification : %s, %s, %s\n", product_key.c_str(), device_name.c_str(), content.c_str());
|
||||||
|
status_notify_doc.clear();
|
||||||
|
if (DeserializationError::Ok == deserializeJson(status_notify_doc, content)) {
|
||||||
|
int key_id = status_notify_doc["keyId"];
|
||||||
|
String key_name = status_notify_doc["keyName"];
|
||||||
|
int status = status_notify_doc["status"];
|
||||||
|
INFOF("will enter status : %d for %s(%d)\n", status, key_name.c_str(), key_id);
|
||||||
|
if (RECIPIENT_STATUS_TEST == status) {
|
||||||
|
// send response for test notification
|
||||||
|
String testResponseData = buildTestResponse();
|
||||||
|
sendData(g_upstream_topic.c_str(), (uint8_t*) testResponseData.c_str(), testResponseData.length());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
INFOF("deserialize failed\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
// parse status
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,15 @@
|
|||||||
#define USER_NAME_MAX (64)
|
#define USER_NAME_MAX (64)
|
||||||
#define PASSWORD_MAX (64)
|
#define PASSWORD_MAX (64)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
RECIPIENT_STATUS_IDLE = 0,
|
||||||
|
RECIPIENT_STATUS_READY_TO_STUDY = 1,
|
||||||
|
RECIPIENT_STATUS_STUDIED = 2,
|
||||||
|
RECIPIENT_STATUS_UPLOADED = 3,
|
||||||
|
RECIPIENT_STATUS_TEST = 10,
|
||||||
|
RECIPIENT_STATUS_MAX = 63,
|
||||||
|
} kit_status_t;
|
||||||
|
|
||||||
// web http call URL list
|
// web http call URL list
|
||||||
#define GET_IRIS_KIT_ACCOUNT_SUFFIX "/irext-collect/credentials/auth_iris_kit"
|
#define GET_IRIS_KIT_ACCOUNT_SUFFIX "/irext-collect/credentials/auth_iris_kit"
|
||||||
#define LOAD_ALIOT_ACCOUNT_SUFFIX "/irext-collect/aliot/load_account"
|
#define LOAD_ALIOT_ACCOUNT_SUFFIX "/irext-collect/aliot/load_account"
|
||||||
@@ -41,6 +50,9 @@
|
|||||||
// IRIS communication
|
// IRIS communication
|
||||||
#define EVENT_NAME_CONNECT "__connect"
|
#define EVENT_NAME_CONNECT "__connect"
|
||||||
#define EVENT_HEART_BEAT_REQ "__hb_request"
|
#define EVENT_HEART_BEAT_REQ "__hb_request"
|
||||||
|
#define EVENT_NOTIFY_RESP "__notify_response"
|
||||||
|
|
||||||
|
#define NOTIFY_RESP_TEST "test_ok"
|
||||||
|
|
||||||
typedef int (*eventHandler)(String, String, String);
|
typedef int (*eventHandler)(String, String, String);
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user