diff --git a/platformio.ini b/platformio.ini index 393fdff..3a68a60 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,4 +45,4 @@ platform = espressif32 board = lolin_s2_mini framework = arduino lib_deps = ${env.lib_deps_ext} -build_flags = -D CORE_DEBUG_LEVEL=0 +build_flags = -D CORE_DEBUG_LEVEL=0 -DHVAC_UART=0 diff --git a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino index c2df08b..3b323aa 100644 --- a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino +++ b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino @@ -54,6 +54,12 @@ ESP8266WebServer server(80); // ESP8266 web #include INCLUDE_FILE(MY_LANGUAGE) #endif +#ifndef HVAC_UART +#define HVAC_UART 0 +#endif + +HardwareSerial* SerialHvac = NULL; + // wifi, mqtt and heatpump client instances WiFiClient espClient; PubSubClient mqtt_client(espClient); @@ -86,6 +92,22 @@ int uploaderror = 0; void setup() { // Start serial for debug before HVAC connect to serial + switch(HVAC_UART) { + #ifdef Serial2 + case 2: + SerialHvac = &Serial2; + break; + #endif + #ifdef Serial1 + case 1: + SerialHvac = &Serial1; + break; + #endif + case 0: + SerialHvac = &Serial0; + break; + } + Serial.begin(115200); // Serial.println(F("Starting Mitsubishi2MQTT")); // Mount SPIFFS filesystem @@ -187,18 +209,19 @@ void setup() { // Allow Remote/Panel hp.enableExternalUpdate(); hp.enableAutoUpdate(); - hp.connect(&Serial); - heatpumpStatus currentStatus = hp.getStatus(); - heatpumpSettings currentSettings = hp.getSettings(); - rootInfo["roomTemperature"] = convertCelsiusToLocalUnit(currentStatus.roomTemperature, useFahrenheit); - rootInfo["temperature"] = convertCelsiusToLocalUnit(currentSettings.temperature, useFahrenheit); - rootInfo["fan"] = currentSettings.fan; - rootInfo["vane"] = currentSettings.vane; - rootInfo["wideVane"] = currentSettings.wideVane; - rootInfo["mode"] = hpGetMode(currentSettings); - rootInfo["action"] = hpGetAction(currentStatus, currentSettings); - rootInfo["compressorFrequency"] = currentStatus.compressorFrequency; - lastTempSend = millis(); + if (hp.connect(SerialHvac)) { + heatpumpStatus currentStatus = hp.getStatus(); + heatpumpSettings currentSettings = hp.getSettings(); + rootInfo["roomTemperature"] = convertCelsiusToLocalUnit(currentStatus.roomTemperature, useFahrenheit); + rootInfo["temperature"] = convertCelsiusToLocalUnit(currentSettings.temperature, useFahrenheit); + rootInfo["fan"] = currentSettings.fan; + rootInfo["vane"] = currentSettings.vane; + rootInfo["wideVane"] = currentSettings.wideVane; + rootInfo["mode"] = hpGetMode(currentSettings); + rootInfo["action"] = hpGetAction(currentStatus, currentSettings); + rootInfo["compressorFrequency"] = currentStatus.compressorFrequency; + lastTempSend = millis(); + } } else { dnsServer.start(DNS_PORT, "*", apIP); @@ -1252,7 +1275,7 @@ void write_log(String log) { heatpumpSettings change_states(heatpumpSettings settings) { if (server.hasArg("CONNECT")) { - hp.connect(&Serial); + hp.connect(SerialHvac); } else { bool update = false;