Statistics: Posted by muris — Sat Nov 08, 2014 4:35 pm
Statistics: Posted by muris — Fri Nov 07, 2014 1:04 am
Statistics: Posted by muris — Thu Nov 06, 2014 3:47 am
Statistics: Posted by muris — Wed Nov 05, 2014 8:34 pm
Statistics: Posted by jackon — Wed Nov 05, 2014 8:13 pm
Code:
espconn_disconnect(ctrlConn);
os_free(ctrlConn); // new line of code
Statistics: Posted by muris — Wed Nov 05, 2014 7:46 pm
Statistics: Posted by jackon — Wed Nov 05, 2014 7:14 pm
Code:
struct espconn *ctrlConn; // global variable holding connection
// creates a TCP connection and starts connecting
static void ICACHE_FLASH_ATTR tcp_connection_create(void)
{
enum espconn_type linkType = ESPCONN_TCP;
ctrlConn = (struct espconn *)os_zalloc(sizeof(struct espconn));
ctrlConn->type = linkType;
ctrlConn->state = ESPCONN_NONE;
ctrlConn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
ctrlConn->proto.tcp->local_port = espconn_port();
ctrlConn->proto.tcp->remote_port = ctrlSetup.serverPort;
os_memcpy(ctrlConn->proto.tcp->remote_ip, ctrlSetup.serverIp, 4);
ctrlConn->reverse = NULL; // I don't need this, right?
espconn_regist_connectcb(ctrlConn, tcpclient_connect_cb);
espconn_regist_reconcb(ctrlConn, tcpclient_recon_cb);
espconn_connect(ctrlConn);
uart0_sendStr("TCP connection created.\r\n");
}
Code:
// closes and destroys current connection
static void ICACHE_FLASH_ATTR tcp_connection_destroy(void)
{
uart0_sendStr("tcp_connection_destroy()\r\n");
ctrlState &= ~CTRL_STATE_AUTHENTICATED; // my custom variables
connState = CTRL_TCP_DISCONNECTED; // my custom variables
espconn_disconnect(ctrlConn); // this will os_free() my ctrlConn so I can create it again by calling tcp_connection_create(); when WIFI gets IP again
}
Statistics: Posted by muris — Wed Nov 05, 2014 2:29 am