Post topics, source code that relate to the Arduino Platform

User avatar
By Ripper121
#29322 I will do a UART<>TCP bridge. It works fine but when i send data from Uart to TCP it is so Slow it needs seconds to send 10 Bytes.
Is there a way to get it faster?

Code: Select allvoid setup() {
  Serial.begin(115200);
  delay(10);

  Serial.print("Battery: ");
  Serial.println(ESP.getVcc());
  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    if (reconnectCount >= 60) {
      ESP.restart();
    }
    Serial.print(".");
    reconnectCount++;
  }
  reconnectCount = 0;

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  connectToServer();
}


void loop() {
  while (Serial.available() > 0) {
    byte inChar = Serial.read();
    //if (client.connected()) {
    client.write(inChar);
    /*
    } else {
    delay(500);
    if (reconnectCount >= 60) {
      ESP.restart();
    }
    Serial.println("Connection lost!");
    Serial.println("Try to reconnect...");
    connectToServer();
    reconnectCount++;
    }
    */
  }

  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
}

void connectToServer() {
  Serial.print("connecting to ");
  Serial.println(host);
  const int httpPort = 21;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
}
User avatar
By Ripper121
#29324 Dont Know why, but this works faster:

Code: Select all  while (Serial.available() > 0) {
    size_t len = Serial.available();
    uint8_t * sbuf = (uint8_t *)malloc(len);
    Serial.readBytes(sbuf, len);
    if (client.connected()) {
      client.write((uint8_t *)sbuf, len);
      yield();
    } else {
      delay(500);
      if (reconnectCount >= 60) {
        ESP.restart();
      }
      Serial.println("Connection lost!");
      Serial.println("Try to reconnect...");
      connectToServer();
      reconnectCount++;
    }
    free(sbuf);
  }