Ejemplo n.º 1
3
void user_init(void)
{
	// Configure the UART
	uart_init(BIT_RATE_115200,0);
	// Enable system messages
	system_set_os_print(1);
	os_printf("\r\nSDK version: %s\n", system_get_sdk_version());
	os_printf("System init...\r\n");

	os_printf("ESP8266 is %s mode, restarting in %s mode...\r\n", WiFiMode[wifi_get_opmode()], WiFiMode[STATION_MODE]);
	setup_wifi_st_mode();
	if(wifi_get_phy_mode() != PHY_MODE_11N)
		wifi_set_phy_mode(PHY_MODE_11N);
	if(wifi_station_get_auto_connect() == 0)
		wifi_station_set_auto_connect(1);

	// Init DHT22 sensor
	DHTInit(DHT22);

	// Wait for Wi-Fi connection
	os_timer_disarm(&WiFiLinker);
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, 1000, 0);

	// Set up a timer to send the message
	os_timer_disarm(&dht22_timer);
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DATA_SEND_DELAY, 1);

	os_printf("System init done.\n");
}
Ejemplo n.º 2
0
void ICACHE_FLASH_ATTR WIFI_Connect(WifiCallback cb)
{
	struct station_config stationConf;
	struct ip_info info;

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

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

	os_sprintf((char *)stationConf.ssid, "%s", sysCfg.sta_ssid);
	os_sprintf((char *)stationConf.password, "%s", sysCfg.sta_pass);

	wifi_get_ip_info(STATION_IF, &info);
	char *dhcp = (char *)sysCfg.sta_mode; 
	char *ip, *mask, *gw;
	if (!dhcp || os_strcmp(dhcp, "dhcp") != 0)
	{
		ip = (char *)sysCfg.sta_ip; 
		mask = (char *)sysCfg.sta_mask;
		gw = (char *)sysCfg.sta_gw;
		if (ip)
			info.ip.addr = ipaddr_addr(ip);
		if (mask)
			info.netmask.addr = ipaddr_addr(mask);
		if (gw)
			info.gw.addr = ipaddr_addr(gw);			
		wifi_set_ip_info(STATION_IF, &info);
	}

	wifi_get_ip_info(SOFTAP_IF, &info);
	ip = (char *)sysCfg.ap_ip; 
	mask = (char *)sysCfg.ap_mask;
	gw = (char *)sysCfg.ap_gw;
	if (ip)
		info.ip.addr = ipaddr_addr(ip);
	if (mask)
		info.netmask.addr = ipaddr_addr(mask);
	if (gw)
		info.gw.addr = ipaddr_addr(gw);
	
	if (wifi_get_opmode() != STATION_MODE)
		wifi_set_ip_info(SOFTAP_IF, &info);


	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);
	wifi_station_connect();
	
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
void setup() {
  pinMode(LDR, INPUT);
  pinMode(BUTTON, INPUT);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

  delay(1000);
  Serial.begin(115200);

  Serial.println("Wifi Connecting");

  WiFi.begin(wifiSSID, wifiPassword);
  wifi_station_set_auto_connect(true);
  wifi_station_set_hostname(wiFiHostname);
  wifiConnectCounter = 1;
  while (WiFi.status() != WL_CONNECTED) {
    delay(wifiRepeatInterval);
    wifiConnectCounter++;
    if (wifiConnectCounter > wifiMaxTries) {
      delay(wifiRepeatInterval * 1000 * 1000);
      wifiConnectCounter = 0;
    }
  }
  Serial.println("Wifi Connected");

  server.on("/", handleRoot);
  server.begin();
}
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);
}
Ejemplo n.º 7
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);

    
}
Ejemplo n.º 8
0
void ICACHE_FLASH_ATTR setup_station(char ssid[], char password[]) {
    // Stop previous connection
    wifi_station_disconnect();
    wifi_station_dhcpc_stop();

    // Create config struct
    struct station_config staConfig;
    wifi_station_get_config(&staConfig);

    // Set SSID in struct
    os_memset(staConfig.ssid, 0, sizeof(staConfig.ssid));
    os_memcpy(staConfig.ssid, ssid, os_strlen(ssid));

    // Set Password in struct
    os_memset(staConfig.password, 0, sizeof(staConfig.password));
    os_memcpy(staConfig.password, password, os_strlen(password));

    // Use config struct
    wifi_station_set_config(&staConfig);
    //print("Set Station info");
    wifi_station_connect();
    wifi_station_dhcpc_start();
    wifi_station_set_auto_connect(1);

    connection_status = CONNECTION_CONNECTING;
}
Ejemplo n.º 9
0
/**
 * Setting the ESP8266 station to connect to the AP (which is recorded)
 * automatically or not when powered on. Enable auto-connect by default.
 * @param autoConnect bool
 * @return if saved
 */
