void ESP8266WiFiClass::beginSmartConfig() { if (_smartConfigStarted) return; if(_useApMode) { // turn on AP+STA mode mode(WIFI_AP_STA); } else { // turn on STA mode mode(WIFI_STA); } _smartConfigStarted = true; _smartConfigDone = false; //SC_TYPE_ESPTOUCH use ESPTOUCH for smartconfig, or use SC_TYPE_AIRKISS for AIRKISS smartconfig_start(reinterpret_cast<sc_callback_t>(&ESP8266WiFiClass::_smartConfigCallback), 1); }
void ICACHE_FLASH_ATTR cos_check_ip() { struct ip_info ipconfig; static bool smartconfig_started = false; os_timer_disarm(&client_timer); wifi_get_ip_info(STATION_IF, &ipconfig); if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) { // connect to router success // TODO: notify the cloud I'm online // cloud return the bind state // start broadcast airkiss-nff udp pkg airkiss_nff_start(); smartconfig_started = false; } else { // idle or connecting os_timer_setfn(&client_timer, (os_timer_func_t *)cos_check_ip, NULL); os_timer_arm(&client_timer, 100, 0); if (check_ip_count++ > 50) { // delay 10s, need to start airkiss to reconfig the network // TODO: flash led to show wifi disconnect if(!smartconfig_started) { smartconfig_set_type(SC_TYPE_AIRKISS); wifi_set_opmode(STATION_MODE); smartconfig_start(smartconfig_done); // set smartconfig flag to prevent start again smartconfig_started = true; } // reset the count check_ip_count = 0; } } }
/****************************************************************************** * FunctionName : esptouch_FlowStart * Description : Set esp-touch callback and start esp-touch *******************************************************************************/ void ICACHE_FLASH_ATTR esptouch_FlowStart() { wifi_station_disconnect(); #if ESP_NOW_SUPPORT light_EspnowDeinit(); #endif WIFI_StopCheckIp(); //esptouch_setAckFlag(true); SC_INFO("ESP-TOUCH FLOW INIT...\r\n"); esptouch_proc.esptouch_fail_cb = esptouch_FailCb; esptouch_proc.esptouch_start_cb = esptouch_StartCb; esptouch_proc.esptouch_suc_cb = esptouch_SuccessCb; esptouch_proc.esptouch_type = SC_TYPE_ESPTOUCH; SC_INFO("ESP-TOUCH SET STATION MODE ...\r\n"); wifi_set_opmode(STATION_MODE); if(esptouch_proc.esptouch_fail_cb){ os_timer_disarm(&esptouch_tout_t); os_timer_setfn(&esptouch_tout_t,esptouch_proc.esptouch_fail_cb,NULL); os_timer_arm(&esptouch_tout_t,ESP_TOUCH_TIME_ENTER,0); } if(esptouch_cnt>=2){ SC_INFO("ALREADY DID ESPTOUCH %d TIMES\r\n",ESP_TOUCH_TIME_LIMIT); esptouch_setAckFlag(true); //stop getting into esptouch mode if(esptouch_proc.esptouch_fail_cb) esptouch_proc.esptouch_fail_cb(NULL); return; } esptouch_cnt += 1; SC_INFO("ESP-TOUCH START"); smartconfig_start(esptouch_ProcCb); }
// Lua: smart(channel, function succeed_cb) // Lua: smart(type, function succeed_cb) static int wifi_start_smart( lua_State* L ) { #if defined( NODE_SMART_OLDSTYLE ) unsigned channel; int stack = 1; if ( lua_isnumber(L, stack) ){ channel = lua_tointeger(L, stack); stack++; } else { channel = 6; } // luaL_checkanyfunction(L, stack); if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION){ lua_pushvalue(L, stack); // copy argument (func) to the top of stack if(wifi_smart_succeed != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, wifi_smart_succeed); wifi_smart_succeed = luaL_ref(L, LUA_REGISTRYINDEX); } if ( channel > 14 || channel < 1 ) return luaL_error( L, "wrong arg range" ); if(wifi_smart_succeed == LUA_NOREF){ smart_begin(channel, NULL, NULL); }else{ smart_begin(channel, (smart_succeed )wifi_smart_succeed_cb, L); } #else if(wifi_get_opmode() != STATION_MODE) { return luaL_error( L, "Smart link only in STATION mode" ); } uint8_t smart_type = 0; int stack = 1; smart_L = L; if ( lua_isnumber(L, stack) ) { smart_type = lua_tointeger(L, stack); stack++; } if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION) { lua_pushvalue(L, stack); // copy argument (func) to the top of stack if(wifi_smart_succeed != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, wifi_smart_succeed); wifi_smart_succeed = luaL_ref(L, LUA_REGISTRYINDEX); } if ( smart_type > 1 ) return luaL_error( L, "wrong arg range" ); smartconfig_start(smart_type, wifi_smart_succeed_cb); #endif // defined( NODE_SMART_OLDSTYLE ) return 0; }
/** * smart-config task */ void ICACHE_FLASH_ATTR smartconfig_task(void *pvParameters) { smartconfig_start(smartconfig_callback); vTaskDelete(NULL); }
void smartconfig_task(void *pvParameters) { smartconfig_start(smartconfig_done); vTaskDelete(NULL); }
void user_init(void) { os_printf("SDK version:%s\n", system_get_sdk_version()); smartconfig_start(SC_TYPE_AIRKISS, smartconfig_done); }