ESP8266 Developer Zone The Official ESP8266 Forum 2016-01-11T16:37:28+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1130 2016-01-11T16:37:28+08:00 2016-01-11T16:37:28+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=5335#p5335 <![CDATA[Re: espconn_get_connection_info()]]>
Sorry for the inconvenience, there are some examples on BBS maybe you can refer to.

UDP demo :http://bbs.espressif.com/viewtopic.php?f=31&t=440
TCP server with multiple connections: http://bbs.espressif.com/viewtopic.php?f=31&t=763.

We will also add it in the documentation.
Thanks for your interest in ESP8266 !

Statistics: Posted by ESP_Faye — Mon Jan 11, 2016 4:37 pm


]]>
2016-01-07T06:36:11+08:00 2016-01-07T06:36:11+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=5286#p5286 <![CDATA[Re: espconn_get_connection_info()]]>
You now have to use the undocumented espconn_get_connection_info function to find out the remote IP address and port of received data. E.g.

Code:

static void socketRecvCB(void *arg, char *usrdata, unsigned short len)
{
  struct espconn* src = (struct espconn*)arg;
 
  remot_info *remote = NULL;
  sint8 err;
  err = espconn_get_connection_info(src,&remote,0);


It's not clear how this would work with multiple connections either.

Espressif, this is a major bug which breaks any code implementing a UDP server. Please fix the API and / or document the espconn_get_connection_info function properly ASAP.

Statistics: Posted by Anki — Thu Jan 07, 2016 6:36 am


]]>
2015-11-24T16:21:46+08:00 2015-11-24T16:21:46+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4744#p4744 <![CDATA[Re: espconn_get_connection_info()]]> viewtopic.php?f=46&t=1268

Statistics: Posted by lobaro — Tue Nov 24, 2015 4:21 pm


]]>
2015-11-23T01:20:53+08:00 2015-11-23T01:20:53+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4707#p4707 <![CDATA[Re: espconn_get_connection_info()]]>
we are developing uPanel, a new firmware for ESP8266 that permits to control any micro-controller (such that of Arduino) through Smart-Phones by means of customisable graphical interfaces (but without the need to write the phone App).

Testing the ESP8266 SDK we found the same problem with the function espconn_get_connection_info(), so we decided to dig a little...

The problem arises from the fact that this function actually returns (a pointer to) an array of "remot_info", with one element for each created UDP socket. This means that if you have only one UDP socket, the returned parameters are correct, but if you have more than one, the returned parameters contained into the first array position are related to the first created socket (temporally first). Therefore, you should examine all the array: the parameter (espconn)->link_cnt will tell you how many elements are present into the returned array remot_info.

Unfortunately, there is no way to find out which is the array element related to the current UDP (we didn't find one...).

Digging into the old sdk code (0.9.4), the espconn_get_connection_info function contains the following code:

case ESPCONN_UDP:
while(plist != NULL){
if (plist->pespconn->type == ESPCONN_UDP){
premot[pespconn->link_cnt].state = plist->pespconn->state;
premot[pespconn->link_cnt].remote_port = plist->pcommon.remote_port;
os_memcpy(premot[pespconn->link_cnt].remote_ip, plist->pcommon.remote_ip, 4);
pespconn->link_cnt ++;
}
plist = plist->pnext;
}

Dear Espressif team, we suggest the following change to the if condition:

if ((plist->pespconn->type == ESPCONN_UDP) && (plist->pespconn == pespconn))

This would return the info only of the wanted UDP socket.

In our tests, we solved this issue creating our function espconn_get_connection_info using the suggested change.

If someone is interested in the source code, let us know by email.

Project website: http://www.miuPanel.com

Regards,
miuPanel Team

Statistics: Posted by Simon — Mon Nov 23, 2015 1:20 am


]]>
2015-11-18T13:42:11+08:00 2015-11-18T13:42:11+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4645#p4645 <![CDATA[Re: espconn_get_connection_info()]]>
Here is my test code, please have a try.
UDP_test_bin.zip

Statistics: Posted by ESP_Faye — Wed Nov 18, 2015 1:42 pm


]]>
2015-11-13T23:30:39+08:00 2015-11-13T23:30:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4576#p4576 <![CDATA[Re: espconn_get_connection_info()]]> had the same issue! But found a "solution"...

In the receive callback of an udp socket we called "espconn_get_connection_info()" and got only 0.0.0.0:0 for ip and port information of the remote sender. The actual data (pData) und length (len) were ok and valid! After doing some trial and error tests we figured out that opening an (different, 2nd) udp socket in "user_init()" makes the difference between valid remote sender information in the callback (of the udp socket created not in user_init) and the 0.0.0.0:0 error behavior:

in user_init():
[...]

Code:

   Conn.type = ESPCONN_UDP;
   Conn.state = ESPCONN_NONE;
   Conn.proto.udp = &UdpConn;
   uint32_t ip =  ipaddr_addr("192.168.1.77");
   Conn.proto.udp->local_port = espconn_port();
   Conn.proto.udp->remote_port = UDP_SERVER_PORT;
   os_memcpy(Conn.proto.udp->remote_ip, &ip, 4);

   sint8 statusCreate = espconn_create(&Conn); //<---- comment this out and no error!


@Espressif
Do you have an idea why this error occurs when calling espconn_create in user_init()?
Thanks!

