Hi,
After update 2022.12.xx the TCP request stopped working.
No compilation error but the connection fails.
If I set the framework to version 2.0.0 everything works again, but I’d like to fix the code to keep everything running without a workaround.
Any idea?
yaml:
substitutions:
#Configurações do dispositivo:
friendly_name: Teste
name: teste
esp32:
board: esp32dev
framework:
type: arduino
# Enable Home Assistant API
api:
encryption:
key: !secret teste_key
packages:
device_base: !include .device_basic_remote_esp32.yaml
wifi:
use_address: !secret teste_ddns
esphome:
includes:
- ./teste/teste.h
custom_component:
- lambda: |-
auto command = new CommandComponent();
return {command};
teste.h
#include "esphome.h"
#include "WiFi.h"
unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
const long interval = 10000;
int connection_failed = 0;
int max_connection_failed = 3;//
//// Check loop time
unsigned long StartTime = millis();
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
const uint16_t port = 9054;
const char * host = "192.168.xx.xx";
int timeout = 500; // timeout in milliseconds
String Status = {"\x00\x01\x02\x03\x04"};
String line;
String Model = " ";
class CommandComponent : public Component {
public:
void setup() override {
}
void loop() override {
unsigned long StartTime = millis();
currentMillis = millis();
if (millis() - previousMillis >= interval) {
previousMillis = millis();
status_update();
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
if ((ElapsedTime >= 30) && (ElapsedTime <= 1000)) {
Serial.print("ElapsedTime: ");
Serial.println(ElapsedTime);
}
Serial.print("ElapsedTime: ");
Serial.println(ElapsedTime);
}
line = "";
}
void status_update() {
WiFiClient client;
if (!client.connect(host, port, timeout)) {
Serial.println("Connection to host failed");
ESP_LOGD("ERROR", "Connection to host failed");
connection_failed++;
if (connection_failed > max_connection_failed) {
ESP_LOGD("ERROR", "Connection to host failed max exceeded");
}
return;
}
client.print(Status);
line = client.readStringUntil(timeout);
delay(5);
ESP_LOGD("Teste", "Teste %s", line);
client.stop();
}
};
workaround:
esp32:
board: esp32dev
framework:
type: arduino
version: 2.0.0