diff --git a/src/config.cpp b/src/config.cpp index 7d700ab..9fc07bd 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -23,8 +23,6 @@ extern struct NetworkConfigStruct networkCfg; extern struct VpnConfigStruct vpnCfg; extern struct MqttConfigStruct mqttCfg; -String tag = "NVS"; - void getNvsStats(int *total, int *used) { nvs_stats_t nvsStats; @@ -262,7 +260,7 @@ void saveSystemConfig(const SystemConfigStruct &config) { preferences.begin(systemConfigKey, false); - preferences.putBool(keepWebKey, config.keepWeb); + //preferences.putBool(keepWebKey, config.keepWeb); preferences.putBool(disableWebKey, config.disableWeb); preferences.putBool(webAuthKey, config.webAuth); preferences.putString(webUserKey, config.webUser); @@ -292,7 +290,7 @@ void loadSystemConfig(SystemConfigStruct &config) { preferences.begin(systemConfigKey, true); - config.keepWeb = preferences.getBool(keepWebKey, true); + //config.keepWeb = preferences.getBool(keepWebKey, true); config.disableWeb = preferences.getBool(disableWebKey, false); config.webAuth = preferences.getBool(webAuthKey, false); strlcpy(config.webUser, preferences.getString(webUserKey, "").c_str(), sizeof(config.webUser)); @@ -348,7 +346,7 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne { case API_PAGE_GENERAL: { - if (serverWeb.hasArg(coordMode)) + /*if (serverWeb.hasArg(coordMode)) { const uint8_t mode = serverWeb.arg(coordMode).toInt(); if (mode <= 2 && mode >= 0) @@ -360,7 +358,7 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne } } - configSys.keepWeb = serverWeb.hasArg(keepWebKey) == true; + configSys.keepWeb = serverWeb.hasArg(keepWebKey) == true;*/ configSys.disableLedPwr = serverWeb.hasArg(disableLedPwrKey) == true; @@ -507,13 +505,22 @@ void updateConfiguration(WebServer &serverWeb, SystemConfigStruct &configSys, Ne break; case API_PAGE_ZIGBEE: { + if (serverWeb.hasArg(coordMode)) + { + const uint8_t mode = serverWeb.arg(coordMode).toInt(); + if (mode <= 2 && mode >= 0) + { + configSys.workMode = static_cast(mode); + } + } + const char *baud = "baud"; if (serverWeb.hasArg(baud)) { configSys.serialSpeed = serverWeb.arg(baud).toInt(); } - if (serverWeb.hasArg(baud)) + if (serverWeb.hasArg(portKey)) { configSys.socketPort = serverWeb.arg(portKey).toInt(); } @@ -754,7 +761,7 @@ void serializeMqttConfigToJson(const MqttConfigStruct &config, JsonObject obj) // Serialization SystemConfigStruct into JSON void serializeSystemConfigToJson(const SystemConfigStruct &config, JsonObject obj) { - obj[keepWebKey] = config.keepWeb; + //obj[keepWebKey] = config.keepWeb; obj[disableWebKey] = config.disableWeb; obj[webAuthKey] = config.webAuth; obj[webUserKey] = config.webUser; @@ -784,7 +791,7 @@ void serializeSysVarsToJson(const SysVarsStruct &vars, JsonObject obj) obj[hwBtnIsKey] = vars.hwBtnIs; obj[hwLedUsbIsKey] = vars.hwLedUsbIs; obj[hwLedPwrIsKey] = vars.hwLedPwrIs; - obj[hwUartSelIsKey] = vars.hwUartSelIs; + //obj[hwUartSelIsKey] = vars.hwUartSelIs; obj[hwZigbeeIsKey] = vars.hwZigbeeIs; obj[connectedClientsKey] = vars.connectedClients; @@ -812,7 +819,6 @@ void serializeSysVarsToJson(const SysVarsStruct &vars, JsonObject obj) bool loadFileConfigHW() { - String tag = "HW"; const char *board = "board"; const char *addr = "addr"; const char *pwrPin = "pwrPin"; @@ -1091,7 +1097,7 @@ bool loadFileConfigGeneral() systemCfg.disableLedPwr = (uint8_t)doc[disableLedPwrKey]; systemCfg.disableLedUSB = (uint8_t)doc[disableLedUSBKey]; vars.disableLeds = (uint8_t)doc[disableLedsKey]; - systemCfg.keepWeb = (uint8_t)doc[keepWebKey]; + //systemCfg.keepWeb = (uint8_t)doc[keepWebKey]; strlcpy(systemCfg.timeZone, doc[timeZoneKey] | NTP_TIME_ZONE, sizeof(systemCfg.timeZone)); configFile.close(); diff --git a/src/config.h b/src/config.h index a7a8cb5..64ae536 100644 --- a/src/config.h +++ b/src/config.h @@ -66,7 +66,7 @@ struct SysVarsStruct bool hwBtnIs = false; bool hwLedUsbIs = false; bool hwLedPwrIs = false; - bool hwUartSelIs = false; + //bool hwUartSelIs = false; bool hwZigbeeIs = false; bool connectedSocket[MAX_SOCKET_CLIENTS]; //[10] @@ -175,7 +175,7 @@ void loadMqttConfig(MqttConfigStruct &config); struct SystemConfigStruct { - bool keepWeb; // when usb mode active + //bool keepWeb; // when usb mode active bool disableWeb; // when socket connected bool webAuth; @@ -297,23 +297,33 @@ uint8_t temprature_sens_read(); // Conditional logging macros #if CURRENT_LOG_LEVEL >= LOG_LEVEL_WARN -#define LOGW(format, ...) Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_RED "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__) +#define LOGW(format, ...) \ + if (systemCfg.workMode == WORK_MODE_NETWORK) { \ + Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_RED "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \ + } #else #define LOGW(format, ...) // Nothing #endif #if CURRENT_LOG_LEVEL >= LOG_LEVEL_INFO -#define LOGI(format, ...) Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_GREEN "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__) +#define LOGI(format, ...) \ + if (systemCfg.workMode == WORK_MODE_NETWORK) { \ + Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_GREEN "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \ + } #else #define LOGI(format, ...) // Nothing #endif #if CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG -#define LOGD(format, ...) Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_YELLOW "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__) +#define LOGD(format, ...) \ + if (systemCfg.workMode == WORK_MODE_NETWORK) { \ + Serial.printf(ANSI_COLOR_PURPLE "%d " ANSI_COLOR_RESET ANSI_COLOR_YELLOW "[%s] " ANSI_COLOR_RESET format "\n", millis(), __func__, ##__VA_ARGS__); \ + } #else #define LOGD(format, ...) // Nothing #endif + /* ----- Define functions | END -----*/ enum LEDMode diff --git a/src/const/hw.cpp b/src/const/hw.cpp index f47991f..222c16f 100644 --- a/src/const/hw.cpp +++ b/src/const/hw.cpp @@ -43,4 +43,5 @@ BrdConfigStruct brdConfigs[] = { {"TubesZB-poe", .ethConfigIndex = 0, .zbConfigIndex = 5, .mistConfigIndex = 0}, {"TubesZB-poe-2022", .ethConfigIndex = 0, .zbConfigIndex = 6, .mistConfigIndex = 0}, {"TubesZB-poe-2023", .ethConfigIndex = 0, .zbConfigIndex = 7, .mistConfigIndex = 0}, -}; + {"CZC-1.0", .ethConfigIndex = 2, .zbConfigIndex = 0, .mistConfigIndex = 1}, +}; \ No newline at end of file diff --git a/src/const/hw.h b/src/const/hw.h index 357307b..11da41c 100644 --- a/src/const/hw.h +++ b/src/const/hw.h @@ -46,7 +46,7 @@ struct BrdConfigStruct #define ETH_CFG_CNT 3 #define ZB_CFG_CNT 8 #define MIST_CFG_CNT 3 -#define BOARD_CFG_CNT 13 +#define BOARD_CFG_CNT 14 struct ThisConfigStruct { diff --git a/src/const/keys.cpp b/src/const/keys.cpp index a7d2d4e..4faa6ca 100644 --- a/src/const/keys.cpp +++ b/src/const/keys.cpp @@ -51,7 +51,7 @@ const char *discoveryKey = "discovery"; const char *reconnectIntKey = "reconnectInt"; const char *systemConfigKey = "system-config"; -const char *keepWebKey = "keepWeb"; +//const char *keepWebKey = "keepWeb"; const char *disableWebKey = "disableWeb"; const char *webAuthKey = "webAuth"; const char *webUserKey = "webUser"; @@ -77,7 +77,7 @@ const char *systemVarsKey = "system-vars"; const char *hwBtnIsKey = "hwBtnIs"; const char *hwLedUsbIsKey = "hwLedUsbIs"; const char *hwLedPwrIsKey = "hwLedPwrIs"; -const char *hwUartSelIsKey = "hwUartSelIs"; +//const char *hwUartSelIsKey = "hwUartSelIs"; const char *hwZigbeeIsKey = "hwZigbeeIs"; const char *workModeKey = "workMode"; const char *connectedSocketKey = "connectedSocket"; diff --git a/src/etc.cpp b/src/etc.cpp index c621682..80ad87f 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -178,26 +178,35 @@ void zigbeeRestart() void usbModeSet(usbMode mode) { - if (vars.hwUartSelIs) - { - String modeStr = (mode == ZIGBEE) ? "ZIGBEE" : "ESP"; - bool pinValue = (mode == ZIGBEE) ? HIGH : LOW; - String msg = "Switched USB to " + modeStr + ""; - printLogMsg(msg); - digitalWrite(hwConfig.mist.uartSelPin, pinValue); - if (pinValue) - { - ledControl.modeLED.mode = LED_ON; - } - else - { - ledControl.modeLED.mode = LED_OFF; - } + // if (vars.hwUartSelIs) + //{ + // String modeStr = (mode == ZIGBEE) ? "ZIGBEE" : "ESP"; + bool pinValue = (mode == ZIGBEE) ? HIGH : LOW; + // String msg = "Switched USB to " + modeStr + ""; + // printLogMsg(msg); + + if (mode == ZIGBEE) + { + Serial.updateBaudRate(systemCfg.serialSpeed); + } + else + { + Serial.updateBaudRate(115200); + } + // digitalWrite(hwConfig.mist.uartSelPin, pinValue); + if (pinValue) + { + ledControl.modeLED.mode = LED_ON; } else { - LOGD("NO vars.hwUartSelIs"); + ledControl.modeLED.mode = LED_OFF; } + //} + // else + //{ + // LOGD("NO vars.hwUartSelIs"); + //} } void getDeviceID(char *arr) @@ -387,6 +396,10 @@ void checkDNS(bool setup = false) { const char *wifiKey = "WiFi"; const char *ethKey = "ETH"; + const char *savedKey = "Saved"; + const char *restoredKey = "Restored"; + const char *dnsTagKey = "[DNS]"; + char buffer[100]; if (networkCfg.wifiEnable) { @@ -394,18 +407,16 @@ void checkDNS(bool setup = false) if (setup) { savedWifiDNS = currentWifiDNS; - LOGI("Saved %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str()); + snprintf(buffer, sizeof(buffer), "%s %s %s - %s", dnsTagKey, savedKey, wifiKey, savedWifiDNS.toString().c_str()); + printLogMsg(buffer); } else { if (currentWifiDNS != savedWifiDNS) { WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), savedWifiDNS); - LOGI("Updated %s DNS - %s", wifiKey, savedWifiDNS.toString().c_str()); - } - else - { - //LOGD("No update on %s DNS", wifiKey); + snprintf(buffer, sizeof(buffer), "%s %s %s - %s", dnsTagKey, restoredKey, wifiKey, savedWifiDNS.toString().c_str()); + printLogMsg(buffer); } } } @@ -416,18 +427,16 @@ void checkDNS(bool setup = false) if (setup) { savedEthDNS = currentEthDNS; - LOGI("Saved %s DNS - %s", ethKey, savedEthDNS.toString().c_str()); + snprintf(buffer, sizeof(buffer), "%s %s %s - %s", dnsTagKey, savedKey, ethKey, savedEthDNS.toString().c_str()); + printLogMsg(buffer); } else { if (currentEthDNS != savedEthDNS) { ETH.config(ETH.localIP(), ETH.gatewayIP(), ETH.subnetMask(), savedEthDNS); - LOGI("Updated %s DNS - %s", ethKey, savedEthDNS.toString().c_str()); - } - else - { - //LOGD("No update on %s DNS", ethKey); + snprintf(buffer, sizeof(buffer), "%s %s %s - %s", dnsTagKey, restoredKey, ethKey, savedEthDNS.toString().c_str()); + printLogMsg(buffer); } } } @@ -507,7 +516,7 @@ void setTimezone(String timezone) String timeNow = asctime(&timeinfo); timeNow.remove(timeNow.length() - 1); - printLogMsg("Local time: " + timeNow); + printLogMsg("[Time] " + timeNow); } const char *getGmtOffsetForZone(const char *zone) diff --git a/src/main.cpp b/src/main.cpp index d52724a..74c880c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -382,20 +382,20 @@ void connectWifi() } else { - if (!(systemCfg.workMode == WORK_MODE_USB && systemCfg.keepWeb)) - { // dont start ap in keepWeb - LOGD("NO SSID & PASS "); - if (!vars.connectedEther) - { - LOGD("and problem with LAN"); - startAP(true); - LOGD("so setupWifiAP"); - } - else - { - LOGD("but LAN is OK"); - } + // if (!(systemCfg.workMode == WORK_MODE_USB && systemCfg.keepWeb)) + //{ // dont start ap in keepWeb + LOGD("NO SSID & PASS "); + if (!vars.connectedEther) + { + LOGD("and problem with LAN"); + startAP(true); + LOGD("so setupWifiAP"); } + else + { + LOGD("but LAN is OK"); + } + // } } } @@ -434,37 +434,41 @@ void setupCoordinatorMode() String workModeString = systemCfg.workMode ? "USB" : "Network"; LOGI("%s", workModeString); - if ((systemCfg.workMode != WORK_MODE_USB) || systemCfg.keepWeb) - { // start network overseer - if (tmrNetworkOverseer.state() == STOPPED) - { - tmrNetworkOverseer.start(); - } - WiFi.onEvent(NetworkEvent); - if (networkCfg.ethEnable) - initLan(); - if (networkCfg.wifiEnable) - connectWifi(); + // if ((systemCfg.workMode != WORK_MODE_USB) || systemCfg.keepWeb) + //{ // start network overseer + if (tmrNetworkOverseer.state() == STOPPED) + { + tmrNetworkOverseer.start(); } + WiFi.onEvent(NetworkEvent); + if (networkCfg.ethEnable) + initLan(); + if (networkCfg.wifiEnable) + connectWifi(); + //} switch (systemCfg.workMode) { case WORK_MODE_USB: ledControl.modeLED.mode = LED_ON; - delay(500); + delay(100); usbModeSet(ZIGBEE); break; case WORK_MODE_NETWORK: ledControl.powerLED.mode = LED_BLINK_1Hz; + delay(100); + usbModeSet(XZG); break; default: break; } - if (!systemCfg.disableWeb && ((systemCfg.workMode != WORK_MODE_USB) || systemCfg.keepWeb)) + // if (!systemCfg.disableWeb && ((systemCfg.workMode != WORK_MODE_USB) || systemCfg.keepWeb)) + // updWeb = true; // handle web server + if (!systemCfg.disableWeb) updWeb = true; // handle web server - if (systemCfg.workMode == WORK_MODE_USB && systemCfg.keepWeb) - connectWifi(); // try 2 connect wifi + // if (systemCfg.workMode == WORK_MODE_USB && systemCfg.keepWeb) + // connectWifi(); // try 2 connect wifi } void setup() @@ -528,8 +532,10 @@ void setup() if (hwConfig.mist.uartSelPin > 0) { pinMode(hwConfig.mist.uartSelPin, OUTPUT); - vars.hwUartSelIs = true; - usbModeSet(XZG); + //vars.hwUartSelIs = true; + // usbModeSet(XZG); + bool fixState = (hwConfig.mist.uartSelPlr == 1) ? LOW : HIGH; + digitalWrite(hwConfig.mist.uartSelPin, fixState); } if ((hwConfig.zb.txPin > 0) && (hwConfig.zb.rxPin > 0) && (hwConfig.zb.rstPin > 0) && (hwConfig.zb.bslPin > 0)) @@ -563,7 +569,7 @@ void setup() printNVSFreeSpace(); zbFwCheck(); - + LOGD("done"); } @@ -684,7 +690,22 @@ void loop(void) } } - if (systemCfg.workMode != WORK_MODE_USB) + if (systemCfg.workMode == WORK_MODE_USB) + { + if (Serial2.available()) + { + Serial.write(Serial2.read()); + Serial.flush(); + } + if (Serial.available()) + { + Serial2.write(Serial.read()); + Serial2.flush(); + } + return; + } + + else if (systemCfg.workMode == WORK_MODE_NETWORK) { uint16_t net_bytes_read = 0; uint8_t net_buf[BUFFER_SIZE]; diff --git a/src/version.h b/src/version.h index 94baff3..9db3115 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ // AUTO GENERATED FILE #ifndef VERSION - #define VERSION "20240528" + #define VERSION "20240529" #endif diff --git a/src/web.cpp b/src/web.cpp index 1a7ed39..0913fd8 100644 --- a/src/web.cpp +++ b/src/web.cpp @@ -1006,11 +1006,11 @@ void handleGeneral() String result; doc[hwBtnIsKey] = vars.hwBtnIs; - doc[hwUartSelIsKey] = vars.hwUartSelIs; + //doc[hwUartSelIsKey] = vars.hwUartSelIs; doc[hwLedPwrIsKey] = vars.hwLedPwrIs; doc[hwLedUsbIsKey] = vars.hwLedUsbIs; - switch (systemCfg.workMode) + /*switch (systemCfg.workMode) { case WORK_MODE_USB: doc["checkedUsbMode"] = checked; @@ -1025,7 +1025,7 @@ void handleGeneral() if (systemCfg.keepWeb) { doc[keepWebKey] = checked; - } + }*/ if (systemCfg.disableLedPwr) { @@ -1142,6 +1142,18 @@ void handleSerial() String result; DynamicJsonDocument doc(1024); + switch (systemCfg.workMode) + { + case WORK_MODE_USB: + doc["usbMode"] = checked; + break; + case WORK_MODE_NETWORK: + doc["lanMode"] = checked; + break; + default: + break; + } + if (systemCfg.serialSpeed == 9600) { doc["9600"] = checked; @@ -1174,6 +1186,7 @@ void handleSerial() { doc["115200"] = checked; } + doc[socketPortKey] = String(systemCfg.socketPort); serializeJson(doc, result); @@ -1475,7 +1488,7 @@ void handleTools() DynamicJsonDocument doc(512); doc[hwBtnIsKey] = vars.hwBtnIs; - doc[hwUartSelIsKey] = vars.hwUartSelIs; + //doc[hwUartSelIsKey] = vars.hwUartSelIs; doc[hwLedPwrIsKey] = vars.hwLedPwrIs; doc[hwLedUsbIsKey] = vars.hwLedUsbIs; // doc["hostname"] = systemCfg.hostname; diff --git a/src/websrc/html/PAGE_GENERAL.html b/src/websrc/html/PAGE_GENERAL.html index 1b969ee..2d4fee7 100644 --- a/src/websrc/html/PAGE_GENERAL.html +++ b/src/websrc/html/PAGE_GENERAL.html @@ -24,7 +24,7 @@ - diff --git a/src/websrc/html/PAGE_ZIGBEE.html b/src/websrc/html/PAGE_ZIGBEE.html index d843609..3711a3b 100644 --- a/src/websrc/html/PAGE_ZIGBEE.html +++ b/src/websrc/html/PAGE_ZIGBEE.html @@ -51,6 +51,17 @@
+
+
+
+ + +
+
+
diff --git a/src/websrc/js/functions.js b/src/websrc/js/functions.js index e5f6c6b..dfa0a25 100644 --- a/src/websrc/js/functions.js +++ b/src/websrc/js/functions.js @@ -395,11 +395,11 @@ function loadPage(url) { apiGetPage(api.pages.API_PAGE_ROOT); break; case api.pages.API_PAGE_GENERAL.str: - apiGetPage(api.pages.API_PAGE_GENERAL, () => { - if (!$("#usbMode").prop(chck)) { - KeepWebDsbl(true); - } - }); + apiGetPage(api.pages.API_PAGE_GENERAL);//, () => { + //if (!$("#usbMode").prop(chck)) { + // KeepWebDsbl(true); + //} + //}); break; case api.pages.API_PAGE_MQTT.str: apiGetPage(api.pages.API_PAGE_MQTT, () => { @@ -668,7 +668,7 @@ function apiGetPage(page, doneCall, loader = true) { //hwBtnIs continue; } - if (property === "hwUartSelIs") { + /*if (property === "hwUartSelIs") { if (values[property]) { showDivById('modeSelCard'); showDivById('curModeSelCard'); @@ -676,7 +676,7 @@ function apiGetPage(page, doneCall, loader = true) { //hwBtnIs continue; - } + }*/ } dataReplace(values); } @@ -1976,7 +1976,7 @@ function modalConstructor(type, params) { } }); break; - case "keepWeb": + /*case "keepWeb": $(headerText).text(i18next.t('p.ge.kw')); $(modalBody).text(i18next.t('md.kw.msg')); $('