void ICACHE_FLASH_ATTR esp8266_resolveCallback(const char* name, ip_addr_t* ip, void* arg)
{
    
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;
    uart0_tx_buffer("get conn\r\n", 10);
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(netConn);

    uart0_tx_buffer("check ip\r\n", 10);
    if(!ip)
    { // failed to lookup the hostname
        uart0_tx_buffer("bad ip\r\n", 8);
        esp8266_destroyConnection(netConn);
        netConn->readCallback(netConn->userData, NULL, 0, net_error);
        return;
    }

    char pageBuffer[20];
    ets_sprintf(pageBuffer, "r: %d.%d.%d.%d\r\n", IP2STR(ip));
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

    uart0_tx_buffer("set tcp callbacks\r\n", 19);
    espconn_regist_connectcb(conn, esp8266_connectCallback);
    espconn_regist_disconcb(conn, esp8266_disconnectCallback);
    espconn_regist_reconcb(conn, esp8266_reconnectCallback);
    uart0_tx_buffer("set callbacks\r\n", 15);
    espconn_regist_recvcb(conn, esp8266_recvCallback);
    espconn_regist_sentcb(conn, esp8266_sendCallback);

    uart0_tx_buffer("set ip\r\n", 8);
    ets_memcpy(&conn->proto.tcp->remote_ip, ip, 4);
    if(driver->secure)
    {
        uart0_tx_buffer("async sconnect\r\n", 16);
        conn->proto.tcp->remote_port = 443;
        
        ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

        sint8 r = espconn_secure_connect(conn);
        ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    }
    else
    {
        uart0_tx_buffer("async connect\r\n", 15);
        conn->proto.tcp->remote_port = 80;
        
        ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

        sint8 r = espconn_connect(conn);
        ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    }
}
void ICACHE_FLASH_ATTR esp8266_recvCallback(void* arg, char* buffer, unsigned short size)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "rx: %d\r\n", size);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    netConn->readCallback(netConn->userData, buffer, size, net_ok);
}
void ICACHE_FLASH_ATTR esp8266_reconnectCallback(void* arg, sint8 err)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "recon: %d\r\n", err);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    esp8266_destroyConnection(netConn);
    netConn->readCallback(netConn->userData, NULL, 0, net_error);
}