Skip to content

Commit

Permalink
Fix missing UART pin when retry for ESP32. Not reset connected state …
Browse files Browse the repository at this point in the history
…when retry, make control more stable.
  • Loading branch information
dzungpv committed Oct 14, 2023
1 parent cea90c5 commit ce460c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/HeatPump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
bitrate = 2400;
retry = true;
}
connected = false;
if (rx >= 0 && tx >= 0) {
#if defined(ESP32)
#if defined(ESP32)
rxPin = rx;
txPin = tx;
_HardSerial->begin(bitrate, SERIAL_8E1, rx, tx);
#else
_HardSerial->begin(bitrate, SERIAL_8E1);
#endif
} else {
#if defined(ESP32)
_HardSerial->begin(bitrate, SERIAL_8E1, rxPin, txPin);
#else
_HardSerial->begin(bitrate, SERIAL_8E1);
#endif
}
if(onConnectCallback) {
onConnectCallback();
Expand All @@ -133,7 +138,8 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
if(packetType != RCVD_PKT_CONNECT_SUCCESS && retry){
return connect(serial, 9600, rx, tx);
}
return packetType == RCVD_PKT_CONNECT_SUCCESS;
connected = (packetType == RCVD_PKT_CONNECT_SUCCESS);
return connected;
//}
}

Expand Down
2 changes: 2 additions & 0 deletions src/HeatPump.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class HeatPump
heatpumpFunctions functions;

HardwareSerial * _HardSerial {nullptr};
int rxPin; // save rx pin for retry ESP32
int txPin; // save tx pin for retry ESP32
unsigned long lastSend;
bool waitForRead;
int infoMode;
Expand Down

0 comments on commit ce460c3

Please sign in to comment.