void ICACHE_FLASH_ATTR http_raw_request(const char * hostname, int port, const char * path, const char * post_data, http_callback user_callback) { PRINTF("DNS request\n"); request_args * req = (request_args *)os_malloc(sizeof(request_args)); req->hostname = esp_strdup(hostname); req->path = esp_strdup(path); req->port = port; req->post_data = esp_strdup(post_data); req->buffer_size = 1; req->buffer = (char *)os_malloc(1); req->buffer[0] = '\0'; // Empty string. req->user_callback = user_callback; ip_addr_t addr; err_t error = espconn_gethostbyname((struct espconn *)req, // It seems we don't need a real espconn pointer here. hostname, &addr, dns_callback); if (error == ESPCONN_INPROGRESS) { PRINTF("DNS pending\n"); } else if (error == ESPCONN_OK) { // Already in the local names table (or hostname was an IP address), execute the callback ourselves. dns_callback(hostname, &addr, req); } else if (error == ESPCONN_ARG) { os_printf("DNS error %s\n", hostname); } else { os_printf("DNS error code %d\n", error); } }
void FUNCTION_ATTRIBUTE http_raw_request(const char * hostname, int port, const char * path, const char * post_data, http_callback user_callback) { if(http_flag == 1) { PRINTF("http client is running, exit"); return; } http_flag = 1; PRINTF("DNS request\n"); os_timer_disarm(&timeout_timer); os_timer_setfn(&timeout_timer, (os_timer_func_t *)http_exit, HTTP_TIMEOUT); os_timer_arm(&timeout_timer, 20000, 0); http_hostname = my_strdup(hostname); http_path = my_strdup(path); http_port = port; http_post_data = my_strdup(post_data); // respond buf http_buf = (HTTP_BUF*)os_malloc(sizeof(HTTP_BUF)); http_buf->buffer = (char *)os_malloc(1); http_buf->buffer[0] = '\0'; // Empty string. http_buf->buffer_size = 1; user_cb= user_callback; ip_addr_t addr; err_t error = espconn_gethostbyname(NULL, // It seems we don't need a real espconn pointer here. hostname, &addr, dns_callback); if (error == ESPCONN_INPROGRESS) { PRINTF("DNS pending\n"); } else if (error == ESPCONN_OK) { // Already in the local names table (or hostname was an IP address), execute the callback ourselves. dns_callback(hostname, &addr, NULL); } else if (error == ESPCONN_ARG) { PRINTF("DNS error %s\n", hostname); } else { PRINTF("DNS error code %d\n", error); } }