A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.
User avatar
By Tjeerd
#67998 Hi everyone! For a project I am looking for a way to see when I get in incoming TCP connection packet without receiving actual data. I am trying to receive data from an alarm panel and upon connection from the panel, I need to send the first packet as a reply to get transmission going.

Code: Select all  if (!TcpServerClient.connected()) {
    TcpServerClient = TcpServer.available();
  } else {
    Serial.println("Incoming connection");
    while (TcpServerClient.connected())
      Serial.println("Connection available");
      while (TcpServerClient.available())
        Serial.println("Receiving incomming TCP packet");
        TcpServerClient.read(TCPpacketBuffer, TCP_TX_PACKET_MAX_SIZE);

None of the Serial.println's get displayed upon the initial connection, only when receiving a complete data packet.

I found a project on GitHub to implement sockets https://github.com/i-n-g-o/esp-socket/tree/master/examples/esp8266ServerCallbacks but to get it to work like it is, is way over my head ...

Does someone know if there's a callback or something similar to: server.onConnected() ?

Attached is a screenshot of the sequence.
You do not have the required permissions to view the files attached to this post.
User avatar
By gdsports
#68053 Use hasClient() to detect new incoming TCP connections.

Code: Select all    // Check for new clients.
    if (server.hasClient()) {
        newClient = server.available();
        Serial.print("New client: "); Serial.println(newClient.remoteIP());
        newClient.println("Hello, new client");
    }  // ...
User avatar
By Tjeerd
#68097 I've tried it but unfortunately it's not sending the first packet although it seems it's doing. I can see the delay, in the packets, but it closed immediately without receiving.

Code: Select all  if (server.hasClient()) {
    Serial.println("We received a client connection");
    client = server.available();

    if (client && sent == false) {
      Serial.println("Transmitting conn packet");
      // Send first recon packet since we didn't receive anything yet
      sent = true;
      byte sendBuffer[] = {0x0, 0x4, 0x85, 0x34};
      client.write((const uint8_t*) sendBuffer, sizeof(sendBuffer));


    while (client.available()) {
      Serial.println("Getting response");
      client.read(TCPpacketBuffer, TCP_TX_PACKET_MAX_SIZE);
      debugPacket(TCPpacketBuffer, TCP_TX_PACKET_MAX_SIZE);

Any suggestions?
You do not have the required permissions to view the files attached to this post.
User avatar
By gdsports
#68113 Could be a problem on the client side. Use netcat or Telnet to connect to the ESP. Note hasClient only returns true when there is an unaccepted client. When the client is accepted by calling server.available(), hasClient returns false. I suggest looking at a fully working example which use hasClient.

https://github.com/esp8266/Arduino/blob ... Serial.ino