@@1. codes below is to get register set from response of dhcp, also, I copied the mac of my wifi module (wihch driving w5500 through spi, the mac is officially assigned, and wifi module won’t connect any wifi route or switch), so it won’t be a locally admined or multicast, by the way, when first plugging in the cable, it works for a couple of hours with the same mac)
if ((dhcp_ret == DHCP_IP_LEASED) || (dhcp_ret == DHCP_IP_CHANGED)) {
#if USER_DEBUG
os_printf("\nw5500_dhcp_execute2 b\n");
#endif
getIPfromDHCP(gWIZNETINFO.ip);
getGWfromDHCP(gWIZNETINFO.gw);
getSNfromDHCP(gWIZNETINFO.sn);
getDNSfromDHCP(gWIZNETINFO.dns);
gWIZNETINFO.dhcp = NETINFO_DHCP;
ctlnetwork(CN_SET_NETINFO, (void*) &gWIZNETINFO);
display_netinfo();
dhcp_lease_time_rest=getDHCPLeasetime();
@@2. yes, I can find the log in order:
"%d:sock closed1","%d:sock closed2","%d:try to connect to the %d.%d.%d.%d : %d\r\n".
@@3. yes, you can find the any_port++
void ICACHE_FLASH_ATTR w5500_send2()
{
#if USER_DEBUG
os_printf("wa70.");
#endif
os_timer_disarm(&w5500_timer_sending);
if(connected ==0)
return;
if(data_sending==NULL)
return;
// max wait times
static uint8 connectwaittimes=0;
connectwaittimes++;
if(connectwaittimes>30)
{
issending=0;
connectwaittimes=0;
close(SOCK_TCPS);
#if USER_DEBUG
os_printf("wa39.");
#endif
return;
}
int32_t ret;
uint16_t size = 0;
uint16_t any_port = 50000;
uint8 SnSR=getSn_SR(SOCK_TCPS);
#if USER_DEBUG
os_printf("wa71:%x.",SnSR);
#endif
switch(SnSR)
{
case SOCK_ESTABLISHED :
connectwaittimes=0;
#if USER_DEBUG
os_printf("wa0.");
#endif
if(getSn_IR(SOCK_TCPS) & Sn_IR_CON) // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
{
#if USER_DEBUG
os_printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",SOCK_TCPS, server_ip[0], server_ip[1], server_ip[2], server_ip[3], server_port);
#endif
setSn_IR(SOCK_TCPS, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
#if USER_DEBUG
os_printf("wa1.");
#endif
}
#if USER_DEBUG
os_printf("wa2.");
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// Data Transaction Parts; Handle the [data receive and send] process
//////////////////////////////////////////////////////////////////////////////////////////////
if((size = getSn_RX_RSR(SOCK_TCPS)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
{
#if USER_DEBUG
os_printf("wa3.");
#endif
if(size > DATA_BUF_SIZE)
size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
uint8 *rxbuf=(uint8 *)os_zalloc(size);
ret = recv(SOCK_TCPS, rxbuf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
#if USER_DEBUG
os_printf("wa4.");
#endif
if(ret <= 0)
{
os_free(rxbuf);
rxbuf=NULL;
return; // If the received data length <= 0, receive failed and process end
}
#if USER_DEBUG
os_printf("wa5.");
#endif
w5500_receive(rxbuf,ret);
#if USER_DEBUG
os_printf("wa6.");
#endif
}
#if USER_DEBUG
os_printf("wa7.");
#endif
ret = send(SOCK_TCPS, data_sending + data_sending_sent, data_sending_len - data_sending_sent); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
#if USER_DEBUG
os_printf("wa8.");
#endif
if(ret < 0) // Send Error occurred (sent data length < 0)
{
#if USER_DEBUG
os_printf("wa9.");
#endif
issending=0;
close(SOCK_TCPS); // socket close
return;
}
#if USER_DEBUG
os_printf("wa10. %d,%d,%d\r\n",data_sending_len,data_sending_sent,ret);
#endif
data_sending_sent += ret; // Don't care SOCKERR_BUSY, because it is zero.
if (data_sending_len <= data_sending_sent)
{
os_printf("\n\th: %u,l: %u\n",system_get_free_heap_size(),data_sending_len);
data_sending_sent=0;
data_sending_len=0;
os_free(data_sending);
data_sending=NULL;
led_set();
http_upload_times=http_upload_times+1;
http_upload_times_temp=http_upload_times;
receivei=senti;
#if USER_DEBUG
os_printf("wa11.");
#endif
w5500_send();
#if USER_DEBUG
os_printf("wa12.");
#endif
return;
}
#if USER_DEBUG
os_printf("wa13.");
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
break;
case SOCK_CLOSE_WAIT :
#if USER_DEBUG
os_printf("%d:sock close wait\r\n", SOCK_TCPS);
#endif
// if((ret=disconnect(SOCK_TCPS)) != SOCK_OK)
// return ;
#if USER_DEBUG
os_printf("wa30.");
#endif
if(getSn_IR(SOCK_TCPS) & Sn_IR_TIMEOUT)
{
#if USER_DEBUG
os_printf("wa31.");
#endif
setSn_CR(SOCK_TCPS,Sn_CR_CLOSE);
while( getSn_CR(SOCK_TCPS) );
/* clear all interrupt of the socket. */
setSn_IR(SOCK_TCPS, 0xFF);
}else{
#if USER_DEBUG
os_printf("wa32.");
#endif
setSn_CR(SOCK_TCPS,Sn_CR_DISCON);
}
break;
case SOCK_INIT :
#if USER_DEBUG
os_printf("%d:try to connect to the %d.%d.%d.%d : %d\r\n", SOCK_TCPS, server_ip[0], server_ip[1], server_ip[2], server_ip[3], server_port);
os_printf("wa33.");
#endif
if( (ret = connect(SOCK_TCPS, server_ip, server_port)) != SOCK_OK)
{
#if USER_DEBUG
os_printf("wa34.");
#endif
return; // Try to TCP connect to the TCP server (destination)
}
#if USER_DEBUG
os_printf("wa35.");
#endif
break;
case SOCK_CLOSED:
#if USER_DEBUG
os_printf("wa36.");
os_printf("%d:sock closed1.", SOCK_TCPS);
#endif
close(SOCK_TCPS);
#if USER_DEBUG
os_printf("%d:sock closed2.", SOCK_TCPS);
#endif
if((ret=socket(SOCK_TCPS, Sn_MR_TCP, any_port++, 0x00)) != SOCK_TCPS)
{
#if USER_DEBUG
os_printf("wa37.");
#endif
return; // TCP socket open with 'any_port' port number
}
#if USER_DEBUG
os_printf("wa38.");
#endif
break;
default:
break;
}
#if USER_DEBUG
os_printf("wa14:%u.",SnSR);
#endif
os_timer_setfn(&w5500_timer_sending, w5500_send2, NULL);
os_timer_arm(&w5500_timer_sending, 50, 0);
return;
}