diff --git a/README.md b/README.md index d6791b4..d1a4d49 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ The software and hardware has been tested by the author for 5 years on the follo This circuit using by the author, here is some [boards](https://github.com/dzungpv/mitsubishi2MQTT/blob/master/hardware/Before_Install.jpg) before install. -You can also use ESP-32 module for more processing power. If using ESP-32 you can change default pins in config.h, by default app use TX pin 26 and RX pin 27 +You can also use ESP-32 module for more processing power. If using ESP-32 by default app use Serial (serial 0 port). +You can assign any compatible pin in the SETUP->OTHERS to use custom pin, example TX: 26, RX: 27, check ESP-32 manual for pin, when TX and RX set it will use Serial2 port. You can see more pictures in [`hardware`](https://github.com/dzungpv/mitsubishi2MQTT/tree/master/hardware) folder. *** diff --git a/main/config.h b/main/config.h index 678c270..72ea3f6 100644 --- a/main/config.h +++ b/main/config.h @@ -120,9 +120,9 @@ unsigned lastWifiScanMillis; const PROGMEM char *m2mqtt_version = "2023.12.2"; // Define global variables for files +int HP_TX = 0; // variable for the ESP32 custom TX pin, 0 is the defautl and it use hardware serial 0 +int HP_RX = 0; // variable for the ESP32 custom RX pin, 0 is the defautl and it use hardware serial 0 #ifdef ESP32 -#define HP_TX 26 // define the ESP32 custom TX pin -#define HP_RX 27 // define the ESP32 custom RX pin const PROGMEM char *wifi_conf = "/wifi.json"; const PROGMEM char *mqtt_conf = "/mqtt.json"; const PROGMEM char *unit_conf = "/unit.json"; diff --git a/main/html_pages.h b/main/html_pages.h index bae450b..7dea8a4 100644 --- a/main/html_pages.h +++ b/main/html_pages.h @@ -112,6 +112,14 @@ const char html_page_others[] PROGMEM = "" "" "

" + "

_TXT_TX_PIN_" + "
" + "" + "

" + "

_TXT_RX_PIN_" + "
" + "" + "

" "
" "" "" diff --git a/main/language_translations.h b/main/language_translations.h index af7c2b7..a732230 100644 --- a/main/language_translations.h +++ b/main/language_translations.h @@ -122,7 +122,8 @@ MAKE_WORD_TRANSLATION(txt_others_haauto, en::txt_others_haauto, vi::txt_others_h MAKE_WORD_TRANSLATION(txt_others_hatopic, en::txt_others_hatopic, vi::txt_others_hatopic, da::txt_others_hatopic, de::txt_others_hatopic, es::txt_others_hatopic, fr::txt_others_hatopic, it::txt_others_hatopic, ja::txt_others_hatopic, zh::txt_others_hatopic, ca::txt_others_hatopic) // TODO translate MAKE_WORD_TRANSLATION(txt_others_debug_packets, en::txt_others_debug_packets, vi::txt_others_debug_packets, da::txt_others_debug_packets, de::txt_others_debug_packets, es::txt_others_debug_packets, fr::txt_others_debug_packets, it::txt_others_debug_packets, ja::txt_others_debug_packets, zh::txt_others_debug_packets, ca::txt_others_debug_packets) // TODO translate MAKE_WORD_TRANSLATION(txt_others_debug_log, en::txt_others_debug_log, vi::txt_others_debug_log, da::txt_others_debug_log, de::txt_others_debug_log, es::txt_others_debug_log, fr::txt_others_debug_log, it::txt_others_debug_log, ja::txt_others_debug_log, zh::txt_others_debug_log, ca::txt_others_debug_log) // TODO translate - +MAKE_WORD_TRANSLATION(txt_others_tx_pin, en::txt_others_tx_pin, vi::txt_others_tx_pin, da::txt_others_tx_pin, de::txt_others_tx_pin, es::txt_others_tx_pin, fr::txt_others_tx_pin, it::txt_others_tx_pin, ja::txt_others_tx_pin, zh::txt_others_tx_pin, ca::txt_others_tx_pin) // TODO translate +MAKE_WORD_TRANSLATION(txt_others_rx_pin, en::txt_others_rx_pin, vi::txt_others_rx_pin, da::txt_others_rx_pin, de::txt_others_rx_pin, es::txt_others_rx_pin, fr::txt_others_rx_pin, it::txt_others_rx_pin, ja::txt_others_rx_pin, zh::txt_others_rx_pin, ca::txt_others_rx_pin) // TODO translate // Page Status MAKE_WORD_TRANSLATION(txt_status_title, en::txt_status_title, vi::txt_status_title, da::txt_status_title, de::txt_status_title, es::txt_status_title, fr::txt_status_title, it::txt_status_title, ja::txt_status_title, zh::txt_status_title, ca::txt_status_title) // TODO translate MAKE_WORD_TRANSLATION(txt_status_hvac, en::txt_status_hvac, vi::txt_status_hvac, da::txt_status_hvac, de::txt_status_hvac, es::txt_status_hvac, fr::txt_status_hvac, it::txt_status_hvac, ja::txt_status_hvac, zh::txt_status_hvac, ca::txt_status_hvac) // TODO translate diff --git a/main/languages/ca-ES.h b/main/languages/ca-ES.h index 681dfe1..d83a13e 100644 --- a/main/languages/ca-ES.h +++ b/main/languages/ca-ES.h @@ -92,6 +92,8 @@ namespace ca const char txt_others_hatopic[] PROGMEM = "HA tema d'autodescobriment"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; // Page Status const char txt_status_title[] PROGMEM = "Estat"; diff --git a/main/languages/da-DA.h b/main/languages/da-DA.h index 3a0dfe4..c08966e 100644 --- a/main/languages/da-DA.h +++ b/main/languages/da-DA.h @@ -91,7 +91,9 @@ namespace da const char txt_others_hatopic[] PROGMEM = "HA Autodiscovery topic"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Status"; const char txt_status_hvac[] PROGMEM = "HVAC Status"; diff --git a/main/languages/de-DE.h b/main/languages/de-DE.h index e7c0ced..eb1bacd 100644 --- a/main/languages/de-DE.h +++ b/main/languages/de-DE.h @@ -91,7 +91,9 @@ namespace de const char txt_others_hatopic[] PROGMEM = "HA Autodiscovery topic"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Status"; const char txt_status_hvac[] PROGMEM = "HVAC Status"; diff --git a/main/languages/en-GB.h b/main/languages/en-GB.h index a746d45..6e5dd47 100644 --- a/main/languages/en-GB.h +++ b/main/languages/en-GB.h @@ -92,6 +92,8 @@ namespace en const char txt_others_hatopic[] PROGMEM = "Autodiscovery topic"; const char txt_others_debug_packets[] PROGMEM = "MQTT debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT debug logs"; + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; // Page Status const char txt_status_title[] PROGMEM = "Status"; diff --git a/main/languages/es-ES.h b/main/languages/es-ES.h index 03a28d4..8138d4e 100644 --- a/main/languages/es-ES.h +++ b/main/languages/es-ES.h @@ -92,7 +92,9 @@ namespace es const char txt_others_hatopic[] PROGMEM = "HA Autodiscovery topic"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Estado"; const char txt_status_hvac[] PROGMEM = "Estado HVAC"; diff --git a/main/languages/fr-FR.h b/main/languages/fr-FR.h index 26e6dc1..cec0b48 100644 --- a/main/languages/fr-FR.h +++ b/main/languages/fr-FR.h @@ -92,7 +92,9 @@ namespace fr const char txt_others_hatopic[] PROGMEM = "HA Topic Découverte automatique"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Etats"; const char txt_status_hvac[] PROGMEM = "Etat HVAC"; diff --git a/main/languages/it-IT.h b/main/languages/it-IT.h index 8d807e6..652dc2f 100644 --- a/main/languages/it-IT.h +++ b/main/languages/it-IT.h @@ -92,7 +92,9 @@ namespace it const char txt_others_hatopic[] PROGMEM = "HA Autodiscovery topic"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Stato"; const char txt_status_hvac[] PROGMEM = "Stato HVAC"; diff --git a/main/languages/ja-JP.h b/main/languages/ja-JP.h index 1abd1b5..1ed62de 100644 --- a/main/languages/ja-JP.h +++ b/main/languages/ja-JP.h @@ -92,7 +92,9 @@ namespace ja const char txt_others_hatopic[] PROGMEM = "HA自動検出トピック"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "ステータス"; const char txt_status_hvac[] PROGMEM = "エアコン本体"; diff --git a/main/languages/vi-VN.h b/main/languages/vi-VN.h index 6e0ef59..58e776a 100644 --- a/main/languages/vi-VN.h +++ b/main/languages/vi-VN.h @@ -92,7 +92,9 @@ namespace vi const char txt_others_hatopic[] PROGMEM = "Chủ đề tự động khám phá"; const char txt_others_debug_packets[] PROGMEM = "MQTT gỡ lỗi gói tin"; const char txt_others_debug_log[] PROGMEM = "MQTT gỡ lỗi nhật ký"; - + const char txt_others_tx_pin[] PROGMEM = "Chân TX (ESP32, 0 dùng Serial)"; + const char txt_others_rx_pin[] PROGMEM = "Chân RX (ESP32, 0 dùng Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "Trạng thái"; const char txt_status_hvac[] PROGMEM = "Trạng thái ĐH"; diff --git a/main/languages/zh-CN.h b/main/languages/zh-CN.h index 1fb22ce..54f9177 100644 --- a/main/languages/zh-CN.h +++ b/main/languages/zh-CN.h @@ -92,7 +92,9 @@ namespace zh const char txt_others_hatopic[] PROGMEM = "HA 自动发现主题"; const char txt_others_debug_packets[] PROGMEM = "MQTT topic debug packets"; const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs"; - + const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use Serial)"; + const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use Serial)"; + // Page Status const char txt_status_title[] PROGMEM = "状态"; const char txt_status_hvac[] PROGMEM = "空调状态"; diff --git a/main/main.cpp b/main/main.cpp index e120fd6..996c20b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -30,9 +30,9 @@ bool loadMqtt(); bool loadUnit(); bool loadOthers(); void saveMqtt(String mqttFn, const String& mqttHost, String mqttPort, const String& mqttUser, const String& mqttPwd, String mqttTopic); -void saveUnit(String tempUnit, String supportMode, String loginPassword, String tempStep, String languageIndex); +void saveUnit(String tempUnit, String supportMode, String supportFanMode, String loginPassword, String tempStep, String languageIndex); void saveWifi(String apSsid, const String& apPwd, String hostName, const String& otaPwd); -void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs); +void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin); void saveCurrentOthers(); void initCaptivePortal(); void initMqtt(); @@ -257,8 +257,15 @@ void setup() // Allow Remote/Panel hp.enableExternalUpdate(); hp.enableAutoUpdate(); -#if defined(ESP32) && defined(HP_TX) && defined(HP_RX) - hp.connect(&Serial2, HP_RX, HP_TX); +#if defined(ESP32) + if (HP_TX > 0 && HP_RX > 0) + { + hp.connect(&Serial2, HP_RX, HP_TX); + } + else + { + hp.connect(&Serial); + } #else hp.connect(&Serial); #endif @@ -522,7 +529,7 @@ bool loadOthers() return false; } // Allocate document capacity. - const size_t capacity = JSON_OBJECT_SIZE(4) + 200; + const size_t capacity = JSON_OBJECT_SIZE(6) + 300; DynamicJsonDocument doc(capacity); deserializeJson(doc, configFile); // unit @@ -545,6 +552,17 @@ bool loadOthers() { _debugModeLogs = true; } + // custom tx rx pin + if (doc.containsKey("txPin") && doc.containsKey("rxPin")) // check key to prevent data is "null" if not exist + { + String txPin = doc["txPin"].as(); + String rxPin = doc["rxPin"].as(); + if (!txPin.isEmpty() && !rxPin.isEmpty()) + { + HP_TX = atoi(txPin.c_str()); + HP_RX = atoi(rxPin.c_str()); + } + } return true; } @@ -646,15 +664,17 @@ void saveWifi(String apSsid, const String& apPwd, String hostName, const String& configFile.close(); } -void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs) +void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin) { // Allocate document capacity. - const size_t capacity = JSON_OBJECT_SIZE(4) + 130; + const size_t capacity = JSON_OBJECT_SIZE(6) + 300; DynamicJsonDocument doc(capacity); doc["haa"] = haa; doc["haat"] = haat; doc["debugPckts"] = debugPckts; doc["debugLogs"] = debugLogs; + doc["txPin"] = txPin; + doc["rxPin"] = rxPin; File configFile = SPIFFS.open(others_conf, "w"); if (!configFile) { @@ -669,7 +689,7 @@ void saveCurrentOthers() String haa = others_haa ? "ON" : "OFF"; String debugPckts = _debugModePckts ? "ON" : "OFF"; String debugLogs = _debugModeLogs ? "ON" : "OFF"; - saveOthers(haa, others_haa_topic, debugPckts, debugLogs); + saveOthers(haa, others_haa_topic, debugPckts, debugLogs, String(HP_TX), String(HP_RX)); } // Initialize captive portal page @@ -1061,7 +1081,7 @@ void handleOthers(AsyncWebServerRequest *request) checkLogin(request); if (request->hasArg("save")) { - saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs")); + saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs"), request->arg("tx_pin"), request->arg("rx_pin")); String saveRebootPage = FPSTR(html_page_save_reboot); // localize saveRebootPage.replace("_TXT_M_SAVE_", translatedWord(FL_(txt_m_save))); @@ -1078,12 +1098,16 @@ void handleOthers(AsyncWebServerRequest *request) othersPage.replace("_TXT_OTHERS_HATOPIC_", translatedWord(FL_(txt_others_hatopic))); othersPage.replace("_TXT_OTHERS_DEBUG_PCKTS_", translatedWord(FL_(txt_others_debug_packets))); othersPage.replace("_TXT_OTHERS_DEBUG_LOGS_", translatedWord(FL_(txt_others_debug_log))); + othersPage.replace("_TXT_TX_PIN_", translatedWord(FL_(txt_others_tx_pin))); + othersPage.replace("_TXT_RX_PIN_", translatedWord(FL_(txt_others_rx_pin))); othersPage.replace("_TXT_F_ON_", translatedWord(FL_(txt_f_on))); othersPage.replace("_TXT_F_OFF_", translatedWord(FL_(txt_f_off))); othersPage.replace("_TXT_SAVE_", translatedWord(FL_(txt_save))); othersPage.replace("_TXT_BACK_", translatedWord(FL_(txt_back))); // set data othersPage.replace("_HAA_TOPIC_", others_haa_topic); + othersPage.replace("_TX_PIN_", String(HP_TX)); + othersPage.replace("_RX_PIN_", String(HP_RX)); if (others_haa) { othersPage.replace("_HAA_ON_", "selected"); @@ -2175,16 +2199,6 @@ void sendKeepAlive() if (_debugModeLogs) mqttClient.publish(ha_debug_logs_topic.c_str(), 1, false, (char *)"Failed to publish avialable status"); } - // send up time - rootInfo["upTime"] = getUpTime(); - String mqttOutput; - serializeJson(rootInfo, mqttOutput); - if (!mqttClient.publish(ha_state_topic.c_str(), 1, false, mqttOutput.c_str())) - { - if (_debugModeLogs) - mqttClient.publish(ha_debug_logs_topic.c_str(), 1, false, (char *)("Failed to publish up time")); - } - mqttOutput = ""; } void hpPacketDebug(byte *packet, unsigned int length, const char *packetDirection)