Field esp_pcb

amsjunior
Posts: 4
Joined: Wed May 27, 2015 1:02 pm

Field esp_pcb

Postby amsjunior » Wed May 27, 2015 1:05 pm

Hi there,

the struct espconn has the following field:
espconn_handle esp_pcb;

I'm wondering if this field is used internally by the ESP connection management, or if it's a field that I can use to point to my own object, and then retrieve these it from the callbacks.


Thanks!
Antonio.

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

Re: Field esp_pcb

Postby ESP_Faye » Wed May 27, 2015 4:09 pm

Hi,

Do you mean the "typedef void *espconn_handle;" in espconn.h ?

It can be used to point to user's own object, but we recommend to use "struct espconn" .

Here is a demo of TCP connection http://bbs.espressif.com/viewtopic.php?f=21&t=232

amsjunior
Posts: 4
Joined: Wed May 27, 2015 1:02 pm

Re: Field esp_pcb

Postby amsjunior » Thu May 28, 2015 2:19 pm

Thanks Espressif_Faye.

I would like to pass my own object between callbacks. For example:

LOCAL void ICACHE_FLASH_ATTR
user_tcp_connect_cb(void *arg)
{
struct espconn *pespconn = arg;
pespconn->esp_pcb = os_malloc(sizeof(my_custom_type));
espconn_regist_recvcb(pespconn, user_tcp_recv_cb);
}

user_tcp_recv_cb(void *arg, char *pusrdata, unsigned short length)
{
struct espconn *pespconn = arg;
my_custom_type* my = (my_custom_type*) pespconn->esp_pcb;

// Do stuff with object (my)
}


Is that correct? Or is there another recommended way for passing data among callbacks?


Thanks!
Antonio.

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

Re: Field esp_pcb

Postby ESP_Faye » Fri May 29, 2015 9:50 am

Hi,

please refer to this:

Code: Select all

LOCAL void ICACHE_FLASH_ATTR
user_tcp_connect_cb(void *arg)
{
struct espconn *pespconn = arg;
pespconn->reverse = os_malloc(sizeof(my_custom_type));
espconn_regist_recvcb(pespconn, user_tcp_recv_cb);
}

user_tcp_recv_cb(void *arg, char *pusrdata, unsigned short length)
{
struct espconn *pespconn = arg;
my_custom_type* my = (my_custom_type*) pespconn->reverse;

// Do stuff with object (my)
}


Who is online

Users browsing this forum: No registered users and 26 guests