mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
add prefix
This commit is contained in:
2
Cmd.ino
2
Cmd.ino
@@ -451,7 +451,7 @@ void mqttOrderSend() {
|
|||||||
String id = sCmd.next();
|
String id = sCmd.next();
|
||||||
String order = sCmd.next();
|
String order = sCmd.next();
|
||||||
|
|
||||||
String all_line = prefix + "/" + id + "/order";
|
String all_line = jsonRead(configSetup, "mqttPrefix") + "/" + id + "/order";
|
||||||
//Serial.print(all_line);
|
//Serial.print(all_line);
|
||||||
//Serial.print("->");
|
//Serial.print("->");
|
||||||
//Serial.println(order);
|
//Serial.println(order);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"timezone": 3,
|
"timezone": 3,
|
||||||
"mqttServer": "m12.cloudmqtt.com",
|
"mqttServer": "m12.cloudmqtt.com",
|
||||||
"mqttPort": 14053,
|
"mqttPort": 14053,
|
||||||
|
"mqttPrefix": "/IoTmanager",
|
||||||
"mqttUser": "lbscvzuj",
|
"mqttUser": "lbscvzuj",
|
||||||
"mqttPass": "bLxlveOgaF8F",
|
"mqttPass": "bLxlveOgaF8F",
|
||||||
"scenario": "1",
|
"scenario": "1",
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "link",
|
"type": "link",
|
||||||
"title": "Инструкция",
|
"title": "Подробная инструкция",
|
||||||
"action": "https://github.com/DmitryBorisenko33/esp8266_iot-manager_modules_firmware/wiki/Instruction",
|
"action": "https://github.com/DmitryBorisenko33/esp32-esp8266_iot-manager_modules_firmware/wiki/Instruction",
|
||||||
"class": "btn btn-block btn-primary"
|
"class": "btn btn-block btn-primary"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,12 +31,22 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"title": "User name:"
|
"title": "Prefix:"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"title": "",
|
"title": "",
|
||||||
"name":"3",
|
"name":"3",
|
||||||
|
"state": "{{mqttPrefix}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "h4",
|
||||||
|
"title": "User name:"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"title": "",
|
||||||
|
"name":"4",
|
||||||
"state": "{{mqttUser}}"
|
"state": "{{mqttUser}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -46,7 +56,7 @@
|
|||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"title": "",
|
"title": "",
|
||||||
"name":"4",
|
"name":"5",
|
||||||
"state": "{{mqttPass}}"
|
"state": "{{mqttPass}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -58,7 +68,7 @@
|
|||||||
{
|
{
|
||||||
"type": "button",
|
"type": "button",
|
||||||
"title":"Сохранить",
|
"title":"Сохранить",
|
||||||
"action": "mqttSave?mqttServer=[[1]]&mqttPort=[[2]]&mqttUser=[[3]]&mqttPass=[[4]]",
|
"action": "mqttSave?mqttServer=[[1]]&mqttPort=[[2]]&mqttPrefix=[[3]]&mqttUser=[[4]]&mqttPass=[[5]]",
|
||||||
"response":"[[my-block]]",
|
"response":"[[my-block]]",
|
||||||
"class": "btn btn-block btn-success",
|
"class": "btn btn-block btn-success",
|
||||||
"style": "width:100%;display:inline"
|
"style": "width:100%;display:inline"
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void setup() {
|
|||||||
|
|
||||||
jsonWrite(configSetup, "firmware_version", firmware_version);
|
jsonWrite(configSetup, "firmware_version", firmware_version);
|
||||||
|
|
||||||
prex = prefix + "/" + chipID;
|
prex = jsonRead(configSetup, "mqttPrefix") + "/" + chipID;
|
||||||
Serial.println(chipID);
|
Serial.println(chipID);
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
CMD_init();
|
CMD_init();
|
||||||
|
|||||||
96
main.ino
96
main.ino
@@ -229,7 +229,7 @@ String readFileString(String fileName, String found)
|
|||||||
|
|
||||||
void sendCONFIG(String topik, String widgetConfig, String key, String date) {
|
void sendCONFIG(String topik, String widgetConfig, String key, String date) {
|
||||||
yield();
|
yield();
|
||||||
topik = prefix + "/" + chipID + "/" + topik + "/status";
|
topik = jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/" + topik + "/status";
|
||||||
String outer = "{\"widgetConfig\":";
|
String outer = "{\"widgetConfig\":";
|
||||||
String inner = "{\"";
|
String inner = "{\"";
|
||||||
inner = inner + key;
|
inner = inner + key;
|
||||||
@@ -277,52 +277,7 @@ void getMemoryLoad(String text) {
|
|||||||
}
|
}
|
||||||
//esp32 full memory = 362868 k bytes
|
//esp32 full memory = 362868 k bytes
|
||||||
//esp8266 full memory = 53312 k bytes
|
//esp8266 full memory = 53312 k bytes
|
||||||
/*
|
|
||||||
String getResetReason(uint8_t core) {
|
|
||||||
int reason = rtc_get_reset_reason(core);
|
|
||||||
switch (reason) {
|
|
||||||
case 1 : return "Power on"; break; //Vbat power on reset
|
|
||||||
case 3 : return "Software reset digital core"; break; //Software reset digital core
|
|
||||||
case 4 : return "Legacy watch dog reset digital core"; break; //Legacy watch dog reset digital core
|
|
||||||
case 5 : return "Deep Sleep reset digital core"; break; //Deep Sleep reset digital core
|
|
||||||
case 6 : return "Reset by SLC module, reset digital core"; break; //Reset by SLC module, reset digital core
|
|
||||||
case 7 : return "Timer Group0 Watch dog reset digital core"; break; //Timer Group0 Watch dog reset digital core
|
|
||||||
case 8 : return "Timer Group1 Watch dog reset digital core"; break; //Timer Group1 Watch dog reset digital core
|
|
||||||
case 9 : return "RTC Watch dog Reset digital core"; break; //
|
|
||||||
case 10 : return "Instrusion tested to reset CPU"; break;
|
|
||||||
case 11 : return "Time Group reset CPU"; break;
|
|
||||||
case 12 : return "Software reset CPU"; break;
|
|
||||||
case 13 : return "RTC Watch dog Reset CPU"; break;
|
|
||||||
case 14 : return "for APP CPU, reseted by PRO CPU"; break;
|
|
||||||
case 15 : return "Reset when the vdd voltage is not stable"; break;
|
|
||||||
case 16 : return "RTC Watch dog reset digital core and rtc module"; break;
|
|
||||||
default : return "NO_MEAN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String EspClass::getResetReason(void) {
|
|
||||||
char buff[32];
|
|
||||||
if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on
|
|
||||||
strcpy_P(buff, PSTR("Power on"));
|
|
||||||
} else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset
|
|
||||||
strcpy_P(buff, PSTR("Hardware Watchdog"));
|
|
||||||
} else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status won’t change
|
|
||||||
strcpy_P(buff, PSTR("Exception"));
|
|
||||||
} else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status won’t change
|
|
||||||
strcpy_P(buff, PSTR("Software Watchdog"));
|
|
||||||
} else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change
|
|
||||||
strcpy_P(buff, PSTR("Software/System restart"));
|
|
||||||
} else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep
|
|
||||||
strcpy_P(buff, PSTR("Deep-Sleep Wake"));
|
|
||||||
} else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset
|
|
||||||
strcpy_P(buff, PSTR("External System"));
|
|
||||||
} else {
|
|
||||||
strcpy_P(buff, PSTR("Unknown"));
|
|
||||||
}
|
|
||||||
return String(buff);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//===================================================================
|
//===================================================================
|
||||||
/*
|
/*
|
||||||
void web_print (String text) {
|
void web_print (String text) {
|
||||||
@@ -386,3 +341,52 @@ String EspClass::getResetReason(void) {
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
//===================================================================
|
//===================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
String getResetReason(uint8_t core) {
|
||||||
|
int reason = rtc_get_reset_reason(core);
|
||||||
|
switch (reason) {
|
||||||
|
case 1 : return "Power on"; break; //Vbat power on reset
|
||||||
|
case 3 : return "Software reset digital core"; break; //Software reset digital core
|
||||||
|
case 4 : return "Legacy watch dog reset digital core"; break; //Legacy watch dog reset digital core
|
||||||
|
case 5 : return "Deep Sleep reset digital core"; break; //Deep Sleep reset digital core
|
||||||
|
case 6 : return "Reset by SLC module, reset digital core"; break; //Reset by SLC module, reset digital core
|
||||||
|
case 7 : return "Timer Group0 Watch dog reset digital core"; break; //Timer Group0 Watch dog reset digital core
|
||||||
|
case 8 : return "Timer Group1 Watch dog reset digital core"; break; //Timer Group1 Watch dog reset digital core
|
||||||
|
case 9 : return "RTC Watch dog Reset digital core"; break; //
|
||||||
|
case 10 : return "Instrusion tested to reset CPU"; break;
|
||||||
|
case 11 : return "Time Group reset CPU"; break;
|
||||||
|
case 12 : return "Software reset CPU"; break;
|
||||||
|
case 13 : return "RTC Watch dog Reset CPU"; break;
|
||||||
|
case 14 : return "for APP CPU, reseted by PRO CPU"; break;
|
||||||
|
case 15 : return "Reset when the vdd voltage is not stable"; break;
|
||||||
|
case 16 : return "RTC Watch dog reset digital core and rtc module"; break;
|
||||||
|
default : return "NO_MEAN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String EspClass::getResetReason(void) {
|
||||||
|
char buff[32];
|
||||||
|
if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on
|
||||||
|
strcpy_P(buff, PSTR("Power on"));
|
||||||
|
} else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset
|
||||||
|
strcpy_P(buff, PSTR("Hardware Watchdog"));
|
||||||
|
} else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status won’t change
|
||||||
|
strcpy_P(buff, PSTR("Exception"));
|
||||||
|
} else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status won’t change
|
||||||
|
strcpy_P(buff, PSTR("Software Watchdog"));
|
||||||
|
} else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change
|
||||||
|
strcpy_P(buff, PSTR("Software/System restart"));
|
||||||
|
} else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep
|
||||||
|
strcpy_P(buff, PSTR("Deep-Sleep Wake"));
|
||||||
|
} else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset
|
||||||
|
strcpy_P(buff, PSTR("External System"));
|
||||||
|
} else {
|
||||||
|
strcpy_P(buff, PSTR("Unknown"));
|
||||||
|
}
|
||||||
|
return String(buff);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
25
mqtt.ino
25
mqtt.ino
@@ -10,6 +10,9 @@ void MQTT_init() {
|
|||||||
int port = (request->getParam("mqttPort")->value()).toInt();
|
int port = (request->getParam("mqttPort")->value()).toInt();
|
||||||
jsonWrite(configSetup, "mqttPort", port);
|
jsonWrite(configSetup, "mqttPort", port);
|
||||||
}
|
}
|
||||||
|
if (request->hasArg("mqttPrefix")) {
|
||||||
|
jsonWrite(configSetup, "mqttPrefix", request->getParam("mqttPrefix")->value());
|
||||||
|
}
|
||||||
if (request->hasArg("mqttUser")) {
|
if (request->hasArg("mqttUser")) {
|
||||||
jsonWrite(configSetup, "mqttUser", request->getParam("mqttUser")->value());
|
jsonWrite(configSetup, "mqttUser", request->getParam("mqttUser")->value());
|
||||||
}
|
}
|
||||||
@@ -20,7 +23,7 @@ void MQTT_init() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
|
||||||
client.disconnect();
|
//client.disconnect();
|
||||||
MQTT_Connecting();
|
MQTT_Connecting();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -95,11 +98,11 @@ boolean MQTT_Connecting() {
|
|||||||
Serial.println("[V] MQTT connected");
|
Serial.println("[V] MQTT connected");
|
||||||
//web_print("MQTT connected");
|
//web_print("MQTT connected");
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
client.subscribe(prefix.c_str()); // Для приема получения HELLOW и подтверждения связи
|
client.subscribe(jsonRead(configSetup, "mqttPrefix").c_str()); // Для приема получения HELLOW и подтверждения связи
|
||||||
client.subscribe((prefix + "/" + chipID + "/+/control").c_str()); // Подписываемся на топики control
|
client.subscribe((jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/+/control").c_str()); // Подписываемся на топики control
|
||||||
client.subscribe((prefix + "/" + chipID + "/order").c_str()); // Подписываемся на топики order
|
client.subscribe((jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/order").c_str()); // Подписываемся на топики order
|
||||||
//client.subscribe((prefix + "/" + chipID + "/test").c_str()); //Для приема получения work и подтверждения связи (для приложения mqtt IOT MQTT Panel)
|
//client.subscribe((jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/test").c_str()); //Для приема получения work и подтверждения связи (для приложения mqtt IOT MQTT Panel)
|
||||||
client.subscribe((prefix + "/ids").c_str()); // Подписываемся на топики ids
|
client.subscribe((jsonRead(configSetup, "mqttPrefix") + "/ids").c_str()); // Подписываемся на топики ids
|
||||||
//sendMQTT("test", "work");
|
//sendMQTT("test", "work");
|
||||||
Serial.println("[V] Callback set, subscribe done");
|
Serial.println("[V] Callback set, subscribe done");
|
||||||
//web_print("Callback set, subscribe done");
|
//web_print("Callback set, subscribe done");
|
||||||
@@ -164,7 +167,7 @@ void outcoming_date() {
|
|||||||
}
|
}
|
||||||
//======================================CONFIG==================================================
|
//======================================CONFIG==================================================
|
||||||
boolean sendMQTT(String end_of_topik, String data) {
|
boolean sendMQTT(String end_of_topik, String data) {
|
||||||
String topik = prefix + "/" + chipID + "/" + end_of_topik;
|
String topik = jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/" + end_of_topik;
|
||||||
boolean send_status = client.beginPublish(topik.c_str(), data.length(), false);
|
boolean send_status = client.beginPublish(topik.c_str(), data.length(), false);
|
||||||
client.print(data);
|
client.print(data);
|
||||||
client.endPublish();
|
client.endPublish();
|
||||||
@@ -172,14 +175,14 @@ boolean sendMQTT(String end_of_topik, String data) {
|
|||||||
}
|
}
|
||||||
//======================================STATUS==================================================
|
//======================================STATUS==================================================
|
||||||
void sendSTATUS(String topik, String state) {
|
void sendSTATUS(String topik, String state) {
|
||||||
topik = prefix + "/" + chipID + "/" + topik + "/" + "status";
|
topik = jsonRead(configSetup, "mqttPrefix") + "/" + chipID + "/" + topik + "/" + "status";
|
||||||
String json_ = "{}";
|
String json_ = "{}";
|
||||||
jsonWrite(json_, "status", state);
|
jsonWrite(json_, "status", state);
|
||||||
int send_status = client.publish (topik.c_str(), json_.c_str(), false);
|
int send_status = client.publish (topik.c_str(), json_.c_str(), false);
|
||||||
}
|
}
|
||||||
//======================================CONTROL==================================================
|
//======================================CONTROL==================================================
|
||||||
void sendCONTROL(String id, String topik, String state) {
|
void sendCONTROL(String id, String topik, String state) {
|
||||||
String all_line = prefix + "/" + id + "/" + topik + "/control";
|
String all_line = jsonRead(configSetup, "mqttPrefix") + "/" + id + "/" + topik + "/control";
|
||||||
int send_status = client.publish (all_line.c_str(), state.c_str(), false);
|
int send_status = client.publish (all_line.c_str(), state.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +289,7 @@ String stateMQTT() {
|
|||||||
String line_ = selectToMarker (all_text, "\n");
|
String line_ = selectToMarker (all_text, "\n");
|
||||||
String id = selectFromMarkerToMarker(line_, " ", 4);
|
String id = selectFromMarkerToMarker(line_, " ", 4);
|
||||||
if (id != "not found") {
|
if (id != "not found") {
|
||||||
client.subscribe((prefix + "/" + id + "/+/status").c_str(), 0);
|
client.subscribe((jsonRead(configSetup, "mqttPrefix") + "/" + id + "/+/status").c_str(), 0);
|
||||||
Serial.println("subscribed to device, id: " + id);
|
Serial.println("subscribed to device, id: " + id);
|
||||||
}
|
}
|
||||||
all_text = deleteBeforeDelimiter(all_text, "\n");
|
all_text = deleteBeforeDelimiter(all_text, "\n");
|
||||||
@@ -306,7 +309,7 @@ String stateMQTT() {
|
|||||||
String id = selectFromMarkerToMarker(line_, " ", 4);
|
String id = selectFromMarkerToMarker(line_, " ", 4);
|
||||||
if (id != "not found") {
|
if (id != "not found") {
|
||||||
//Serial.println();
|
//Serial.println();
|
||||||
Serial.println(client.publish ((prefix + "/" + id).c_str(), "CHECK", true));
|
Serial.println(client.publish ((jsonRead(configSetup, "mqttPrefix") + "/" + id).c_str(), "CHECK", true));
|
||||||
|
|
||||||
}
|
}
|
||||||
all_text = deleteBeforeDelimiter(all_text, "\n");
|
all_text = deleteBeforeDelimiter(all_text, "\n");
|
||||||
|
|||||||
BIN
pictures/esp32_1.png
Normal file
BIN
pictures/esp32_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
BIN
pictures/esp32_2.png
Normal file
BIN
pictures/esp32_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 140 KiB |
BIN
pictures/esp8266_1.png
Normal file
BIN
pictures/esp8266_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
BIN
pictures/esp8266_2.png
Normal file
BIN
pictures/esp8266_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
Reference in New Issue
Block a user