2018-03-28 01:03 AM
Hello every body im using lwip netconn tcp protocol, to send and recieve data , i have a question ,
when i connect my board ethernet cable it send and receive but when i take the cable and put back i loose my connection naturally which is normal because we need application to always research and scan if there is a connection to not make reset manually and loose data , here is my code :
void StartDefaultTask(void const * argument)
{//struct netconn *conn, *newconn;err_t err, accept_err;struct netbuf *buf;void *data;//char *data=pvPortMalloc(2048);//char data[100]; err_t recv_err;uint16_t len=0;ip_addr_t local_ip;//stm32ip_addr_t remote_ip;//pc hostuint8_t i=0;/* init code for LWIP */
MX_LWIP_Init();/* USER CODE BEGIN 5 */
printf('ETHERNET STM32F429ZI lwip init complete\r\n'); char * buffer=pvPortMalloc(100);while(gnetif.ip_addr.addr==0) osDelay(1);//wait the ip to reach the structure
printf('OUR Static ip adress:%s\r\n',ip4addr_ntoa(&gnetif.ip_addr));local_ip =gnetif.ip_addr;ip4addr_aton ('10.1.1.3',&remote_ip);LWIP_UNUSED_ARG(conn); //---------------------------------------Server---------------------------------------------// conn=netconn_new(NETCONN_TCP);//create new network connection TCP TYPE if (conn!=NULL) {//new /* Bind connection to well known port number 23 */ err = netconn_bind(conn,&local_ip,23);if (err == ERR_OK)
{ /* Tell connection to go into listening mode. */ netconn_listen(conn); /* Infinite loop */ while (1) { /* Grab new connection. */ accept_err = netconn_accept(conn, &newconn);/* Process the new connection. */
if (accept_err == ERR_OK)/* block until we get an incoming connection */ { while (( recv_err = netconn_recv(newconn, &buf)) == ERR_OK) {//receive do { netbuf_data(buf, &data, &len); // netbuf_copy(buf,data,len);//not trustable much len=netbuf_len(buf); printf('Received %d bytes:\r\n %s\r\n',len,data); // printf('Received %d bytes:\r\n',len);// for (i=0;i<len;i++)// {// printf('%c',data[i]);// } sprintf(buffer,'ack from stm\n\r'); netconn_write(newconn,buffer,strlen(buffer),NETCONN_COPY);//send ack //netconn_write(newconn, data, len, NETCONN_COPY);//send same msg to client HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);//blink a led to check if the prgm is keeping running } while (netbuf_next(buf) >= 0); netbuf_delete(buf);//delete the recieved data }/* Close connection and discard connection identifier. */
// netconn_close(newconn);// netconn_delete(newconn); }//accept}//while1
}//listen else {//bind netconn_delete(newconn); printf(' can not bind TCP netconn'); } } else//new { printf('can not create TCP netconn'); }can i put this part inside of while 1 loop to check always new connection
LWIP_UNUSED_ARG(conn);
//---------------------------------------Server---------------------------------------------//conn=netconn_new(NETCONN_TCP);//create new network connection TCP TYPEif (conn!=NULL){//new/* Bind connection to well known port number 23 */err = netconn_bind(conn,&local_ip,23);if (err == ERR_OK)
{/* Tell connection to go into listening mode. */netconn_listen(conn);thanks
2018-03-28 02:53 AM
You have to poll the PHY periodically to find out whether you have connection or not. The details depend on your particular setup - whether you have PHY IRQ or not, whether you run multitasking, etc. Search this forum for 'ETH poll PHY' or similar.
JW