cancel
Showing results for 
Search instead for 
Did you mean: 

how to extract data from ethernet at the reception

TARHAN SAMAH
Senior
Posted on March 28, 2018 at 09:51

Hello im using stm32f429ZI NUCLEO (with server application netconn) , protocol tcp for sending and receiving data using ethernet ,, i can send no prblm , i receive also but i need to save like a serie , i use this server example this way:

void StartDefaultTask(void const * argument)

{

//struct netconn *conn, *newconn;

err_t err, accept_err;

struct netbuf *buf;

void *data;

//char *data=pvPortMalloc(2048);---------->here i confuse which is the right definition of data??????

//char data[100];

err_t recv_err;

uint16_t len=0;

ip_addr_t local_ip;//stm32

ip_addr_t remote_ip;//pc host

uint8_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');

}

}

i need to read this way 

printf('Received %d bytes:\r\n',len);

for (i=0;i<len;i++)

{

printf('%c',data[i]); --------> but this one is not accepted (error of compile) i want to process or extract byte by byte data how should i write it ????

 }

thanks much 

2 REPLIES 2
Tilen MAJERLE
ST Employee
Posted on March 28, 2018 at 10:55

Hello

‌,

void * is special C type and can not be accessed as array. You can set yourdata touint8_t

uint8_t* data = pvPort...(..);�?

Posted on April 05, 2018 at 10:48

tahnks muccccch