diff --git a/README.md b/README.md index 94effc6..f6b3bc3 100644 --- a/README.md +++ b/README.md @@ -317,20 +317,6 @@ If everything done correct, all shutters should work like before. If not, some s # MQTT -## additional information's (read only) - -status information about WiFi: - -```text -Topic: ESP32-Jarolift-Controller/wifi = { - "status":"online", - "rssi":"-50", - "signal":"90", - "ip":"192.168.1.1", - "date-time":"01.01.2022 - 10:20:30" -} -``` - ## Commands ### Shutter @@ -420,10 +406,46 @@ payload: {0b0000000000010101, 0x15, 21} ``` +## Status + +The controller will also send a status **based on the commands**. + +> [!IMPORTANT] +> But it is important to know, that this status is only a "copy of the received command". +> It does not correspond to the real status of the roller shutter, because unfortunately the roller shutter itself does not have a status that could be analyzed. So if the roller shutter is operated via the original remote control, for example, or via local operation, or is stopped during movement, then this status is no longer correct! + +```text + +Status: Shutter OPEN +topic: ../status/shutter/1 ... status/shutter/16 +payload: {0} + +Status: Shutter CLOSED +topic: ../status/shutter/1 ... status/shutter/16 +payload: {100} + +Status: Shutter SHADE +topic: ../status/shutter/1 ... status/shutter/16 +payload: {90} +``` > [!NOTE] > < ../ > is the placeholder for the MQTT topic which is specified in the settings. +## additional information's (read only) + +status information about WiFi: + +```text +Topic: ESP32-Jarolift-Controller/wifi = { + "status":"online", + "rssi":"-50", + "signal":"90", + "ip":"192.168.1.1", + "date-time":"01.01.2022 - 10:20:30" +} +``` + ## Home Assistant MQTT discovery for Home Assistant makes it easy to get all values in Home Assistant. diff --git a/README_DE.md b/README_DE.md index c7252e7..72cd849 100644 --- a/README_DE.md +++ b/README_DE.md @@ -316,20 +316,6 @@ Wenn alles richtig gemacht wurde, sollten alle Rollläden wie vorher funktionier # MQTT -### zusätzliche Informationen (nur lesen) - -Statusinformationen über WiFi: - -```text -Topic: ESP32-Jarolift-Controller/wifi = { - "status":"online", - "rssi":"-50", - "signal":"90", - "ip":"192.168.1.1", - "date-time":"01.01.2022 - 10:20:30" -} -``` - ## Kommandos ### Rolläden @@ -419,9 +405,45 @@ payload: {0b0000000000010101, 0x15, 21} ``` +## Status + +Der Controller sendet auch einen Status, **basierend auf den empfangenen Kommandos.** + +> [!IMPORTANT] +> Aber es ist wichtig zu beachten, dass dieser Status nicht dem tatsächlichen Zustand des Rollladens entspricht, denn leider sendet der Rolladen selbst keinen Status den man dazu auswerten könnte. Wenn also der Rolladen z.B. über die originale Fernbedienung bedient wird oder über eine vor Ort Bedienung, oder während der Bewegung gestoppt wird, dann stimmt dieser Status hier nicht mehr! + +```text + +Status: Rolladen OFFEN +topic: ../status/shutter/1 ... status/shutter/16 +payload: {0} + +Status: Rolladen GESCHLOSSEN +topic: ../status/shutter/1 ... status/shutter/16 +payload: {100} + +Status: Rolladen SCHATTEN +topic: ../status/shutter/1 ... status/shutter/16 +payload: {90} +``` + > [!NOTE] > < ../ > ist der Platzhalter für das MQTT-Topic, das in den Einstellungen angegeben ist. +## zusätzliche Informationen (nur lesen) + +Statusinformationen über WiFi: + +```text +Topic: ESP32-Jarolift-Controller/wifi = { + "status":"online", + "rssi":"-50", + "signal":"90", + "ip":"192.168.1.1", + "date-time":"01.01.2022 - 10:20:30" +} +``` + ## Home Assistant MQTT Discovery für Home Assistant macht es einfach, alle Werte in Home Assistant zu erhalten. diff --git a/include/config.h b/include/config.h index b2b5e27..70906b5 100644 --- a/include/config.h +++ b/include/config.h @@ -22,6 +22,7 @@ struct s_cfg_jaro { }; struct s_cfg_wifi { + bool enable = false; char ssid[128]; char password[128]; char hostname[128]; diff --git a/src/basics.cpp b/src/basics.cpp index 0f93604..aa18e15 100644 --- a/src/basics.cpp +++ b/src/basics.cpp @@ -113,32 +113,23 @@ void setupWiFi() { if (setupMode) { // start Accesspoint for initial setup - IPAddress ip(192, 168, 4, 1); - IPAddress gateway(192, 168, 4, 1); - IPAddress subnet(255, 255, 255, 0); - WiFi.softAPConfig(ip, gateway, subnet); + WiFi.softAPConfig(IPAddress(192, 168, 4, 1), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0)); WiFi.softAP("ESP32-Jarolift"); MY_LOGI(TAG, "\n! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !\n"); MY_LOGI(TAG, "> WiFi Mode: AccessPoint <"); MY_LOGI(TAG, "1. connect your device to SSID: ESP32-Jarolift"); MY_LOGI(TAG, "2. open Browser and go to Address: http://192.168.4.1"); MY_LOGI(TAG, "\n! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !\n"); - } else { + + } else if (config.wifi.enable) { + // setup callback function WiFi.onEvent(onWiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED); WiFi.onEvent(onWiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); + // manual IP-Settings if (config.wifi.static_ip) { - // manual IP-Settings - IPAddress manIp; - manIp.fromString(config.wifi.ipaddress); - IPAddress manSubnet; - manSubnet.fromString(config.wifi.subnet); - IPAddress manGateway; - manGateway.fromString(config.wifi.gateway); - IPAddress manDns; - manDns.fromString(config.wifi.dns); - WiFi.config(manIp, manGateway, manSubnet, manDns); + WiFi.config(IPAddress(config.wifi.ipaddress), IPAddress(config.wifi.gateway), IPAddress(config.wifi.subnet), IPAddress(config.wifi.dns)); } // connect to configured wifi AP @@ -228,7 +219,6 @@ void basicSetup() { // NTP ntpSetup(); - } /** diff --git a/src/config.cpp b/src/config.cpp index 3bd2fd2..0ab2822 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -18,6 +18,7 @@ static const char *TAG = "CFG"; // LOG TAG void configGPIO(); void configInitValue(); void checkGPIO(); +void configFinalCheck(); /** * ******************************************************************* @@ -39,6 +40,8 @@ void configSetup() { checkGPIO(); // gpio settings configGPIO(); + // check final settings + configFinalCheck(); } /** @@ -229,6 +232,7 @@ void configInitValue() { config.log.level = 4; // WiFi + config.wifi.enable = true; snprintf(config.wifi.hostname, sizeof(config.wifi.hostname), "ESP32-Jarolift"); // MQTT @@ -267,6 +271,7 @@ void configSaveToFile() { doc["lang"] = (config.lang); + doc["wifi"]["enable"] = config.wifi.enable; doc["wifi"]["ssid"] = config.wifi.ssid; doc["wifi"]["password"] = config.wifi.password; doc["wifi"]["hostname"] = config.wifi.hostname; @@ -398,7 +403,7 @@ void configLoadFromFile() { } else { config.lang = doc["lang"]; - + config.wifi.enable = doc["wifi"]["enable"]; EspStrUtil::readJSONstring(config.wifi.ssid, sizeof(config.wifi.ssid), doc["wifi"]["ssid"]); EspStrUtil::readJSONstring(config.wifi.password, sizeof(config.wifi.password), doc["wifi"]["password"]); EspStrUtil::readJSONstring(config.wifi.hostname, sizeof(config.wifi.hostname), doc["wifi"]["hostname"]); @@ -480,18 +485,30 @@ void configLoadFromFile() { } } + + file.close(); // Close the file (Curiously, File's destructor doesn't close the file) + configHashInit(); // init hash value + +} + +void configFinalCheck(){ + + // check network settings if (strlen(config.wifi.ssid) == 0) { // no valid wifi setting => start AP-Mode MY_LOGW(TAG, "no valid wifi SSID set => enter SetupMode and start AP-Mode"); setupMode = true; + } else if (config.wifi.enable == false && config.eth.enable == false) { + // no network enabled => start AP-Mode + MY_LOGW(TAG, "WiFi and ETH disabled => enter SetupMode and start AP-Mode"); + setupMode = true; } - file.close(); // Close the file (Curiously, File's destructor doesn't close the file) - configHashInit(); // init hash value - // check log level if (config.jaro.learn_mode == 0) { config.jaro.learn_mode = 4; // ESP_LOG_DEBUG } setLogLevel(config.log.level); -} + + +} \ No newline at end of file diff --git a/src/message.cpp b/src/message.cpp index 76908a8..13bb9d4 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -194,8 +194,13 @@ void messageCyclic() { // send cyclic infos if (mainTimer.cycleTrigger(10000) && !setupMode && mqttIsConnected()) { - sendWiFiInfo(); + sendSysInfo(); + + if (config.wifi.enable) { + sendWiFiInfo(); + } + if (config.eth.enable) { sendETHInfo(); } diff --git a/src/webUIcallback.cpp b/src/webUIcallback.cpp index f435a19..d5facfb 100644 --- a/src/webUIcallback.cpp +++ b/src/webUIcallback.cpp @@ -46,6 +46,9 @@ void webCallback(const char *elementId, const char *value) { // ------------------------------------------------------------------ // WiFi + if (strcmp(elementId, "cfg_wifi_enable") == 0) { + config.wifi.enable = EspStrUtil::stringToBool(value); + } if (strcmp(elementId, "cfg_wifi_hostname") == 0) { snprintf(config.wifi.hostname, sizeof(config.wifi.hostname), value); } diff --git a/src/webUIupdates.cpp b/src/webUIupdates.cpp index 42502e9..5d15ff3 100644 --- a/src/webUIupdates.cpp +++ b/src/webUIupdates.cpp @@ -96,28 +96,37 @@ void updateSystemInfoElements() { initJsonBuffer(jsonDoc); - // Network information - addJson(jsonDoc, "p09_wifi_ip", wifi.ipAddress); - snprintf(tmpMessage, sizeof(tmpMessage), "%i %%", wifi.signal); - addJson(jsonDoc, "p09_wifi_signal", tmpMessage); - snprintf(tmpMessage, sizeof(tmpMessage), "%ld dbm", wifi.rssi); - addJson(jsonDoc, "p09_wifi_rssi", tmpMessage); - - if (!WiFi.isConnected()) { - addJson(jsonDoc, "p00_wifi_icon", "i_wifi_nok"); - } else if (wifi.rssi < -80) { - addJson(jsonDoc, "p00_wifi_icon", "i_wifi_1"); - } else if (wifi.rssi < -70) { - addJson(jsonDoc, "p00_wifi_icon", "i_wifi_2"); - } else if (wifi.rssi < -60) { - addJson(jsonDoc, "p00_wifi_icon", "i_wifi_3"); + // WiFi information + if (config.eth.enable) { + addJson(jsonDoc, "p09_wifi_ip", wifi.ipAddress); + snprintf(tmpMessage, sizeof(tmpMessage), "%i %%", wifi.signal); + addJson(jsonDoc, "p09_wifi_signal", tmpMessage); + snprintf(tmpMessage, sizeof(tmpMessage), "%ld dbm", wifi.rssi); + addJson(jsonDoc, "p09_wifi_rssi", tmpMessage); + + if (!WiFi.isConnected()) { + addJson(jsonDoc, "p00_wifi_icon", "i_wifi_nok"); + } else if (wifi.rssi < -80) { + addJson(jsonDoc, "p00_wifi_icon", "i_wifi_1"); + } else if (wifi.rssi < -70) { + addJson(jsonDoc, "p00_wifi_icon", "i_wifi_2"); + } else if (wifi.rssi < -60) { + addJson(jsonDoc, "p00_wifi_icon", "i_wifi_3"); + } else { + addJson(jsonDoc, "p00_wifi_icon", "i_wifi_4"); + } + } else { - addJson(jsonDoc, "p00_wifi_icon", "i_wifi_4"); + addJson(jsonDoc, "p00_wifi_icon", ""); + addJson(jsonDoc, "p09_wifi_ip", "-.-.-.-"); + addJson(jsonDoc, "p09_wifi_signal", "0"); + addJson(jsonDoc, "p09_wifi_rssi", "0 dbm"); } addJson(jsonDoc, "p09_eth_ip", strlen(eth.ipAddress) ? eth.ipAddress : "-.-.-.-"); addJson(jsonDoc, "p09_eth_status", eth.connected ? WEB_TXT::CONNECTED[config.lang] : WEB_TXT::NOT_CONNECTED[config.lang]); + // ETH information if (config.eth.enable) { if (eth.connected) { addJson(jsonDoc, "p00_eth_icon", "i_eth_ok"); @@ -378,7 +387,7 @@ void webUIupdates() { processGitHubVersion(); // perform GitHub update processGitHubUpdate(); - + // update webUI Logger if (webLogRefreshActive()) { webReadLogBufferCyclic(); diff --git a/web/html/12_settings.html b/web/html/12_settings.html index 7c3fb10..31a0483 100644 --- a/web/html/12_settings.html +++ b/web/html/12_settings.html @@ -37,6 +37,17 @@
+
+ +
+ +
+
+