Skip to content

Update ModbusTLS.h #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/ModbusTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ class ModbusTLS : public ModbusAPI<ModbusTCPTemplate<WiFiServerSecure, WiFiClien
#endif
#if defined(MODBUSIP_USE_DNS)
bool connect(String host, uint16_t port, const char* client_cert = nullptr, const char* client_private_key = nullptr, const char* ca_cert = nullptr) {
return connect(resolver(host.c_str()), port, client_cert, client_private_key, ca_cert);
return connect(resolver(host.c_str()), port, client_cert, client_private_key, ca_cert, host.c_str());
}
bool connect(const char* host, uint16_t port, const char* client_cert = nullptr, const char* client_private_key = nullptr, const char* ca_cert = nullptr) {
return connect(resolver(host), port, client_cert, client_private_key, ca_cert);
return connect(resolver(host), port, client_cert, client_private_key, ca_cert, host);
}
#endif
bool connect(IPAddress ip, uint16_t port, const char* client_cert = nullptr, const char* client_private_key = nullptr, const char* ca_cert = nullptr) {
bool connect(IPAddress ip, uint16_t port, const char* client_cert = nullptr, const char* client_private_key = nullptr, const char* ca_cert = nullptr, const char* host = nullptr) {
if (!ip)
return false;
if(getSlave(ip) >= 0)
Expand All @@ -113,8 +113,14 @@ class ModbusTLS : public ModbusAPI<ModbusTCPTemplate<WiFiServerSecure, WiFiClien
}
#endif
//return tcpclient[p]->connect(ip, port);
if (!tcpclient[p]->connect(ip, port))
if (host) {
if (!tcpclient[p]->connect(host, port))
return false;
}
else {
if (!tcpclient[p]->connect(ip, port))
return false;
}
return true;
}
};