w5500-evb-pico as TCP client, send simple TCP packet to server.

Hello,

I’m trying to send a simple TCP packet to a TCP server on the w5500-evb-pico.
w5500-evb-pico (TCP client) → PC (packetSender TCP server)
When I send a TCP packet with packet sender application to the TCP server IP I receive the packet correctly.

Because i don’t get the status SOCK_ESTABLISHED it’s not possible to send data.

Code to init socket:

    uint16_t any_port = 1000;
    socket(sn, Sn_MR_TCP, any_port, 0x00);
    while (getSn_SR(sn) != SOCK_INIT)
        ;

After a few seconds, I get SOCK_INIT (0x13)
So this seems OK.

Code to connect:

    sn = 0;                                 // using only the socket 0
    uint Serverip[4] = {192, 168, 201, 55}; // set Server(destination) IP
    uint Serverport = 54858;                // set Server(destination) port

    connect(sn, Serverip, Serverport);

    while (getSn_SR(sn) != SOCK_ESTABLISHED)
        ;

The above will never get to SOCK_ESTABLISHED (0x17) instead it gets stuck on SOCK_SYNSENT (0x15)

The TCP server does have the ports opened, I can send with another PC with packetSender to the server with packetSender.

I add the complete code block, you can add it to the w5x00_loopback.c example.

wizchip_spi_initialize();
    wizchip_cris_initialize();
    wizchip_reset();
    wizchip_initialize();
    wizchip_check();
    network_initialize(g_net_info);
    print_network_information(g_net_info);

    int32_t ret; // return value for SOCK_ERRORs

    uint16_t sn = 0; // using only the socket 0
    uint16_t any_port = 1000;

    // init socket
    socket(sn, Sn_MR_TCP, any_port, 0x00);
    while (getSn_SR(sn) != SOCK_INIT)
        ;

    // connect part
    sn = 0;                                 // using only the socket 0
    uint Serverip[4] = {192, 168, 201, 55}; // set Server(destination) IP
    uint Serverport = 54858;                // set Server(destination) port

    connect(sn, Serverip, Serverport);

    while (getSn_SR(sn) != SOCK_ESTABLISHED)
        ;
    // basic send, just to see if it works    
    send(sn, "test", strlen("test"), 0);

Does anybody have more information or a minimal example how to send a TCP packet?

It means that remote node (server) does not reply with SYN/ACK.
Why? Good question. What is MAC address? Do you have network mask set properly? Do you have gateway set to something correct? What network tracing (using Wireshark for example) shows?

I’m testing with a PC with packet sender as remote node (server).
Because it’s not working I have used another PC (client) with another instance of packet sender so I can use this as a client to send from one PC to the other. PC1 server, PC2 client. Just to be sure the remote node was actually working.

I do have another TCP server, an ESC/POS printer. If I sent to this with packet sender “Test\n”.
I can see Test on the paper of the printer.

However if I try this TCP server endpoint with the wiznet connect call , SOCK_SYNSENT (0x15) stays there.

Below a picture from wireshark when capturing on PC2 (client, 192.168.0.219) when sending “Test\n” to the ESC/POS printer. (TCP server, 192.168.0.155:9100)

And this is the output from packet sender when i send “Test\n” to the printer:

The above prints out the text on the printer and it seems the printer sends back a message.
If i would change the above IP in the application to the IP of another PC running packet sender and change the port accordingly, i can send to this PC as well.

IP settings from wiznet-evb-pico:

{
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 0, 20},                  // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 0, 1},                    // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
        .dhcp = 0                                    // DHCP enable/disable
};

I have tested on two different networks now, and same result. That’s why in my initial post you can see different IP range, 192, 168, 201, x

This might be the key point here. You try to connect from network 192.168.0 to the 192.168.201 with mask 255.255.255.0. This means nodes are on different networks, and W5500 routes packets through the gateway. Does 192.168.0.1 know route to the 192.168.201 network, and actually can function as a router? If can, may it block traffic using its firewall?

No it is not, i mean that i have done the whole setup in 192.168.201.x on my office.
And now i have reconfigured everything for my home network in 192.168.0.x.

So the code in my initial post is now:

