Skip to content

Commit 9f764ac

Browse files
authored
TCP bridge more logging (#23410)
1 parent f660ba7 commit 9f764ac

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tasmota/tasmota_xdrv_driver/xdrv_41_tcp_bridge.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,16 @@ void TCPLoop(void)
6363
if ((server_tcp) && (server_tcp->hasClient())) {
6464
WiFiClient new_client = server_tcp->available();
6565

66-
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Got connection from %s"), new_client.remoteIP().toString().c_str());
66+
// count already connected ports
67+
uint32_t connected = 0;
68+
for (uint32_t i=0; i<nitems(client_tcp); i++) {
69+
WiFiClient &client = client_tcp[i];
70+
if (client.connected()) {
71+
connected++;
72+
}
73+
}
74+
75+
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Got connection from %s (%i already connected)"), new_client.remoteIP().toString().c_str(), connected);
6776
// Check for IP filtering if it's enabled.
6877
if (ip_filter_enabled) {
6978
if (ip_filter != new_client.remoteIP()) {
@@ -80,13 +89,17 @@ void TCPLoop(void)
8089
WiFiClient &client = client_tcp[i];
8190
if (!client) {
8291
client = new_client;
92+
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "Adding connection to slot %i"), i);
8393
break;
8494
}
8595
}
8696
if (i >= nitems(client_tcp)) {
8797
i = client_next++ % nitems(client_tcp);
8898
WiFiClient &client = client_tcp[i];
89-
client.stop();
99+
if (client.connected()) {
100+
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "Replacing connection in slot %i, closing connection from %s"), i, client.remoteIP().toString().c_str());
101+
client.stop();
102+
}
90103
client = new_client;
91104
}
92105
}

0 commit comments

Comments
 (0)