Example #1
1
void setup_wifi_ap_mode(void)
{
	wifi_set_opmode((wifi_get_opmode()|SOFTAP_MODE)&STATIONAP_MODE);
	struct softap_config apconfig;
	if(wifi_softap_get_config(&apconfig))
	{
		wifi_softap_dhcps_stop();
		memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, WIFI_AP_NAME);
		os_sprintf(apconfig.password, "%s", WIFI_AP_PASSWORD);
		apconfig.authmode = AUTH_WPA_WPA2_PSK;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 4;
		if(!wifi_softap_set_config(&apconfig))
		{
			#ifdef PLATFORM_DEBUG
			os_printf("ESP8266 not set AP config!\r\n");
			#endif
		};
		struct ip_info ipinfo;
		wifi_get_ip_info(SOFTAP_IF, &ipinfo);
		IP4_ADDR(&ipinfo.ip, 192, 168, 4, 1);
		IP4_ADDR(&ipinfo.gw, 192, 168, 4, 1);
		IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);
		wifi_softap_dhcps_start();
	}
	#ifdef PLATFORM_DEBUG
	os_printf("ESP8266 in AP mode configured.\r\n");
	#endif
}
Example #2
0
void ICACHE_FLASH_ATTR config_wifi_new(void){
        wifi_softap_dhcps_stop();
	//vTaskDelay( xDelay );
        wifi_set_opmode(NULL_MODE);
	//vTaskDelay( xDelay );
	wifi_set_opmode(SOFTAP_MODE);
	//vTaskDelay( xDelay );
	struct softap_config apConfig;
	char ssid[8];
	wifi_set_event_handler_cb(wifi_event_cb);
	//mode_info();
	memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
	sprintf(ssid, "%s\0", WIFI_APSSID);
	memcpy(apConfig.ssid, ssid, strlen(ssid));
	printf("SSID %s\n",apConfig.ssid);
	apConfig.authmode = AUTH_OPEN;
	apConfig.channel = 5;
	apConfig.ssid_len=strlen(ssid);
	apConfig.max_connection = 255;
	apConfig.ssid_hidden = 0;
	wifi_softap_set_config(&apConfig);
	//vTaskDelay( xDelay );
	wifi_softap_dhcps_start();
	//vTaskDelay( xDelay*10 );
	coap_restart(0);
}
/******************************************************************************
 * FunctionName : mesh_SetSoftap
 * Description  : If the device failed to join mesh network,
                  open the SoftAP interface for webserver
                  The SSID should not be the same form as that of the device in mesh network
*******************************************************************************/
void ICACHE_FLASH_ATTR
mesh_SetSoftap()
{
    MESH_INFO("----------------------\r\n");
    MESH_INFO("MESH ENABLE SOFTAP \r\n");
    MESH_INFO("----------------------\r\n");
    struct softap_config config_softap;
    char ssid[33]={0};
    wifi_softap_get_config(&config_softap);
    os_memset(config_softap.password, 0, sizeof(config_softap.password));
    os_memset(config_softap.ssid, 0, sizeof(config_softap.ssid));
    os_sprintf(ssid,"ESP_%06X",system_get_chip_id());
    os_memcpy(config_softap.ssid, ssid, os_strlen(ssid));
    config_softap.ssid_len = os_strlen(ssid);
    config_softap.ssid_hidden = 0;
    config_softap.channel = wifi_get_channel();
    #ifdef SOFTAP_ENCRYPT
        char password[33];
        char macaddr[6];
        os_sprintf(password, MACSTR "_%s", MAC2STR(macaddr), PASSWORD);
        os_memcpy(config_softap.password, password, os_strlen(password));
        config_softap.authmode = AUTH_WPA_WPA2_PSK;
    #else
        os_memset(config_softap.password,0,sizeof(config_softap.password));
        config_softap.authmode = AUTH_OPEN;
    #endif
    wifi_set_opmode(STATIONAP_MODE);
    wifi_softap_set_config(&config_softap);
    wifi_set_opmode(STATIONAP_MODE);
    wifi_softap_get_config(&config_softap);
    MESH_INFO("SSID: %s \r\n",config_softap.ssid);
    MESH_INFO("CHANNEL: %d \r\n",config_softap.channel);
    MESH_INFO("-------------------------\r\n");
}
Example #4
0
// This routine is ran some time after a connection attempt to an access point. If
// the connect succeeds, this gets the module in STA-only mode. If it fails, it ensures
// that the module is in STA+AP mode so the user has a chance to recover.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
  int x = wifi_station_get_connect_status();
  int m = wifi_get_opmode() & 0x3;
  DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

  if (m == 2) return; // 2=AP, in AP-only mode we don't do any auto-switching

  if ( x == STATION_GOT_IP ) {
    // if we got an IP we could switch to STA-only...
    if (m != 1) { // 1=STA
#ifdef CHANGE_TO_STA
      // We're happily connected, go to STA mode
      DBG("Wifi got IP. Going into STA mode..\n");
      wifi_set_opmode(1);
      os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif
    }
    log_uart(false);
    // no more resetTimer at this point, gotta use physical reset to recover if in trouble
  } else {
    // we don't have an IP address
    if (m != 3) {
      DBG("Wifi connect failed. Going into STA+AP mode..\n");
      wifi_set_opmode(3);
      wifi_softap_set_config(&apconf);
    }
    log_uart(true);
    DBG("Enabling/continuing uart log\n");
    os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
  }
}
Example #5
0
// This routine is ran some time after a connection attempt to an access point. If
// the connect succeeds, this gets the module in STA-only mode. If it fails, it ensures
// that the module is in STA+AP mode so the user has a chance to recover.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
  int x = wifi_station_get_connect_status();
  int m = wifi_get_opmode() & 0x3;
  DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

  if (x == STATION_GOT_IP) {
    if (m != 1) {
#ifdef CHANGE_TO_STA
      // We're happily connected, go to STA mode
      DBG("Wifi got IP. Going into STA mode..\n");
      wifi_set_opmode(1);
      os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); // check one more time after switching to STA-only
#endif
    }
    log_uart(false);
    // no more resetTimer at this point, gotta use physical reset to recover if in trouble
  } else {
    if (m != 3) {
      DBG("Wifi connect failed. Going into STA+AP mode..\n");
      wifi_set_opmode(3);
    }
    log_uart(true);
    DBG("Enabling/continuing uart log\n");
    os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
  }
}
Example #6
0
//This routine is ran some time after a connection attempt to an access point. If
//the connect succeeds, this gets the module in STA-only mode.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
	int x = wifi_station_get_connect_status();
	int m = wifi_get_opmode() & 0x3;
	os_printf("Wifi check: mode=%s status=%d\n", wifiMode[m], x);

	if (x == STATION_GOT_IP) {
		if (m != 1) {
			// We're happily connected, go to STA mode
			os_printf("Wifi got IP. Going into STA mode..\n");
			wifi_set_opmode(1);
			wifi_set_sleep_type(SLEEP_MODE);
			os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
			//os_timer_disarm(&deepTimer);
			//os_timer_setfn(&deepTimer, deepSleepCb, NULL);
			//os_timer_arm(&deepTimer, 1000, 1);
		}
		log_uart(false);
		// no more resetTimer at this point, gotta use physical reset to recover if in trouble
	} else {
		if (m != 3) {
			os_printf("Wifi connect failed. Going into STA+AP mode..\n");
			wifi_set_opmode(3);
		}
		log_uart(true);
		os_printf("Enabling/continuing uart log\n");
		os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
	}
}
Example #7
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    bool ret;
    PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC);
    xUARTQueue = xQueueCreate(128, sizeof(char));
    uart_init_new();
    UART_intr_handler_register(&uart0_rx_intr_handler, &xUARTQueue);
    ETS_UART_INTR_ENABLE();
    printf("SDK version:%s\n", system_get_sdk_version());
    GPIO_OUTPUT_SET(LED_GPIO, 0);

   
   //Set  station mode
   wifi_set_opmode(STATIONAP_MODE);

   // ESP8266 connect to router.
   // user_set_station_config();

   // Setup TCP server
   


   wifi_station_set_auto_connect(0);
    // wifi_station_set_reconnect_policy(0);

    printf("Wifi Button example program. \r\n");
    if (!read_user_config(&user_config))
    {
        ret = wifi_set_opmode(STATIONAP_MODE);
        DBG("wifi_set_opmode returns %d op_mode now %d\r\n", ret, wifi_get_opmode());
        // user_set_station_config();
        user_tcpserver_init(SERVER_LOCAL_PORT);
        // user_tcpserver_init(SERVER_LOCAL_PORT);
        wifi_station_set_auto_connect(1);
    }
    else
    {
        printf ("No valid config\r\n");
    }

    printf("Hiya");
    // sys_init_timing();
   lwip_init();

   // while(1);

   // xTaskCreate(check_input, "input", 256, &xUARTQueue, 3, NULL);

   // xTaskCreate(helloworld, "hw", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
   // xTaskCreate(blinky, "bl", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
}
void restoreFactorySettings() {
	wifi_station_disconnect();
	wifi_set_opmode(0x3); //reset to STA+AP mode

	struct softap_config apConfig;
	wifi_softap_get_config(&apConfig);
	os_strncpy((char*)apConfig.ssid, "smartswitch", 18);
	apConfig.authmode = 0; //Disable security
	wifi_softap_set_config(&apConfig);

	struct station_config stconf;
	os_strncpy((char*)stconf.ssid, "", 2);
	os_strncpy((char*)stconf.password, "", 2);
	wifi_station_set_config(&stconf);

	OLED_CLS();
	OLED_Print(2, 0, "RESET", 1);
	os_printf("Reset completed. Restarting system...\n");

	ioOutput(0, GPIO_OUTPUT1);
	ioOutput(0, GPIO_OUTPUT2);

	while (!GPIO_INPUT_GET(GPIO_BUTTON1)) { os_printf("."); };
	while (!GPIO_INPUT_GET(GPIO_BUTTON2)) { os_printf("."); };

	system_restart();
}
Example #9
0
/*
 * 函数:user_wifi_init
 * 说明:WiFi配置初始化
 */