sn = 0;                                 // using only the socket 0
    uint Serverip[4] = {192, 168, 0, 115}; // set Server(destination) IP
    uint Serverport = 9100;                // set Server(destination) port

    connect(sn, Serverip, Serverport);

    while (getSn_SR(sn) != SOCK_ESTABLISHED)
        ;

As stated before, i can send to the tcp server on another pc also acting as a client.
And with this its actualy printing. So the network is fine.

Then the only ultimate way is to look at the traffic between W5500 and server. Set up one of the PCs you have as a bridge/sharing center (needs 2 network interfaces), connect one interface to W5500 and another to your network and use Wireshark to capture traffic going through it. First, we will see what exactly is going on, and second, we will examine details of all the packets to find out why server does not respond to SYN.

So i setup a RPI4 with an extra Ethernet NIC trough USB. And captured with wireshark.

The working client PC, sends one TCP packet to printer. And printer prints:

The same but with the W5500-evb-pico:

The test pc or w5500 have 192.168.201.237 as ip.
And the tcp server 192.168.201.38

If you look at the first picture for W5500 you will see that first time SYN is sent to host with IP 192.0.0.0, which is definitely wrong. Check your code why destination IP address is not correct.
Solve this issue and then we will look at the “TCP retransmissions” if needed.

I checked my code and the IP is correctly inside the variable before dooing the connect method.

How I set my server IP, and the call connect():

    sn = 0;                                 // using only the socket 0
    uint8_t server_ip[4] = {192, 168, 201, 38}; // set Server(destination) IP
    uint server_port = 9100;                     // set Server(destination) port
    printf("%d:Connected server ip: %d.%d.%d.%d \r\n", sn, server_ip[0], server_ip[1], server_ip[2], server_ip[3]);
    connect(sn, server_ip, server_port);

You previously said that you have changed server to local network server at the 192.168.0.115. Now I again see it is at 192.168.201.38, therefore W5500 sends SYN packet to the gateway, and 192.0.0.0 is an address of the gateway set in the W5500. Please do not change your setup, these changes make troubleshooting harder and pointless.

I have to change since i work on it in work env and home.
But I’ll now leave it at the 192.168.201.x.

The complete IP configuration from the tests:

{
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 201, 237},                  // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 201, 1},                    // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
        .dhcp = 0                                    // DHCP enable/disable
}

And the TCP server IP:

    uint8_t server_ip[4] = {192, 168, 201, 38}; // set Server(destination) IP
    uint server_port = 9100;

If i run the code i can print all the necessary vars and they contain the correct IP.

I have no 192.0.0.0 in my code. Also not in the previous setups, like home network 192.168.0.x.

Is it possible to try this yourself on a W5500-EVB-pico board?
I have also tested on a second board but with same results.

This was not the case, when testing with packet tracer where results are in my last post.
The gateway was never 192.0.0.0 but 192.168.201.1.


This is where your SYN packet was sent last time.

Please perform the same test with Wireshark capturing using the settings you listed above (in previous reply).

This package was sent with using the settings i listed above (in previous reply).

I’ll redo, but i’ts gone be the same result i’m afraid.

Yes please, and do not change anything to the configuration after the capturing the log. Then we will see how to track the problem down.

Today i test again, without any modifications to the source.
And everything is working fine, I have spent over a week on this.
And the worst thing is, I 'm not sure what was the issue.

I changed the IP’s from the TCP server (after verifying it worked with the old setup) , and also this worked.

I have another question concerning the IP setup of the wiznet.
If I now connect the w5500 to a switch and then the TCP server (printer) also to the switch.
I can send TCP messages.

However, when I connect the Ethernet from w5500 directly to the TCP server (that uses static IP) it doesn’t get past wizchip_initialize();

Is there a way to get around this?

Please give link to the routine code and identify where exactly it hangs (putting breakpoints/debug output in the routine).

I have a similar problem when using the Pico W5500 board.
It hangs when wiznet_initalize() is called but ONLY when there in no ethernet cable plugged into the board and the link LED is obviously Off. I haven’t found a solution, other than plugging in the Ethernet cable.
I will raise a separate question on the forum for this.