From 1b423bfa28f2dfd27ecee531113f2f66a95d39ed Mon Sep 17 00:00:00 2001 From: Andras Kiss Date: Wed, 16 Feb 2022 11:32:58 +0100 Subject: [PATCH] add client connection mode --- tasmota/xdrv_41_tcp_bridge.ino | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_41_tcp_bridge.ino b/tasmota/xdrv_41_tcp_bridge.ino index c24fae5ec..75ca5ce91 100644 --- a/tasmota/xdrv_41_tcp_bridge.ino +++ b/tasmota/xdrv_41_tcp_bridge.ino @@ -41,11 +41,11 @@ IPAddress ip_filter; TasmotaSerial *TCPSerial = nullptr; const char kTCPCommands[] PROGMEM = "TCP" "|" // prefix - "Start" "|" "Baudrate" "|" "Config" + "Start" "|" "Baudrate" "|" "Config" "|" "Connect" ; void (* const TCPCommand[])(void) PROGMEM = { - &CmndTCPStart, &CmndTCPBaudrate, &CmndTCPConfig + &CmndTCPStart, &CmndTCPBaudrate, &CmndTCPConfig, &CmndTCPConnect }; // @@ -216,6 +216,45 @@ void CmndTCPConfig(void) { ResponseCmndChar_P(GetSerialConfig(0x7F & Settings->tcp_config).c_str()); } +// +// Command `Connect` +// Params: port, +// +void CmndTCPConnect(void) { + int32_t tcp_port = XdrvMailbox.payload; + + if (ArgC() == 2) { + char sub_string[XdrvMailbox.data_len]; + WiFiClient new_client; + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Connecting to %s on port %d"), ArgV(sub_string, 2),tcp_port); + if (new_client.connect(ArgV(sub_string, 2),tcp_port)) { + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "connected!")); + } else { + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "error connecting!")); + } + + // find an empty slot + uint32_t i; + for (i=0; i= nitems(client_tcp)) { + i = client_next++ % nitems(client_tcp); + WiFiClient &client = client_tcp[i]; + client.stop(); + client = new_client; + } + } else { + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_TCP "Usage: port,ip_address")); + } + + ResponseCmndDone(); +} + /*********************************************************************************************\ * Interface \*********************************************************************************************/