bool ESP8266WiFiSTAClass::setAutoConnect(bool autoConnect) {
    bool ret;
    ETS_UART_INTR_DISABLE();
    ret = wifi_station_set_auto_connect(autoConnect);
    ETS_UART_INTR_ENABLE();
    return ret;
}
Ejemplo n.º 10
0
static void ICACHE_FLASH_ATTR ost_wifi_setup(os_event_t *events){
	os_printf("WiFi Setup...\n");
	uint8_t stationStatus = wifi_station_get_connect_status();
	//Handle status
	wifi_station_set_auto_connect(TRUE);
	wifi_setup(&ssid,&pass, STATION_MODE);
}
Ejemplo n.º 11
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
}
Ejemplo n.º 12
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
  wifi_station_set_auto_connect(FALSE); 
	stdoutInit();
  CFG_Load();
	ioInit();	     
  
  MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n");	
  stack_init();  

  /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */
  captdnsInit(); 

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
  #ifdef ESPFS_POS
    espFsInit((void*)(0x40200000 + ESPFS_POS));
  #else
    espFsInit((void*)(webpages_espfs_start));
  #endif
  httpdInit(builtInUrls, 80);
  #ifdef SHOW_HEAP_USE
    os_timer_disarm(&prHeapTimer);
    os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
    os_timer_arm(&prHeapTimer, 3000, 1);
  #endif
  os_timer_disarm(&websockTimer);
  os_timer_setfn(&websockTimer, websockTimerCb, NULL);
  os_timer_arm(&websockTimer, 1000, 1);
  
  os_printf("\nReady\n");	
}
Ejemplo n.º 13
0
static int do_wifi(const struct sys_config *cfg) {
  int result = 1;
  int gpio = cfg->wifi.ap.trigger_on_gpio;
  int trigger_ap = 0;

  wifi_set_opmode_current(STATION_MODE);
  wifi_station_set_auto_connect(0);
  wifi_station_disconnect();

  if (gpio >= 0) {
    sj_gpio_set_mode(gpio, GPIO_MODE_INPUT, GPIO_PULL_PULLUP);
    trigger_ap = sj_gpio_read(gpio) == GPIO_LEVEL_HIGH;
  }

  if (!trigger_ap && cfg->wifi.ap.mode == 2 && cfg->wifi.sta.enable) {
    wifi_set_opmode_current(STATIONAP_MODE);
    result =
        sj_wifi_setup_ap(&cfg->wifi.ap) ? sj_wifi_setup_sta(&cfg->wifi.sta) : 0;
  } else if (!trigger_ap && cfg->wifi.sta.enable) {
    wifi_set_opmode_current(STATION_MODE);
    result = sj_wifi_setup_sta(&cfg->wifi.sta);
  } else if (trigger_ap || cfg->wifi.ap.mode > 0) {
    wifi_set_opmode_current(SOFTAP_MODE);
    result = sj_wifi_setup_ap(&cfg->wifi.ap);
  } else {
    LOG(LL_WARN, ("No wifi mode specified"));
  }

  return result;
}
Ejemplo n.º 14
0
// Lua: wifi.sta.config(ssid, password)
static int wifi_station_config( lua_State* L )
{
  size_t sl, pl;
  struct station_config sta_conf;
  int i;
  const char *ssid = luaL_checklstring( L, 1, &sl );
  if (sl>32 || ssid == NULL)
    return luaL_error( L, "ssid:<32" );
  const char *password = luaL_checklstring( L, 2, &pl );
  if (pl>64 || password == NULL)
    return luaL_error( L, "pwd:<64" );

  c_memset(sta_conf.ssid, 0, 32);
  c_memset(sta_conf.password, 0, 64);
  c_memset(sta_conf.bssid, 0, 6);
  c_memcpy(sta_conf.ssid, ssid, sl);
  c_memcpy(sta_conf.password, password, pl);
  sta_conf.bssid_set = 0;

  NODE_DBG(sta_conf.ssid);
  NODE_DBG(" %d\n", sl);
  NODE_DBG(sta_conf.password);
  NODE_DBG(" %d\n", pl);

  wifi_station_set_config(&sta_conf);
  wifi_station_set_auto_connect(true);
  wifi_station_disconnect();
  wifi_station_connect();
  // station_check_connect(0);
  return 0;  
}
Ejemplo n.º 15
0
void ICACHE_FLASH_ATTR user_init(void) {
	stdout_init();
	gpio_init();
	wifi_station_disconnect();
	wifi_station_set_auto_connect(false);
	wifi_station_set_reconnect_policy(false);

	system_init_done_cb(&initDone_cb);
}
Ejemplo n.º 16
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{	
	user_gpio_init();
	uart_init(115200,115200);
	//system_timer_reinit();
	//wifi_set_sleep_type(MODEM_SLEEP_T);
    os_printf("\n\nHFWiFiMode version:%s\n",HFWIFIMODE);
	wifi_station_set_auto_connect(1);
    user_esp_platform_init();
}
Ejemplo n.º 17
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
	UART_WaitTxFifoEmpty(0,50000);
	uart_init(74880,74880);
	user_DispAppInfo();

	wifi_set_opmode(STATIONAP_MODE);
	#if ESP_MESH_SUPPORT
    	wifi_station_set_auto_connect(0);
    	wifi_station_disconnect();
	#else
    	wifi_station_set_auto_connect(1);
	#endif
    os_printf("SDK version:%s\n", system_get_sdk_version());
	wifi_station_ap_number_set(AP_CACHE_NUMBER);
	   
	system_init_done_cb(light_main_flow);

}
Ejemplo n.º 18
0
void ICACHE_FLASH_ATTR user_init(void) {
	uart_init(115200, 115200);
//	stdout_init();
	gpio_init();
	wifi_station_set_auto_connect(false); // Needs to be in user_init to apply to this session

	savedLastAction = lastAction;

	easygpio_pinMode(LED, EASYGPIO_PULLUP, EASYGPIO_OUTPUT);
	easygpio_outputSet(LED, 1);
	system_init_done_cb(&startUp);
}
Ejemplo n.º 19
0
static void wifi_connect() {
  struct station_config conf;
  wifi_station_set_auto_connect(FALSE);
  wifi_set_event_handler_cb(wifi_change_cb);
  strcpy((char *) conf.ssid, NETWORK_SSID);
  strcpy((char *) conf.password, NETWORK_PWD);
  printf("connecting to %s\n", conf.ssid);
  conf.bssid_set = 0;
  wifi_set_opmode_current(STATION_MODE);
  wifi_station_disconnect();
  wifi_station_set_config_current(&conf);
  wifi_station_connect();
}
Ejemplo n.º 20
0
// Lua: wifi.sta.auto(true/false)
static int wifi_station_setauto( lua_State* L )
{
  unsigned a;
  
  a = luaL_checkinteger( L, 1 );

  if ( a != 0 && a != 1 )
    return luaL_error( L, "wrong arg type" );
  wifi_station_set_auto_connect(a);
  if(a){
    // station_check_connect(0);
  }
  return 0;  
}
Ejemplo n.º 21
0
void ICACHE_FLASH_ATTR 
user_sta_init(void)
{
	if(wifi_get_opmode() != STATION_MODE) 
	{
		os_printf("Setting STATION_MODE\n");
		wifi_set_opmode(STATION_MODE);
	}

	wifi_station_set_auto_connect(0);
	user_sta_setup_config(); 

    //os_printf("Wifi physical level mode: %d \n", (int) wifi_get_phy_mode());
}
Ejemplo n.º 22
0
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(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);
	wifi_station_connect();
}
Ejemplo n.º 23
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "setAutoConnect",
  "generate" : "jswrap_ESP8266WiFi_setAutoConnect",
  "params"   : [
    ["autoconnect","JsVar","True if we wish to auto connect."]
  ]
}*/
void jswrap_ESP8266WiFi_setAutoConnect(
    JsVar *autoconnect //!< True if we wish to auto connect.
  ) {
  os_printf("Auto connect is: %d\n", (int)autoconnect);
  // Check that we have been passed a boolean ... if not, nothing to do here.
  if (!jsvIsBoolean(autoconnect)) {
    return;
  }

  uint8 newValue = jsvGetBool(autoconnect);
  os_printf("New value: %d\n", newValue);

  wifi_station_set_auto_connect(newValue);
  os_printf("Autoconnect changed\n");
}
Ejemplo n.º 24
0
void ICACHE_FLASH_ATTR wifiInit(int wifiMode)
{
INFO("\r===== WiFi Init =====\r");

wifi_set_opmode(0); // Clear all modes
INFO("\r\nSetting WiFI\r\n");

if(wifiMode & SOFTAP_MODE)
	{
	INFO("\rSetting SOFTAP Mode\r\n");
	setup_wifi_ap_mode();
	INFO("Done\r\n");
	}

if(wifiMode & STATION_MODE)
	{
	INFO("\rSetting Station Mode \r\n");
	setup_wifi_st_mode();
	INFO("Done\r\n");
	}

if(wifi_get_phy_mode() != PHY_MODE_11N)
	wifi_set_phy_mode(PHY_MODE_11N);
if(wifi_station_get_auto_connect() == 0)
	wifi_station_set_auto_connect(1);

INFO("Wi-Fi mode: %s\r\n", WiFiMode[wifi_get_opmode()]);
if(wifiMode & SOFTAP_MODE)
	{
	struct softap_config apConfig;
	if(wifi_softap_get_config(&apConfig))
		{
		INFO("AP config: SSID: %s, PASSWORD: %s\r\n",
			apConfig.ssid,
			apConfig.password);
		}
	}
if(wifiMode & STATION_MODE)
	{
	struct station_config stationConfig;
	if(wifi_station_get_config(&stationConfig))
		{
		INFO("STA config: SSID: %s, PASSWORD: %s\r\n",
			stationConfig.ssid,
			stationConfig.password);
		}
	}
}
Ejemplo n.º 25
0
void ICACHE_FLASH_ATTR connectToAp() {
    char * ap = "LedAccess";
    char * pass = "******";
    wifi_set_phy_mode( PHY_MODE_11N );

    struct station_config apconf;
    wifi_station_set_auto_connect(true);
    wifi_set_opmode(STATION_MODE);
    wifi_station_get_config(&apconf);
    strncpy((char*)apconf.ssid, ap, 32);
    printf("connecting to: %s", apconf.ssid);
    strncpy((char*)apconf.password, pass, 64);
    wifi_station_set_config(&apconf);
    wifi_promiscuous_enable(1);
    //wifi_set_event_handler_cb(wifi_event_cb);
}
Ejemplo n.º 26
0
//Init function 
void ICACHE_FLASH_ATTR
user_init(void) {
  // Make uart0 work with just the TX pin. Baud:115200,n,8,1
  // The RX pin is now free for GPIO use.
  stdout_init();

  // turn off WiFi for this console only demo
  wifi_station_set_auto_connect(false);
  wifi_station_disconnect();

  // Start setup timer
  os_timer_disarm(&loop_timer);
  os_timer_setfn(&loop_timer, (os_timer_func_t *) setup, NULL);
  os_timer_arm(&loop_timer, 2000, false);

}
Ejemplo n.º 27
0
//Init function 
void ICACHE_FLASH_ATTR
user_init()
{
    char ssid[32] = "MY_SSID";
    char password[64] = "MY_PASS";
    struct station_config stationConf;
    
    os_printf("Init a\n\r");

    uart_init(BIT_RATE_115200, BIT_RATE_115200);

    gpio16_output_conf();

    gpio16_output_set(0);

    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14);
    
    gpio_output_set(0, BIT12|BIT13|BIT14, BIT12|BIT13|BIT14, 0);

    //Set station mode
    //wifi_set_macaddr(uint8 if_index, uint8 *macaddr)
    wifi_set_opmode_current( STATION_MODE );
    os_memcpy(&stationConf.ssid, ssid, 32);
    os_memcpy(&stationConf.password, password, 64);
    stationConf.bssid_set = 0;
    wifi_station_set_config_current(&stationConf);
