- /******************************************************************************
- * FunctionName : user_dns_found
- * Description : dns found callback
- * Parameters : name -- pointer to the name that was looked up.
- * ipaddr -- pointer to an ip_addr_t containing the IP address of
- * the hostname, or NULL if the name could not be found (or on any
- * other error).
- * callback_arg -- a user-specified callback argument passed to
- * dns_gethostbyname
- * Returns : none
- *******************************************************************************/
- LOCAL void ICACHE_FLASH_ATTR
- user_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
- {
- struct espconn *pespconn = (struct espconn *)arg;
-
- if (ipaddr == NULL) {
- os_printf("user_dns_found NULL \r\n");
- return;
- }
-
- //dns got ip
- os_printf("user_dns_found %d.%d.%d.%d \r\n",
- *((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr + 1),
- *((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 3));
-
- if (tcp_server_ip.addr == 0 && ipaddr->addr != 0) {
- // dns succeed, create tcp connection
- os_timer_disarm(&test_timer);
- tcp_server_ip.addr = ipaddr->addr;
- os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); // remote ip of tcp server which get by dns
- pespconn->proto.tcp->remote_port = 80; // remote port of tcp server
- pespconn->proto.tcp->local_port = espconn_port(); //local port of ESP8266
-
- espconn_regist_connectcb(pespconn, user_tcp_connect_cb); // register connect callback
- espconn_regist_reconcb(pespconn, user_tcp_recon_cb); // register reconnect callback as error handler
-
- espconn_connect(pespconn); // tcp connect
- }
- }
-
- /******************************************************************************
- * FunctionName : user_esp_platform_dns_check_cb
- * Description : 1s time callback to check dns found
- * Parameters : arg -- Additional argument to pass to the callback function
- * Returns : none
- *******************************************************************************/
- LOCAL void ICACHE_FLASH_ATTR
- user_dns_check_cb(void *arg)
- {
- struct espconn *pespconn = arg;
-
- espconn_gethostbyname(pespconn, NET_DOMAIN, &tcp_server_ip, user_dns_found); // recall DNS function
-
- os_printf("dns_check\n");
- os_timer_arm(&test_timer, 1000, 0);
- }
-
- /******************************************************************************
- * FunctionName : CheckIpStart
- * Description : set the router info which ESP8266 station will connect to
- * Parameters : none
- * Returns : none
- *******************************************************************************/
- void ICACHE_FLASH_ATTR
- CheckIpStart(void)
- {
- // Connect to tcp server as NET_DOMAIN
- user_tcp_conn.proto.tcp = &user_tcp;
- user_tcp_conn.type = ESPCONN_TCP;
- user_tcp_conn.state = ESPCONN_NONE;
- tcp_server_ip.addr = 0;
- espconn_gethostbyname(&user_tcp_conn, NET_DOMAIN, &tcp_server_ip, user_dns_found); // DNS function
-
- os_timer_disarm(&test_timer);
- os_timer_setfn(&test_timer, (os_timer_func_t *)user_dns_check_cb, user_tcp_conn);
- os_timer_arm(&test_timer, 1000, 0);
- }
-
- void ICACHE_FLASH_ATTR
|