Tobi

Statistics: Posted by lobaro — Fri Nov 13, 2015 11:30 pm


]]>
2015-11-13T22:36:03+08:00 2015-11-13T22:36:03+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4573#p4573 <![CDATA[Re: espconn_get_connection_info()]]>
bojanpotocnik wrote:
Hello,

function espconn_get_connection_info(), called in UDP Data Received Callback always returns remote_ip as 0.0.0.0. How to get around that, how to know remote IP of the sender of UDP data?

Regards,
Bojan

Code:

static void ICACHE_FLASH_ATTR
uart_server_Data_Received_Callback(void *arg, char *pdata, unsigned short len)
{
   struct espconn* conn = (struct espconn*)arg;

   dprintf(DEBUG_INFO, "Server received %d bytes\r\n", len);

   /* Parameters remote_ip and REMOTE_PORT in it are the remote IP and Port set by espconn_create.
    * If users want to obtain IP and ports of the current sender, please
    * call espconn_get_connection_info relevant to get information. */
   if(conn->type == ESPCONN_UDP) {
      remot_info *remote = NULL;
      if(espconn_get_connection_info(conn, &remote, 0) == 0) {
         dprintf(DEBUG_WARNING, "Remote IP: " IPSTR "\r\n", IP2STR(remote->remote_ip));
      }
      else {
         dprintf(DEBUG_WARNING, "Cannot get sender IP\r\n");
      }
   }
   else {
      dprintfnp(DEBUG_INFO, "from " IPSTR ":%d ", IP2STR(conn->proto.tcp->remote_ip), conn->proto.tcp->remote_port);
   }
}


Server received 9 bytes
Remote IP: 0.0.0.0


Did you solve this by now? I have exactly the same problem.

Using Non-OS SDK 1.4 and calling espconn_get_connection_info in receive callback of an udp socket...
The remote ip&port are zero, but pData and len are finde/correct.

Statistics: Posted by lobaro — Fri Nov 13, 2015 10:36 pm


]]>
2015-10-08T17:12:47+08:00 2015-10-08T17:12:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=4013#p4013 <![CDATA[Re: espconn_get_connection_info()]]>
Sorry that we can not duplicate your problem.

Please provide your test code, we will have a try.

Thanks for your interest in ESP8266 !

Statistics: Posted by ESP_Faye — Thu Oct 08, 2015 5:12 pm


]]>
2015-10-05T20:23:10+08:00 2015-10-05T20:23:10+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=3988#p3988 <![CDATA[Re: espconn_get_connection_info()]]>

Statistics: Posted by bojanpotocnik — Mon Oct 05, 2015 8:23 pm


]]>
2015-10-05T17:15:49+08:00 2015-10-05T17:15:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=3985#p3985 <![CDATA[Re: espconn_get_connection_info()]]>
function espconn_get_connection_info(), called in UDP Data Received Callback always returns remote_ip as 0.0.0.0. How to get around that, how to know remote IP of the sender of UDP data?

Regards,
Bojan

Code:

static void ICACHE_FLASH_ATTR
uart_server_Data_Received_Callback(void *arg, char *pdata, unsigned short len)
{
   struct espconn* conn = (struct espconn*)arg;

   dprintf(DEBUG_INFO, "Server received %d bytes\r\n", len);

   /* Parameters remote_ip and REMOTE_PORT in it are the remote IP and Port set by espconn_create.
    * If users want to obtain IP and ports of the current sender, please
    * call espconn_get_connection_info relevant to get information. */
   if(conn->type == ESPCONN_UDP) {
      remot_info *remote = NULL;
      if(espconn_get_connection_info(conn, &remote, 0) == 0) {
         dprintf(DEBUG_WARNING, "Remote IP: " IPSTR "\r\n", IP2STR(remote->remote_ip));
      }
      else {
         dprintf(DEBUG_WARNING, "Cannot get sender IP\r\n");
      }
   }
   else {
      dprintfnp(DEBUG_INFO, "from " IPSTR ":%d ", IP2STR(conn->proto.tcp->remote_ip), conn->proto.tcp->remote_port);
   }
}



Server received 9 bytes
Remote IP: 0.0.0.0

Statistics: Posted by bojanpotocnik — Mon Oct 05, 2015 5:15 pm


]]>
2015-09-19T21:35:51+08:00 2015-09-19T21:35:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1130&p=3767#p3767 <![CDATA[espconn_get_connection_info()]]>

I am trying to use this function to get IP address of sender's but have had no success.
I use:

remot_info *pinfo = NULL;
espconn_get_connection_info(esp_conn, &pinfo , 0);


Then print:

os_printf("Remote IP address: %u\n", pinfo.remote_ip);


And get 1073675224, which do not correspond to sender´s IP (in my case, 192.168.1.65 = 1090627776).

Also tried:

inti = 0;
while(i <= 100) {
os_printf("Remote IP address: %u\n", pinfo[i].remote_ip);
i++;
};

And got numbers in the same range as above 1073675224, increasing in 12 (1073675224, 1073675248, 1073675260, etc.)

What is the meaning of link_cnt??
How can i find the sender's IP address??


Please provide some insight. Thanks in advance!!


Horacio

Statistics: Posted by hdrut — Sat Sep 19, 2015 9:35 pm


]]>