//    wifi_status_led_install (16, uint32 gpio_name, FUNC_GPIO16)

    os_printf("Init Ok! %d\n\r", wifi_station_get_connect_status());


    wifi_station_set_auto_connect(1);

    wifi_station_connect();

    wifi_station_dhcpc_start();
    
    user_server_init(8888);

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

  //  system_os_post(user_procTaskPrio, 0, 0 );

}
Ejemplo n.º 28
0
void user_init(void) {
	gpio_init();
	stdout_init();
	easygpio_pinMode(LCD_Light, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(LCD_SCE, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(LCD_clk, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(LCD_Data, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(LCD_D_C, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(LCD_RST, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
	easygpio_pinMode(SWITCH, EASYGPIO_PULLUP, EASYGPIO_INPUT);
	easygpio_outputDisable(SWITCH);
	lcdReset();
	lightOn();
	wifi_station_set_auto_connect(false);
	wifi_station_set_reconnect_policy(true);

	system_init_done_cb(&initDone_cb);
}
Ejemplo n.º 29
0
bool StationClass::config(String ssid, String password, bool autoConnectOnStartup /* = true*/)
{
	station_config config = {0};

	if (ssid.length() >= sizeof(config.ssid)) return false;
	if (password.length() >= sizeof(config.password)) return false;

	bool enabled = isEnabled();
	bool dhcp = isEnabledDHCP();
	enable(true); // Power on for configuration

	wifi_station_disconnect();
	if (dhcp) enableDHCP(false);
	bool cfgreaded = wifi_station_get_config(&config);
	if (!cfgreaded) debugf("Can't read station configuration!");

	memset(config.ssid, 0, sizeof(config.ssid));
	memset(config.password, 0, sizeof(config.password));
	config.bssid_set = false;
	strcpy((char*)config.ssid, ssid.c_str());
	strcpy((char*)config.password, password.c_str());

	noInterrupts();
	if(!wifi_station_set_config(&config))
	{
		interrupts();
		debugf("Can't set station configuration!");
		wifi_station_connect();
		enableDHCP(dhcp);
		enable(enabled);
		return false;
	}
	debugf("Station configuration was updated to: %s", ssid.c_str());

	interrupts();
	wifi_station_connect();
	enableDHCP(dhcp);
	enable(enabled);

	wifi_station_set_auto_connect(autoConnectOnStartup);

	return true;
}
void wifi_config()
{
// Wifi configuration
  char ssid[32]     = SSID;
  char password[64] = SSID_PASSWORD;
  
  struct station_config stationConf;

  //Set station mode
  wifi_set_opmode(0x1);

  //Set ap settings
  os_memcpy(&stationConf.ssid, ssid, 32);
  os_memcpy(&stationConf.password, password, 64);
  
  stationConf.bssid_set = 0;
          
  wifi_station_set_config(&stationConf);
  wifi_station_set_auto_connect(1); 
}