espconn_get_connection_info()

muris
Posts: 35
Joined: Fri Oct 24, 2014 7:25 pm
Location: Bosnia-Herzegovina
Contact:

espconn_get_connection_info()

Postby muris » Mon Oct 27, 2014 7:56 pm

Hello,

Is there any example on how to use this function espconn_get_connection_info() ?

I would like to check the state of my connection but when I read description in espconn.h I get another explanation:

Code: Select all

/******************************************************************************
 * FunctionName : espconn_get_connection_info
 * Description  : used to specify the function that should be called when disconnect
 * Parameters   : espconn -- espconn to set the err callback
 *                discon_cb -- err callback function to call when err
 * Returns      : none
*******************************************************************************/

sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags);

It says that this function sets a callback function to be called when connection disconnects?! Do you have a simple example of how this function is actually used?

Is this OK:

Code: Select all

   remot_info *ri = (struct remot_info *)os_zalloc(sizeof(struct remot_info));
   espconn_get_connection_info(myConn, &ri, 0);
   enum espconn_state connInfo = ri->state;

   // connInfo now holds information about myConn connection?

It is a bit difficult to debug so I thought I better ask here before trying when I get home tonight from work.

Thanks!

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Re: espconn_get_connection_info()

Postby costaud » Tue Oct 28, 2014 12:47 am

Code: Select all

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


;)

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

Re: espconn_get_connection_info()

Postby ESP_Faye » Tue Oct 28, 2014 9:08 am

costaud wrote:

Code: Select all

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


;)


Yes, this is right! there is no need to call os_zalloc
and the description is wrong. :oops: . this api is used to get the info of tcp client that connected to ESP8266(which runs as a tcp server).

muris
Posts: 35
Joined: Fri Oct 24, 2014 7:25 pm
Location: Bosnia-Herzegovina
Contact:

Re: espconn_get_connection_info()

Postby muris » Tue Oct 28, 2014 3:36 pm

Ok thanks to both of you :-)

If this is used to get the info of tcp client that is connected to ESP8266 (which runs as a tcp server), is there a command to query the ESP8266 chip and see the status of a socket connection to a cloud server? What I am trying to do is get the status of current socket connection from ESP8266 to the Cloud server. So this function can't be used for that? Is there a different function to use?

I have a situation where ESP8266 is always connected to the cloud server, but sometimes connection breaks. Then I have a timer that checks whether the connection is still active and if not it would start the re-connect process. Is this approach wrong, or can I simply use the callback functions which are called when connection breaks, such as this one:

Code: Select all

espconn_regist_reconcb(ctrlConn, tcpclient_recon_cb);


It seems logical that espconn_get_connection_info() will get the provided espconn's info and set the "state" property to any of:
/** Current state of the espconn. Non-TCP espconn are always in state ESPCONN_NONE! */
enum espconn_state {
ESPCONN_NONE,
ESPCONN_WAIT,
ESPCONN_LISTEN,
ESPCONN_CONNECT,
ESPCONN_WRITE,
ESPCONN_READ,
ESPCONN_CLOSE
};


Thanks :)

muris
Posts: 35
Joined: Fri Oct 24, 2014 7:25 pm
Location: Bosnia-Herzegovina
Contact:

Re: espconn_get_connection_info()

Postby muris » Tue Oct 28, 2014 5:20 pm

I am browsing the espconn.c and espconn_tcp.c files that I found in lwip implementation (app subfolder).
It seems that I don't need to call espconn_get_connection_info() since the "state" property is updated by the functions implemented in lwip portion.

In my app I can simply check myConn->state.

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

Re: espconn_get_connection_info()

Postby ESP_Faye » Thu Oct 30, 2014 9:38 am

There are several callbacks can be used.
espconn_regist_connectcb : register a callback that will be called when connect succeed.
espconn_regist_disconcb: for disconnect
espconn_regist_reconcb: register a reconnect callback which will be called when abnormal disconnection happens or connect fail.
espconn_regist_sentcb: for packet send succeed.
espconn_regist_recvcb: for packet received.

Who is online

Users browsing this forum: No registered users and 219 guests