void ICACHE_FLASH_ATTR
user_wifi_init(void)
{
	wifi_set_opmode(STATION_MODE);
	user_set_station_config(WIFI_SSID, WIFI_PASSWORD);
    wifi_set_event_handler_cb(wifi_handle_event_cb);
}
/******************************************************************************
 * FunctionName : esptouch_SuccessCb
 * Description  : esp-touch success callback
*******************************************************************************/
void ICACHE_FLASH_ATTR
    esptouch_SuccessCb(void* data)
{
    wifi_set_opmode(STATIONAP_MODE);
    
    os_timer_disarm(&esptouch_tout_t);//disable check timeout 
    #if LIGHT_DEVICE
    light_hint_stop(HINT_WHITE);
    #endif
    SC_INFO("ESP-TOUCH SUCCESS \r\n");
    
    SC_INFO("ENABLE LIGHT ACTION(ESP-NOW)");
    SC_INFO("debug: channel:%d\r\n",wifi_get_channel());
#if ESP_MESH_SUPPORT
    if(MESH_DISABLE == espconn_mesh_get_status()){
        //user_MeshStart();
        //mesh_enable_task();
    }
    user_esp_platform_connect_ap_cb();
    //user_MeshStart();
#else
    user_esp_platform_connect_ap_cb();
#endif
#if ESP_NOW_SUPPORT
    light_EspnowInit();
#endif
    SC_INFO("CONNECTED TO AP...ENABLE MESH AND RUN PLATFORM CODE ...WAIT...\r\n");

}
Example #11
0
//============================================================================================================================
void setup_wifi_ap_mode(void)
{
	wifi_set_opmode((wifi_get_opmode()|STATIONAP_MODE)&STATIONAP_MODE);
	struct softap_config apconfig;
	if(wifi_softap_get_config(&apconfig))
	{
		wifi_softap_dhcps_stop();
		os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		os_memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, configs.hwSettings.wifi.SSID);//"HA-HA-HA");
		os_sprintf(apconfig.password, "%s", configs.hwSettings.wifi.SSID_PASS);//"qwertyuiop");
		apconfig.authmode = configs.hwSettings.wifi.auth;//AUTH_OPEN;//AUTH_WPA_WPA2_PSK;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 4;
		if(!wifi_softap_set_config(&apconfig))
		{
			//#if DEBUG_LEVEL > 0
			ets_uart_printf("ESP8266 not set AP config!\r\n");
			//#endif
		};
		struct ip_info ipinfo;
		wifi_get_ip_info(SOFTAP_IF, &ipinfo);
		IP4_ADDR(&ipinfo.ip, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.gw, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);
		wifi_softap_dhcps_start();
	}
	//#if DEBUG_LEVEL > 0
	ets_uart_printf("ESP8266 in AP mode configured.\r\n");
	//#endif
}
void ICACHE_FLASH_ATTR dhconnector_init(dhconnector_command_json_cb cb) {
	dhrequest_load_settings();
	mCommandCallback = cb;
	mConnectionState = CS_DISCONNECT;

	dhrequest_create_info(&mInfoRequest);
	dhrequest_create_register(&mRegisterRequest);
	mPollRequest.len = mPollRequest.data[0] = 0;

	wifi_set_opmode(STATION_MODE);
	wifi_station_set_auto_connect(1);
	wifi_station_set_reconnect_policy(true);
	struct station_config stationConfig;
	wifi_station_get_config(&stationConfig);
	wifi_set_phy_mode(PHY_MODE_11N);
	os_memset(stationConfig.ssid, 0, sizeof(stationConfig.ssid));
	os_memset(stationConfig.password, 0, sizeof(stationConfig.password));
	snprintf(stationConfig.ssid, sizeof(stationConfig.ssid), "%s", dhsettings_get_wifi_ssid());
	snprintf(stationConfig.password, sizeof(stationConfig.password), "%s", dhsettings_get_wifi_password());
	wifi_station_set_config(&stationConfig);

	static esp_tcp tcp;
	os_memset(&tcp, 0, sizeof(tcp));
	os_memset(&mDHConnector, 0, sizeof(mDHConnector));
	mDHConnector.type = ESPCONN_TCP;
	mDHConnector.state = ESPCONN_NONE;
	mDHConnector.proto.tcp = &tcp;
	mDHConnector.proto.tcp->local_port = espconn_port();

	wifi_set_event_handler_cb(wifi_state_cb);
}
Example #13
0
/**
  * @brief  Setup commad of set wifi mode.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCwmode(uint8_t id, char *pPara)
{
  uint8_t mode;
  char temp[32];

  pPara++;
  mode = atoi(pPara);
  if(mode == at_wifiMode)
  {
    uart0_sendStr("no change\r\n");
    return;
  }
  if((mode >= 1) && (mode <= 3))
  {
    ETS_UART_INTR_DISABLE();
    wifi_set_opmode(mode);
    ETS_UART_INTR_ENABLE();
    at_backOk;
//    system_restart();
  }
  else
  {
    at_backError;
  }
}
Example #14
0
void ICACHE_FLASH_ATTR WIFI_999_Connect(uint8_t* ssid, uint8_t* pass, WifiCallback cb)
{
	struct station_config stationConf;

	INFO("WIFI_INIT\r\n");
	wifi_set_opmode(STATION_MODE);
	wifi_station_set_auto_connect(FALSE);
	wifiCb = cb;

	os_memset(&stationConf, 0, sizeof(struct station_config));

	os_sprintf(stationConf.ssid, "%s", ssid);
	os_sprintf(stationConf.password, "%s", pass);

	wifi_station_set_config(&stationConf);

	os_timer_disarm(&WiFiLinker);
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, 1000, 0);

	wifi_station_set_auto_connect(TRUE);
	/*
	 * Reconnect is only in SDK 1.2 and newer.  :-(
	 *
	 * wifi_station_set_reconnect_policy(TRUE);	// After a hint from Pete Scargill.
	 */
	wifi_station_connect();
}
Example #15
0
static void config_wifi(){
    NODE_DBG("Putting AP UP");

    platform_key_led(0);    
    
    wifi_station_set_auto_connect(1); 
    wifi_set_opmode(0x03); // station+ap mode                       

    struct softap_config config;
    wifi_softap_get_config(&config);

    char ssid[]="SmartRelay"SERIAL_NUMBER;

    strcpy(config.ssid,ssid);
    memset(config.password,0,64);
    config.ssid_len=strlen(ssid);
    config.channel=11;
    config.authmode=AUTH_OPEN;
    config.max_connection=4;
    config.ssid_hidden=0;

    wifi_softap_set_config(&config);

    
}
Example #16
0
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());
	
    wifi_set_opmode(STATION_MODE);
    smartconfig_start(smartconfig_done);
}
Example #17
0
void AccessPointClass::enable(bool enabled)
{
	uint8 mode = wifi_get_opmode() & ~SOFTAP_MODE;
	if (enabled) mode |= SOFTAP_MODE;
//	wifi_set_opmode(static_cast<WIFI_MODE>(mode));
	wifi_set_opmode((WIFI_MODE)mode);
}
Example #18
0
void user_init()
{
    struct station_config conf;

    // This is used to setup the serial communication
    uart_div_modify(0, UART_CLK_FREQ / 115200);

    wifi_set_opmode(STATION_MODE);

    // os_bzero ( &conf, sizeof(struct station_config) );
    os_memset ( &conf, 0, sizeof(struct station_config) );
    os_memcpy (&conf.ssid, ssid, 32);
    os_memcpy (&conf.password, pass, 64 );
    wifi_station_set_config (&conf);

    // And this is used to print some information
    os_printf("\n");
    os_printf("SDK version:%s\n", system_get_sdk_version());
    system_print_meminfo();
    os_delay_us ( 1 );
    os_printf ( "CPU Hz = %d\n", system_get_cpu_freq() );

    show_mac ();
    show_ip ();

    /* set a callback for wifi events */
    wifi_set_event_handler_cb ( wifi_event );
}
Example #19
0
void ICACHE_FLASH_ATTR user_init(void) {
	uart_div_modify(0, UART_CLK_FREQ / BAUD);

	wifi_set_opmode(STATION_MODE);
	wifi_station_connect();

	/*** I²C init ***/
	i2c_master_gpio_init();
	mpu9250_init();
	ak8963_init();

	os_delay_us(10000);
	i2c_scanbus();

	/*** LCD Init ***/
	ssd1306_init(0);
	ssd1306_text_small(10, 10, "Init...");
	ssd1306_flip();

	// ~Charge input
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);
	gpio_output_set(0, 0, 0, BIT13);

	// Button inputs
	buttons_init();

	ak8963_calibration_start(10000, on_ak8963_calibration);

	os_printf("Startup\r\n");
}
Example #20
0
//Init function 
void ICACHE_FLASH_ATTR user_init()
{
    uart_init(115200, 115200);
    os_delay_us(100);

    uart0_sendStr("*** Monitor mode test ***\r\n");
    
    os_printf(" -> Promisc mode setup ... ");
    wifi_set_promiscuous_rx_cb(promisc_cb);
    wifi_promiscuous_enable(1);
    os_printf("done.\n");

    os_printf(" -> Timer setup ... ");
    os_timer_disarm(&channelHop_timer);
    os_timer_setfn(&channelHop_timer, (os_timer_func_t *) channelHop, NULL);
    os_timer_arm(&channelHop_timer, CHANNEL_HOP_INTERVAL, 1);
    os_printf("done.\n");
    
    os_printf(" -> Set opmode ... ");
    wifi_set_opmode( 0x1 );
    os_printf("done.\n");

    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);

    os_printf(" -> Init finished!\n\n");
}
void ICACHE_FLASH_ATTR user_init(void) {
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	os_printf("SDK version:%s\n", system_get_sdk_version());
	i2c_init();
#ifdef ESP8266OLED
	oled_init();
#endif
	key_and_gpio_init();
#ifdef ESP8266DOOR
	door_switch_init();
#endif
	wifi_set_event_handler_cb(wifi_handle_event_cb);
	mqttstart();
#ifdef ESP8266ENVINFO
	task_send_environment_info_init();
#endif
#ifdef ESP8266CARDREAD
	pn532_init();
	pn532_cb_event_init();
#endif
	struct station_config s_staconf;
	wifi_station_get_config_default(&s_staconf);
	if (os_strlen(s_staconf.ssid) == 0) {
		wifi_set_opmode(STATION_MODE);
		smartconfig_set_type(SC_TYPE_ESPTOUCH);
		smartconfig_start(smartconfig_done);
	}
}
Example #22
0
void user_init()
{
#ifdef ESP8266_GDBSTUB
	gdbstub_init();
#endif

	//Uncomment the line below if you want to step through the initialization function in the debugger without getting a reset from a watchdog.
	//system_soft_wdt_stop();
	struct ip_info info;
	struct softap_config cfg;
	wifi_softap_get_config(&cfg);
	strcpy((char *)cfg.ssid, "$$com.sysprogs.esp8266.http.ssid$$");
	cfg.ssid_len = strlen((char*)cfg.ssid);
	wifi_softap_set_config_current(&cfg);
	wifi_set_opmode(SOFTAP_MODE);
	
	wifi_softap_dhcps_stop();
	IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &info);
	dhcps_lease_test();
	wifi_softap_dhcps_start();
	
	static struct espconn httpdConn;
	static esp_tcp httpdTcp;
	httpdConn.type = ESPCONN_TCP;
	httpdConn.state = ESPCONN_NONE;
	httpdTcp.local_port = 80;
	httpdConn.proto.tcp = &httpdTcp;

	espconn_regist_connectcb(&httpdConn, httpdConnectCb);
	espconn_accept(&httpdConn);
}
Example #23
0
static void ICACHE_FLASH_ATTR resetButtonTimerCallback(void *data)
{
    static int previousState = 1;
    static int matchingSampleCount = 0;
    static int buttonPressCount = 0;
    static uint32_t lastButtonTime;
    int newState = GPIO_INPUT_GET(RESET_BUTTON_PIN);
    if (newState != previousState)
        matchingSampleCount = 0;
    else if (matchingSampleCount < RESET_BUTTON_THRESHOLD) {
        if (++matchingSampleCount == RESET_BUTTON_THRESHOLD) {
            if (newState != resetButtonState) {
                resetButtonState = newState;
                if (resetButtonState == 0) {
                    uint32_t buttonTime = system_get_time() / 1000;
                    //os_printf("Reset button press: count %d, last %u, this %u\n", buttonPressCount, (unsigned)lastButtonTime, (unsigned)buttonTime);
                    if (buttonPressCount == 0 || buttonTime - lastButtonTime > RESET_BUTTON_PRESS_DELTA)
                        buttonPressCount = 1;
                    else if (++buttonPressCount == RESET_BUTTON_PRESS_COUNT) {
                        os_printf("Entering STA+AP mode\n");
                        wifi_set_opmode(STATIONAP_MODE);
                        buttonPressCount = 0;
                    }
                    lastButtonTime = buttonTime;
                }
            }
        }
    }
    previousState = newState;
}
Example #24
0
/**
 * set new mode
 * @param m WiFiMode_t
 */
bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
    if(_persistent){
        if(wifi_get_opmode() == (uint8) m && wifi_get_opmode_default() == (uint8) m){
            return true;
        }
    } else if(wifi_get_opmode() == (uint8) m){
        return true;
    }

    bool ret = false;

    if (m != WIFI_STA && m != WIFI_AP_STA)
        // calls lwIP's dhcp_stop(),
        // safe to call even if not started
        wifi_station_dhcpc_stop();

    ETS_UART_INTR_DISABLE();
    if(_persistent) {
        ret = wifi_set_opmode(m);
    } else {
        ret = wifi_set_opmode_current(m);
    }
    ETS_UART_INTR_ENABLE();

    return ret;
}
Example #25
0
void setup_wifi_st_mode(void)
{
//	wifi_set_opmode((wifi_get_opmode()|STATION_MODE)&STATIONAP_MODE);
	wifi_set_opmode(wifi_get_opmode() | STATION_MODE);

	struct station_config stconfig;
	wifi_station_disconnect();
	wifi_station_dhcpc_stop();
	if(wifi_station_get_config(&stconfig))
		{
		memset(stconfig.ssid, 0, sizeof(stconfig.ssid));
		memset(stconfig.password, 0, sizeof(stconfig.password));
		os_sprintf(stconfig.ssid, "%s", sysCfg.sta_ssid);
		os_sprintf(stconfig.password, "%s", sysCfg.sta_pwd);
		if(!wifi_station_set_config(&stconfig))
			{
			#ifdef PLATFORM_DEBUG
			INFO("ESP8266 not set station config!\r\n");
			#endif
			}
		}
	wifi_station_connect();
	wifi_station_dhcpc_start();
	wifi_station_set_auto_connect(1);
	#ifdef PLATFORM_DEBUG
	INFO("ESP8266 in STA mode configured.\r\n");
	#endif
}
void ICACHE_FLASH_ATTR 
    WIFI_Connect(uint8_t* ssid, uint8_t* pass, WifiCallback cb)
{
    struct station_config stationConf;

    INFO("WIFI_INIT\r\n");
    wifi_set_opmode(STATIONAP_MODE);//
    if(cb){
        wifiCb = cb;
    }else{
        wifiCb = WIFI_ConnectCb;
    }
    os_memset(&stationConf, 0, sizeof(struct station_config));

    os_sprintf(stationConf.ssid, "%s", ssid);
    os_sprintf(stationConf.password, "%s", pass);

    wifi_station_set_config(&stationConf);

    os_timer_disarm(&WiFiLinker);
    os_timer_setfn(&WiFiLinker, (os_timer_func_t *)WIFI_CheckIp, NULL);
    os_timer_arm(&WiFiLinker, 1000, 0);

    wifi_station_connect();
}
Example #27
0
void ICACHE_FLASH_ATTR
user_init(void)
{
	gpio_init();
	gpio_output_set(0, 0, 0, 0xFFFFFFFF);

	//init software uart
	Softuart_SetPinRx(&softuart,13); 	
	Softuart_SetPinTx(&softuart,15);

	gpio_pin_wakeup_disable();
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12);

	UART_SetPrintPort(UART1);
	UartDev.data_bits = EIGHT_BITS;
	UartDev.parity = NONE_BITS;
	UartDev.stop_bits = ONE_STOP_BIT;
	uart_init(BIT_RATE_9600, BIT_RATE_115200);


	//clear noise
	uart0_sendStr("\r\n\r\n\r\n");

	//wifi_set_phy_mode(3);
	system_phy_set_powerup_option(3);
	wifi_set_opmode(STATION_MODE); //Set station mode
	system_phy_set_max_tpw(82); //MAX POWERR!
	system_phy_set_tpw_via_vdd33(system_get_vdd33());
	user_set_station_config();

	os_timer_disarm(&init_timer);
	os_timer_setfn(&init_timer, (os_timer_func_t *)gps_uart_init, NULL);
	os_timer_arm(&init_timer, 1000, 0); 
}
Example #28
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    uart_div_modify(0, UART_CLK_FREQ / 115200);

    wifi_set_opmode(STATION_MODE);
    websocket_start(&test_mode);
}
Example #29
0
void ICACHE_FLASH_ATTR
load_userParam(void)
{
	struct softap_config config;
    spi_flash_read((ESP_PARAM_START_SEC + 1) * SPI_FLASH_SEC_SIZE,
                   (uint32 *)&myParam, sizeof(USER_PARAM));

	// default setup
	if(myParam.sign!=4771215){
		myParam.sign = 4771215;
		myParam.baud_rate = BIT_RATE_115200;
		myParam.port = 1025;
		spi_flash_erase_sector(ESP_PARAM_START_SEC + 1);
        spi_flash_write((ESP_PARAM_START_SEC + 1) * SPI_FLASH_SEC_SIZE,
                        (uint32 *)&myParam, sizeof(USER_PARAM));
		wifi_set_opmode(STATIONAP_MODE);
		wifi_softap_get_config(&config);
		
		config.authmode = AUTH_OPEN;
        wifi_softap_set_config(&config);
		
	}
    spi_flash_read((ESP_PARAM_START_SEC + 1) * SPI_FLASH_SEC_SIZE,
                   (uint32 *)&myParam, sizeof(USER_PARAM));
}
void user_init(void)
{
	uart_init(74880,74880);

	wifi_set_opmode(STATION_MODE); //todo: re-enable
	system_init_done_cb(user_system_init_done_cb);
}