Skip to content

Commit

Permalink
Allow specifying the UART number to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleech committed Dec 13, 2023
1 parent 1c1c9ac commit 8e90b0b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 36 additions & 13 deletions src/mitsubishi2mqtt/mitsubishi2mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e90b0b

Please sign in to comment.