/******************************************************************************
 * FunctionName : esptouch_FailCb
 * Description  : esp-touch fail callback
*******************************************************************************/
void ICACHE_FLASH_ATTR
    esptouch_FailCb(void* data)
{   
    wifi_station_disconnect();
    smartconfig_stop();
    //wifi_set_opmode(STATIONAP_MODE);
    
    SC_INFO("ESP-TOUCH FAIL \r\n");
    os_timer_disarm(&esptouch_tout_t);
    #if LIGHT_DEVICE
    light_shadeStart(HINT_RED,2000,0,1,NULL);
    #endif
    
    SC_INFO("ENABLE LIGHT ACTION(ESP-NOW)");
    os_printf("debug: channel:%d\r\n",wifi_get_channel());
#if ESP_NOW_SUPPORT
    light_EspnowInit();
#endif

#if ESP_MESH_SUPPORT
    SC_INFO("RESTART MESH NOW...\r\n");
    #if LIGHT_DEVICE
    light_hint_stop(HINT_RED);
    #endif
    //user_MeshStart();
    wifi_RestartMeshScan(5000);
#else
	SC_INFO("ESP-TOUCH FAIL, OPEN WEBSERVER NOW");
	mesh_SetSoftap();//check
#endif
}
예제 #2
0
bool ICACHE_FLASH_ATTR checkSmartConfig(enum SmartConfigAction action) {
	static doingSmartConfig = false;

	switch (action) {
	case SC_CHECK:
		break;
	case SC_HAS_STOPPED:
		os_printf("Finished smartConfig\n");
		stopFlash();
		doingSmartConfig = false;
		MQTT_Connect(&mqttClient);
		break;
	case SC_TOGGLE:
		if (doingSmartConfig) {
			os_printf("Stop smartConfig\n");
			stopFlash();
			smartconfig_stop();
			doingSmartConfig = false;
			wifi_station_disconnect();
			wifi_station_connect();
		} else {
			os_printf("Start smartConfig\n");
			MQTT_Disconnect(&mqttClient);
			mqttConnected = false;
			startFlash(100, true);
			doingSmartConfig = true;
			smartconfig_start(smartConfig_done, true);
		}
		break;
	}
	return doingSmartConfig;
}
예제 #3
0
void ICACHE_FLASH_ATTR
smartconfig_done(sc_status status, void *pdata)
{
    switch(status) {
        case SC_STATUS_WAIT:
            printf("SC_STATUS_WAIT\n");
            break;
        case SC_STATUS_FIND_CHANNEL:
            printf("SC_STATUS_FIND_CHANNEL\n");
            break;
        case SC_STATUS_GETTING_SSID_PSWD:
            printf("SC_STATUS_GETTING_SSID_PSWD\n");
            break;
        case SC_STATUS_LINK:
            printf("SC_STATUS_LINK\n");
            struct station_config *sta_conf = pdata;
	
	        wifi_station_set_config(sta_conf);
	        wifi_station_disconnect();
	        wifi_station_connect();
            break;
        case SC_STATUS_LINK_OVER:
            printf("SC_STATUS_LINK_OVER\n");
            if (SC_Type == SC_TYPE_ESPTOUCH) {
                uint8 phone_ip[4] = {0};

                memcpy(phone_ip, (uint8*)pdata, 4);
                printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
            }
            smartconfig_stop();
            break;
    }
	
}
예제 #4
0
void ICACHE_FLASH_ATTR smartConfig_done(sc_status status, void *pdata) {
	switch (status) {
	case SC_STATUS_WAIT:
		os_printf("SC_STATUS_WAIT\n");
		break;
	case SC_STATUS_FIND_CHANNEL:
		os_printf("SC_STATUS_FIND_CHANNEL\n");
		break;
	case SC_STATUS_GETTING_SSID_PSWD:
		os_printf("SC_STATUS_GETTING_SSID_PSWD\n");
		break;
	case SC_STATUS_LINK:
		os_printf("SC_STATUS_LINK\n");
		struct station_config *sta_conf = pdata;
		wifi_station_set_config(sta_conf);
		INFOP("Connected to %s (%s) %d", sta_conf->ssid, sta_conf->password, sta_conf->bssid_set);
		strcpy(sysCfg.sta_ssid, sta_conf->ssid);
		strcpy(sysCfg.sta_pwd, sta_conf->password);
		wifi_station_disconnect();
		wifi_station_connect();
		break;
	case SC_STATUS_LINK_OVER:
		os_printf("SC_STATUS_LINK_OVER\n");
		smartconfig_stop();
		checkSmartConfig(SC_HAS_STOPPED);
		sysCfg.sta_ssid;
		break;
	}
}
예제 #5
0
void ESP8266WiFiClass::stopSmartConfig()
{
    if (!_smartConfigStarted)
        return;

    smartconfig_stop();
    _smartConfigStarted = false;
}
예제 #6
0
/**
 *  Stop SmartConfig
 */
