/*JSON{ "type" : "staticmethod", "class" : "ESP8266WiFi", "name" : "getState", "generate" : "jswrap_ESP8266WiFi_getState", "return" : ["JsVar","The state of the ESP8266"], "return_object" : "ESP8266State" }*/ JsVar *jswrap_ESP8266WiFi_getState() { // Create a new variable and populate it with the properties of the ESP8266 that we // wish to return. JsVar *esp8266State = jspNewObject(NULL, "ESP8266State"); jsvUnLock(jsvObjectSetChild(esp8266State, "sdkVersion", jsvNewFromString(system_get_sdk_version()))); jsvUnLock(jsvObjectSetChild(esp8266State, "cpuFrequency", jsvNewFromInteger(system_get_cpu_freq()))); jsvUnLock(jsvObjectSetChild(esp8266State, "freeHeap", jsvNewFromInteger(system_get_free_heap_size()))); jsvUnLock(jsvObjectSetChild(esp8266State, "maxCon", jsvNewFromInteger(espconn_tcp_get_max_con()))); return esp8266State; }
/****************************************************************************** * FunctionName : espconn_connect * Description : The function given as the connect * Parameters : espconn -- the espconn used to listen the connection * Returns : none *******************************************************************************/ sint8 ICACHE_FLASH_ATTR espconn_connect(struct espconn *espconn) { ip_addr_t ipaddr; tcpip_adapter_ip_info_t ipinfo; uint8 connect_status = 0; sint8 value = ESPCONN_OK; espconn_msg *plist = NULL; // remot_info *pinfo = NULL; if (espconn == NULL) { return ESPCONN_ARG; } else if (espconn ->type != ESPCONN_TCP) return ESPCONN_ARG; /*Check the active node count whether is the limit or not*/ if (espconn_get_acticve_num(ESPCONN_TCP) >= espconn_tcp_get_max_con()) { printf("espconn_tcp_get_max_con \n"); return ESPCONN_ISCONN; } /*Check the IP address whether is zero or not in different mode*/ esp_wifi_get_mode((wifi_mode_t*)&value); if (value == WIFI_MODE_STA){ wifi_get_ip_info(TCPIP_ADAPTER_IF_STA,&ipinfo); if (ipinfo.ip.addr == 0){ return ESPCONN_RTE; } } else if(value == WIFI_MODE_AP){ wifi_get_ip_info(TCPIP_ADAPTER_IF_AP,&ipinfo); if (ipinfo.ip.addr == 0){ return ESPCONN_RTE; } } else if(value == WIFI_MODE_APSTA){ IP4_ADDR(&ipaddr.u_addr.ip4, espconn->proto.tcp->remote_ip[0], espconn->proto.tcp->remote_ip[1], espconn->proto.tcp->remote_ip[2], espconn->proto.tcp->remote_ip[3]); ipaddr.u_addr.ip4.addr <<= 8; wifi_get_ip_info(TCPIP_ADAPTER_IF_AP,&ipinfo); ipinfo.ip.addr <<= 8; // espconn_printf("softap_addr = %x, remote_addr = %x\n", ipinfo.ip.addr, ipaddr.u_addr.ip4.addr); if (ipaddr.u_addr.ip4.addr != ipinfo.ip.addr){ connect_status = wifi_station_get_connect_status(); if (connect_status == SYSTEM_EVENT_STA_GOT_IP){ wifi_get_ip_info(TCPIP_ADAPTER_IF_STA,&ipinfo); // espconn_printf("wifi_get_ip_info:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n", // IP2STR(&ipinfo.ip), IP2STR(&ipinfo.netmask), IP2STR(&ipinfo.gw)); if (ipinfo.ip.addr == 0) return ESPCONN_RTE; } else if (connect_status != SYSTEM_EVENT_STA_GOT_IP){ return ESPCONN_RTE; } else { return connect_status; } } } /*check the active node information whether is the same as the entity or not*/ for (plist = plink_active; plist != NULL; plist = plist->pnext){ if (plist->pespconn && plist->pespconn->type == ESPCONN_TCP){ if (espconn->proto.tcp->local_port == plist->pespconn->proto.tcp->local_port){ return ESPCONN_ISCONN; } } } espconn_set_opt(espconn, ESPCONN_COPY|ESPCONN_NODELAY); value = espconn_tcp_client(espconn); espconn_printf("espconn_connect err value %d \n",value); return value; }
/****************************************************************************** * FunctionName : espconn_connect * Description : The function given as the connect * Parameters : espconn -- the espconn used to listen the connection * Returns : none *******************************************************************************/ sint8 ICACHE_FLASH_ATTR espconn_connect(struct espconn *espconn) { struct ip_addr ipaddr; struct ip_info ipinfo; uint8 connect_status = 0; sint8 value = ESPCONN_OK; espconn_msg *plist = NULL; remot_info *pinfo = NULL; if (espconn == NULL) { return ESPCONN_ARG; } else if (espconn ->type != ESPCONN_TCP) return ESPCONN_ARG; /*Check the active node count whether is the limit or not*/ if (espconn_get_acticve_num(ESPCONN_TCP) >= espconn_tcp_get_max_con()) return ESPCONN_ISCONN; /*Check the IP address whether is zero or not in different mode*/ if (wifi_get_opmode() == ESPCONN_STA) { wifi_get_ip_info(STA_NETIF,&ipinfo); if (ipinfo.ip.addr == 0) { return ESPCONN_RTE; } } else if(wifi_get_opmode() == ESPCONN_AP) { wifi_get_ip_info(AP_NETIF,&ipinfo); if (ipinfo.ip.addr == 0) { return ESPCONN_RTE; } } else if(wifi_get_opmode() == ESPCONN_AP_STA) { IP4_ADDR(&ipaddr, espconn->proto.tcp->remote_ip[0], espconn->proto.tcp->remote_ip[1], espconn->proto.tcp->remote_ip[2], espconn->proto.tcp->remote_ip[3]); ipaddr.addr <<= 8; wifi_get_ip_info(AP_NETIF,&ipinfo); ipinfo.ip.addr <<= 8; espconn_printf("softap_addr = %x, remote_addr = %x\n", ipinfo.ip.addr, ipaddr.addr); if (ipaddr.addr != ipinfo.ip.addr) { connect_status = wifi_station_get_connect_status(); if (connect_status == STATION_GOT_IP) { wifi_get_ip_info(STA_NETIF,&ipinfo); if (ipinfo.ip.addr == 0) return ESPCONN_RTE; } else if (connect_status == STATION_IDLE) { return ESPCONN_RTE; } else { return connect_status; } } } /*check the active node information whether is the same as the entity or not*/ for (plist = plink_active; plist != NULL; plist = plist->pnext) { if (plist->pespconn && plist->pespconn->type == ESPCONN_TCP) { if (espconn->proto.tcp->local_port == plist->pespconn->proto.tcp->local_port) { return ESPCONN_ISCONN; } } } value = espconn_tcp_client(espconn); return value; }
/** @brief main() Initialize user task @return void */ MEMSPACE void setup(void) { int i; char time[20]; int ret; uint16_t *ptr; double ang; extern web_init(); int w,h; ip_msg[0] = 0; // CPU // 160MHZ REG_SET_BIT(0x3ff00014, BIT(0)); // 80MHZ // REG_CLR_BIT(0x3ff00014, BIT(0)); os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle // Configure the UART //uart_init(BIT_RATE_115200,BIT_RATE_115200); uart_init(BIT_RATE_74880,BIT_RATE_74880); os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle printf("\n\n\n\n"); sep(); printf("System init...\n"); printf("ESP8266 multidevice project\n"); printf(" (c) 2014-2017 by Mike Gore\n"); printf(" GNU version 3\n"); printf("-> https://github.com/magore/esp8266_ili9341\n"); printf(" GIT last pushed: %s\n", GIT_VERSION); printf(" Last updated file: %s\n", LOCAL_MOD); sep(); PrintRam(); sep(); printf("HSPI init...\n"); hspi_init(1,0); printf("Timers init...\n"); init_timers(); // 1000HZ timer ms_init(); test_types(); // Functions manage user defined address pins chip_addr_init(); initialize_clock(300); #ifdef ADF4351 #ifdef ADF4351_CS chip_select_init(ADF4351_CS); #endif ADF4351_Init(); printf("ADF4351 init done\n"); #endif // Make sure all other GPIO pins are initialized BEFORE SD card #ifdef FATFS_SUPPORT sep(); // Functions manage chip selects #ifdef MMC_CS chip_select_init(MMC_CS); #endif printf("SD Card init...\n"); mmc_init(1); #endif #ifdef DISPLAY sep(); #ifdef ILI9341_CS chip_select_init(ILI9341_CS); #endif #ifdef XPT2046_CS XPT2046_spi_init(); #endif // Initialize TFT master = tft_init(); tft_calX = MatRead("/tft_calX"); tft_calY = MatRead("/tft_calY"); if(tft_calX.data == NULL || tft_calY.data == NULL) tft_is_calibrated = 0; else tft_is_calibrated = 1; printf("TFT calibration %s\n", tft_is_calibrated ? "YES" : "NO"); // rotateion = 1, debug = 1 setup_windows(1,1); #endif wdt_reset(); sep(); printf("Setup Tasks\n"); sep(); setup_networking(); #ifdef TELNET_SERIAL printf("Setup Network Serial Bridge\n"); bridge_task_init(23); #endif if ( espconn_tcp_set_max_con(MAX_CONNECTIONS+1) ) printf("espconn_tcp_set_max_con(%d) != (%d) - failed!\n", MAX_CONNECTIONS+1, espconn_tcp_get_max_con()); else printf("espconn_tcp_set_max_con(%d) = (%d) - success!\n", MAX_CONNECTIONS+1, espconn_tcp_get_max_con()); #ifdef NETWORK_TEST printf("Setup Network TFT Display Client\n"); servertest_setup(TCP_PORT); #endif #ifdef WEBSERVER printf("Setup Network WEB SERVER\n"); web_init(80); #endif sep(); PrintRam(); system_set_os_print(0); } //setup()