WIZnet Developer Forum

Not Connecting

here is my code. The chip setups ok and can set and read back the IP/SN/MAC etc I can also ping the teh device from my PC. But when i try to connect to my server the connect just returns -13 timeout or -4.

static THD_FUNCTION( ThreadHTTPC, arg )
{
int32_t ret;
uint16_t sn = 1;
uint16_t port = 80;
uint16_t size = 0, i = 0;

(void)arg;

chRegSetThreadName( "httc" );
chThdSleepMilliseconds( 10000 );

while( TRUE )
{
  chThdSleepMilliseconds( 10 );

  switch(getSn_SR(sn))
   {
      case SOCK_ESTABLISHED :
         if(getSn_IR(sn) & Sn_IR_CON)
         {

           MBS_DEBUG( DBG_MASK_APP,
                      "$ APP - Web client established(%i)\r\n", sn );

           setSn_IR(sn,Sn_IR_CON);

             ret = send(sn, httppost, sizeof(httppost));

             if(ret < 0)
             {
                close(sn);
             }
            }
         break;

      case SOCK_CLOSE_WAIT :
         if((ret=disconnect(sn)) != SOCK_OK) return ret;
         break;

      case SOCK_INIT :
          MBS_DEBUG( DBG_MASK_APP,
                     "$ APP - Web client connect(%i)\r\n", sn );

             ret = connect(sn, Domain_IP, PORT_HTTPS);

             if(ret == SOCK_OK )
             {
                 MBS_DEBUG( DBG_MASK_APP,
                            "$ APP - Web socket created(%i)\r\n", sn );
             }
             else if(ret == SOCKERR_TIMEOUT )
             {
                 MBS_DEBUG( DBG_MASK_APP,
                            "$ APP - Web client time out(%i)\r\n", sn );
             }

         break;

      case SOCK_CLOSED:
         if((ret=socket(sn, Sn_MR_TCP, port, 0x00)) != sn)

           MBS_DEBUG( DBG_MASK_APP,
                      "$ APP - Web client socket(%i)\r\n", sn );
         break;

      default:
         break;
   }
}

}

You try to connect to HTTPS port (I assume it is 443), from port 80. It may be that

  • port 443 is blocked for routing;
  • your server does not respond on port 443;
  • your server does not accept secure connections from port 80.

HTTPS is just a acronym i.e. HTTP (S)ERVER the port number is 80.

it works very intermittently, maybe once every 15 tries

Use Wireshark (in the best case installed on the server being connected to) to see what is going on the network interface and what packets are travelling from and to the W5500 - when it succeeds and when it is not.

Already using packetyzer on the server, got a filter in port 80.

The analsyer captures nothing below is my debug output from the software

Version 1.00 - xx-08-2017
Build time: Sep 5 2017 - 17:01:07

ch>
MAC - ADDR[54:10:EC:28:98:6C] NET - Network Initalisation Valid
APP - Server(www.mbsdemo.co.uk) NET - ADDR[192.168.1.51]
NET - SUBN[255.255.255.0] NET - GATW[192.168.1.254]
NET - MAC[54:10:EC:28:98:6C] NET - Network Link[UP]
APP - Link Setup[HARD] APP - Link Mode[AUTO]
APP - Link Speed[10] APP - Link Duplex[HALF]
APP - Web client socket(1) APP - Web client connecting(1)
APP - Web client socket(1) APP - Web client connecting(1)
APP - WatchDog timeout(1) APP - Web client timeout(1)
APP - Web client socket(1) APP - Web client connecting(1)

Right ive got it working why it needs this maybe someone can explain.

when doing ret = socket(sn, Sn_MR_TCP, any_port++, 0x00);

the any port must change, and it seems it must be over 50000 ?

It seems that server is on the same subnet as your W5500 device, it simplifies the troubleshooting.

Remove port 80 filtering, just leave W5500 IP address filtering so that you can see also broadcast packets generated by the W5500. Is there anything from W5500 on the network when it configures and tries to connect?

as i’m using an rtos is there anything i need to call in the back ground timers etc … i noted that in DNS.c there is a call DNS_time_handler(void) ?

But saying this the dns always resolves the url.

The only issue is intermittent connect(sn, domain_addr, PORT_HTTP);

Sometimes it works ok and others it doesn’t. Heres my debug output

$ HTT - Web client socket(1)

$ HTT - DNS Server : 8.8.8.8

$ HTT - Resolve : www.mbsdemo.co.uk

$ HTT - Resolved to 217.160.231.5

$ HTT - Web client connecting(1)

$ HTT - Web client timeout(1)

$ HTT - Web client socket(1)

$ HTT - DNS Server : 8.8.8.8

$ HTT - Resolve : www.mbsdemo.co.uk

$ HTT - Resolved to 217.160.231.5

$ HTT - Web client connecting(1)

Did you perform Wireshark logging? What is in the log? Where’s the log? What it contains?

Next step would be dumping all the registers of the socket and seeing values they contain. Dig into the W5500 libraries and header files to find out the function name to read socket registers.

It works, but the first connection attempt will always fail. After this it will connect and send data for ever more.

So its something like the first fail, resets something… and this then allows it to work ok.

You do not give much diagnostic information, and also give contradicting problem description information.

then

and then

So initially connect did not not work at all, then connecting problem becomes intermittent, and in your last message it is only first connect that fails.

How do you think it is possible to deal with your problem scientifically?

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.