ESP8266 Developer Zone The Official ESP8266 Forum 2016-04-05T10:47:48+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1982 2016-04-05T10:47:48+08:00 2016-04-05T10:47:48+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1982&p=6332#p6332 <![CDATA[Re: Remote IP can't be retrieved using UDP]]>
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 !

Statistics: Posted by ESP_Faye — Tue Apr 05, 2016 10:47 am


]]>
2016-04-03T03:49:58+08:00 2016-04-03T03:49:58+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1982&p=6323#p6323 <![CDATA[Remote IP can't be retrieved using UDP]]>

Code:

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);
}

Statistics: Posted by wsptr — Sun Apr 03, 2016 3:49 am


]]>