bool ESP8266WiFiSTAClass::stopSmartConfig() {
    if(!_smartConfigStarted) {
        return true;
    }

    if(smartconfig_stop()) {
        _smartConfigStarted = false;
        return true;
    }
    return false;
}
예제 #7
0
// Lua: exit_smart()
static int wifi_exit_smart( lua_State* L )
{
#if defined( NODE_SMART_OLDSTYLE )
  smart_end();
#else
  smartconfig_stop();
#endif // defined( NODE_SMART_OLDSTYLE )

  if(wifi_smart_succeed != LUA_NOREF)
    luaL_unref(L, LUA_REGISTRYINDEX, wifi_smart_succeed);
  wifi_smart_succeed = LUA_NOREF;
  return 0;  
}
예제 #8
0
/**
 *  Connection timeout reached
 */
void connectFail() {

	debugf("CAN NOT CONNECT");

	blinkStop();
	digitalWrite(RED_LED_PIN, true);

	if (configMode) {

		configMode = false;
		smartconfig_stop();
	}

}
예제 #9
0
void smartconfig_done(sc_status status, void *pdata)
{
    switch(status) {
        case SC_STATUS_WAIT:
            printf("SC_STATUS_WAIT\n");
            break;
        case SC_STATUS_FIND_CHANNEL:
            printf("SC_STATUS_FIND_CHANNEL\n");
            break;
        case SC_STATUS_GETTING_SSID_PSWD: {
				printf("SC_STATUS_GETTING_SSID_PSWD\n");
				sc_type *type = (sc_type *) pdata;
				if (*type == SC_TYPE_ESPTOUCH) {
					printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
				} else {
					printf("SC_TYPE:SC_TYPE_AIRKISS\n");
				}
				break;
        	}
        case SC_STATUS_LINK: {
				printf("SC_STATUS_LINK\n");
				struct station_config *sta_conf = (station_config *) pdata;

				printf("Trying to connect to %s\n", sta_conf->ssid);
				printf("Using password to %s\n", sta_conf->password);

				wifi_station_set_config(sta_conf);
				wifi_station_disconnect();
				wifi_station_connect();

				// Run our method when station was connected to AP (or not connected)
				WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for connection timeout at start

				break;
			}
        case SC_STATUS_LINK_OVER:
            printf("SC_STATUS_LINK_OVER\n");
            if (pdata != NULL) {
                uint8 phone_ip[4] = {0};

                memcpy(phone_ip, (uint8*)pdata, 4);
                printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
            }
            smartconfig_stop();
            break;
    }

}
예제 #10
0
static void wifi_smart_succeed_cb(void *arg){
  NODE_DBG("wifi_smart_succeed_cb is called.\n");
  if( !arg )
    return;
#if 0
  struct station_config *sta_conf = arg;
  wifi_station_set_config(sta_conf);
  wifi_station_disconnect();
  wifi_station_connect();
  smartconfig_stop();
#endif
  if(wifi_smart_succeed == LUA_NOREF)
    return;
  lua_State* L = (lua_State *)arg;
  lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_smart_succeed);
  lua_call(L, 0, 0);
}
예제 #11
0
/******************************************************************************
 * FunctionName : user_humiture_long_press
 * Description  : humiture key's function, needed to be installed
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_sensor_long_press(void)
{
    os_printf(" LVZAINA ===> SmartConfig start! \n");
	
	uint32 gpio_status;
	gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	//clear interrupt status
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
	
	user_link_led_timer_init();	
	
	smartconfig_stop();
    smartconfig_start(smartconfig_done);
	
    os_printf(" LVZAINA ===> SmartConfig end! \n");
}
예제 #12
0
void ICACHE_FLASH_ATTR
smartconfig_done(sc_status status, void *pdata)
{
    switch(status) {
        case SC_STATUS_WAIT:
            printf("SC_STATUS_WAIT\n");
            break;
        case SC_STATUS_FIND_CHANNEL:
            printf("SC_STATUS_FIND_CHANNEL\n");
            break;
        case SC_STATUS_GETTING_SSID_PSWD:
            printf("SC_STATUS_GETTING_SSID_PSWD\n");
            sc_type *type = pdata;
            if (*type == SC_TYPE_ESPTOUCH) {
                printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
            } else {
                printf("SC_TYPE:SC_TYPE_AIRKISS\n");
            }
            break;
        case SC_STATUS_LINK:
            printf("SC_STATUS_LINK\n");
            struct station_config *sta_conf = pdata;
	
	        wifi_station_set_config(sta_conf);
	        wifi_station_disconnect();
	        wifi_station_connect();
            break;
        case SC_STATUS_LINK_OVER:
            printf("SC_STATUS_LINK_OVER\n");
            if (pdata != NULL) {
				//SC_TYPE_ESPTOUCH
                uint8 phone_ip[4] = {0};

                memcpy(phone_ip, (uint8*)pdata, 4);
                printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
            } else {
            	//SC_TYPE_AIRKISS - support airkiss v2.0
				airkiss_start_discover();
			}
            smartconfig_stop();
            break;
    }
	
}
예제 #13
0
void ICACHE_FLASH_ATTR
smartconfig_done(sc_status status, void *pdata)
{
    switch(status) {
        case SC_STATUS_WAIT:
            os_printf("SC_STATUS_WAIT\n");
            break;
        case SC_STATUS_FIND_CHANNEL:
            os_printf("SC_STATUS_FIND_CHANNEL\n");
            break;
        case SC_STATUS_GETTING_SSID_PSWD:
            os_printf("SC_STATUS_GETTING_SSID_PSWD\n");
			sc_type *type = pdata;
            if (*type == SC_TYPE_ESPTOUCH) {
                os_printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
            } else {
                os_printf("SC_TYPE:SC_TYPE_AIRKISS\n");
            }
            break;
        case SC_STATUS_LINK:
            os_printf("SC_STATUS_LINK\n");
            struct station_config *sta_conf = pdata;
	
	        wifi_station_set_config(sta_conf);
	        wifi_station_disconnect();
	        wifi_station_connect();
            break;
        case SC_STATUS_LINK_OVER:
            os_printf("SC_STATUS_LINK_OVER\n");
            if (pdata != NULL) {
                uint8 phone_ip[4] = {0};

                os_memcpy(phone_ip, (uint8*)pdata, 4);
                os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
            }
            smartconfig_stop();
			user_link_led_timer_done();
			user_devicefind_init();
            break;
    }
	
}
예제 #14
0
파일: main.c 프로젝트: icamgo/noduino-sdk
void smartconfig_done(sc_status status, void *pdata)
{
	switch (status) {
	case SC_STATUS_WAIT:
		os_printf("SC_STATUS_WAIT\n");
		break;
	case SC_STATUS_FIND_CHANNEL:
		os_printf("SC_STATUS_FIND_CHANNEL\n");
		break;
	case SC_STATUS_GETTING_SSID_PSWD:
		os_printf("SC_STATUS_GETTING_SSID_PSWD\n");
		sc_type *type = pdata;
		if (*type == SC_TYPE_ESPTOUCH) {
			os_printf("SC_TYPE:SC_TYPE_ESPTOUCH\n");
		} else {
			os_printf("SC_TYPE:SC_TYPE_AIRKISS\n");
		}
		break;
	case SC_STATUS_LINK:
		os_printf("SC_STATUS_LINK\n");
		struct station_config *sta_conf = pdata;

		os_printf("Store the ssid and password into flash\n");
		wifi_station_set_config(sta_conf);

		wifi_station_disconnect();
		wifi_station_connect();
		break;
	case SC_STATUS_LINK_OVER:
		os_printf("SC_STATUS_LINK_OVER\n");
		if (pdata != NULL) {
			uint8 phone_ip[4] = { 0 };

			os_memcpy(phone_ip, (uint8 *) pdata, 4);
			os_printf("Phone ip: %d.%d.%d.%d\n", phone_ip[0],
				  phone_ip[1], phone_ip[2], phone_ip[3]);
		}
		smartconfig_stop();
		break;
	}

}
예제 #15
0
static void wifi_smart_succeed_cb(void *arg){
  NODE_DBG("wifi_smart_succeed_cb is called.\n");

#if defined( NODE_SMART_OLDSTYLE )

  if( !arg )
    return;
  if(wifi_smart_succeed == LUA_NOREF)
    return;

  lua_State* L = (lua_State *)arg;
  lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_smart_succeed);
  lua_call(L, 0, 0);

#else

  if( !arg )
    return;

  struct station_config *sta_conf = arg;
  wifi_station_set_config(sta_conf);
  wifi_station_disconnect();
  wifi_station_connect();

  if(wifi_smart_succeed != LUA_NOREF)
  {
    lua_rawgeti(smart_L, LUA_REGISTRYINDEX, wifi_smart_succeed);

    lua_pushstring(smart_L, sta_conf->ssid); 
    lua_pushstring(smart_L, sta_conf->password); 
    lua_call(smart_L, 2, 0);

    luaL_unref(smart_L, LUA_REGISTRYINDEX, wifi_smart_succeed);
    wifi_smart_succeed = LUA_NOREF;
  }
  smartconfig_stop();

#endif // defined( NODE_SMART_OLDSTYLE )
}
예제 #16
0
void setConfigMode(bool on) {
	if (on) {

		configMode = true;
		blinkGreenStart(500, -1);

		// start smart-config
		xTaskCreate(smartconfig_task, (const signed char* ) "smartconfig_task", 256, NULL, 2, NULL);
		smartConfigActive = true;

	} else {

		configMode = false;
		blinkStop();
		smartconfig_stop();
		smartConfigActive = false;
		WifiStation.waitConnection(connectOk, 10, connectFail);

		// Reboot in operation mode
		rboot_set_current_rom(0);
		Serial.println("Restarting...");
		System.restart();
	}
}
/******************************************************************************
 * FunctionName : esptouch_ProcCb
 * Description  : esp-touch status change callback for smartconfig_start
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR 
esptouch_ProcCb(sc_status status, void *pdata)
{
    switch(status) {
        case SC_STATUS_WAIT:
            SC_INFO("SC_STATUS_WAIT\n");
            break;
        case SC_STATUS_FIND_CHANNEL:
            SC_INFO("SC_STATUS_FIND_CHANNEL\n");
            if(esptouch_proc.esptouch_start_cb){
                esptouch_proc.esptouch_start_cb(NULL);
            }
            break;
        case SC_STATUS_GETTING_SSID_PSWD:
            SC_INFO("SC_STATUS_GETTING_SSID_PSWD\n");
            #if LIGHT_DEVICE
            light_shadeStart(HINT_BLUE,1000,0,1,NULL);
            #endif
            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_TIMEOUT_MS,0);
            }
            break;
        case SC_STATUS_LINK:
            SC_INFO("SC_STATUS_LINK\n");
            struct station_config *sta_conf = pdata;
            //os_printf();
            wifi_station_set_config(sta_conf);
            wifi_station_disconnect();
            
            //wifi_station_disconnect();
            //======================
            #if ESP_MESH_SUPPORT
            //mesh_enable_task();
            //user_MeshStart();
            //user_esp_platform_connect_ap_cb();
            #endif
            //======================
            wifi_station_connect();
            
            os_timer_disarm(&esptouch_tout_t);
            os_timer_arm(&esptouch_tout_t,ESPTOUCH_CONNECT_TIMEOUT_MS,0);
            #if LIGHT_DEVICE
            //light_blinkStart(HINT_WHITE);
            light_shadeStart(HINT_WHITE,1000,0,1,NULL);
            #endif
            break;
        case SC_STATUS_LINK_OVER:
            os_timer_disarm(&esptouch_tout_t);
            SC_INFO("SC_STATUS_LINK_OVER\n");
            if (esptouch_proc.esptouch_type == SC_TYPE_ESPTOUCH) {
                uint8 phone_ip[4] = {0};
                os_memcpy(phone_ip, (uint8*)pdata, 4);
                SC_INFO("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
            }
            smartconfig_stop();
            SC_INFO("UPDATE PASSWORD HERE\r\n");
            if(esptouch_proc.esptouch_suc_cb){
                esptouch_proc.esptouch_suc_cb(NULL);//run finish cb
            }
            break;
    }
    
}