Remote IP can't be retrieved using UDP

wsptr
Posts: 11
Joined: Sun Apr 03, 2016 3:40 am

Remote IP can't be retrieved using UDP

Postby wsptr » Sun Apr 03, 2016 3:49 am

I want to send & receive data to/from different hosts via udp. Code is shown as below. I can receiv data, but the remote ip is always wrong, it seems that the remote_ip in arg is never changed. How can I solve this problem?

Code: Select all

struct espconn _Conn;
esp_udp _ConnUdp;

static void ICACHE_FLASH_ATTR UdpDataReceived(void *arg, char* data,uint16_t len)
{
   struct espconn *conn=(struct espconn *)arg;
   char remoteIp[16];
   os_sprintf(remoteIp,IPSTR,conn->proto.udp->remote_ip[0],conn->proto.udp->remote_ip[1],conn->proto.udp->remote_ip[2],conn->proto.udp->remote_ip[3]);
   console_printf("################ %s: Data received from %s:%d:\r\n",localIp,remoteIp,conn->proto.udp->remote_port);
}

static void InitUdp(uint32_t localIp,int localPort)
{
   _Conn.proto.udp=&_ConnUdp;
   _Conn.type=ESPCONN_UDP;                  
   _Conn.state=ESPCONN_NONE;
   os_memcpy(_Conn.proto.udp->local_ip,&localIp,4);
   _Conn.proto.udp->local_port=localPort;

   espconn_regist_recvcb(&_Conn,UdpDataReceived);
   espconn_regist_sentcb(&_Conn,DataSent);
   
   sint8 connStatus =espconn_create(&_Conn);
}


ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: Remote IP can't be retrieved using UDP

Postby ESP_Faye » Tue Apr 05, 2016 10:47 am

Hi,

You need to call espconn_get_connection_info to get the information of remote IP, here is an example: http://bbs.espressif.com/viewtopic.php?f=31&t=440.

Thanks for your interest in ESP8266 !

Who is online

Users browsing this forum: No registered users and 238 guests