Ejemplo n.º 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
}
/******************************************************************************
 * 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");
}
Ejemplo n.º 3
0
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden)
{
    _useApMode = true;
    if(_useClientMode) {
        // turn on AP+STA mode
        _mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        _mode(WIFI_AP);
    }

    if(!ssid || *ssid == 0 || strlen(ssid) > 31) {
        // fail SSID too long or missing!
        return;
    }

    if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        return;
    }

    struct softap_config conf;
    wifi_softap_get_config(&conf);
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
    conf.channel = channel;
    conf.ssid_len = strlen(ssid);
    conf.ssid_hidden = ssid_hidden;
    conf.max_connection = 4;
    conf.beacon_interval = 100;

    if (!passphrase || strlen(passphrase) == 0)
    {
        conf.authmode = AUTH_OPEN;
        *conf.password = 0;
    }
    else
    {
        conf.authmode = AUTH_WPA2_PSK;
        strcpy(reinterpret_cast<char*>(conf.password), passphrase);
    }

    struct softap_config conf_current;
    wifi_softap_get_config(&conf_current);
    if (softap_config_equal(conf, conf_current))
    {
        DEBUGV("softap config unchanged");
        return;
    }

    ETS_UART_INTR_DISABLE();
    if (_persistent)
        wifi_softap_set_config(&conf);
    else
        wifi_softap_set_config_current(&conf);
    ETS_UART_INTR_ENABLE();
}
Ejemplo n.º 4
0
//Set wifi channel for AP mode
CgiStatus ICACHE_FLASH_ATTR cgiWiFiSetChannel(HttpdConnData *connData) {

	int len;
	char buff[64];

	if (connData->isConnectionClosed) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	len=httpdFindArg(connData->getArgs, "ch", buff, sizeof(buff));
	if (len!=0) {
		int channel = atoi(buff);
		if (channel > 0 && channel < 15) {
			httpd_printf("cgiWifiSetChannel: %s\n", buff);
			struct softap_config wificfg;
			wifi_softap_get_config(&wificfg);
			wificfg.channel = (uint8)channel;
			wifi_softap_set_config(&wificfg);
		}
	}
	httpdRedirect(connData, "/wifi");


	return HTTPD_CGI_DONE;
}
Ejemplo n.º 5
0
void ICACHE_FLASH_ATTR get_wifi2_mesh_ap_status(const int8_t cid,
	const GetWifi2MeshAPStatus *data) {
		uint8_t mac[6];
		struct ip_info info_ipv4;
		struct softap_config config_ap;

		os_bzero(&gw2masr.header, sizeof(gw2masr.header));

		gw2masr.header = data->header;
		gw2masr.header.length = sizeof(GetWifi2MeshAPStatusReturn);

		if((wifi_softap_get_config(&config_ap)) && (wifi_get_ip_info(SOFTAP_IF, &info_ipv4)) \
		&& (wifi_get_macaddr(SOFTAP_IF, mac))) {
			os_bzero(gw2masr.ssid, sizeof(gw2masr.ssid));
			os_memcpy(gw2masr.ssid, config_ap.ssid, sizeof(config_ap.ssid));

			os_bzero(gw2masr.ip, sizeof(gw2masr.ip));
			os_memcpy(gw2masr.ip, (uint8_t *)&info_ipv4.ip.addr, sizeof(info_ipv4.ip.addr));

			os_bzero(gw2masr.sub, sizeof(gw2masr.sub));
			os_memcpy(gw2masr.sub, (uint8_t *)&info_ipv4.netmask.addr, sizeof(info_ipv4.ip.addr));

			os_bzero(gw2masr.gw, sizeof(gw2masr.gw));
			os_memcpy(gw2masr.gw, (uint8_t *)&info_ipv4.gw.addr, sizeof(info_ipv4.ip.addr));

			os_bzero(gw2masr.mac, sizeof(gw2masr.mac));
			os_memcpy(gw2masr.mac, mac, sizeof(mac));
		}

		com_send(&gw2masr, sizeof(GetWifi2MeshAPStatusReturn), cid);
}
Ejemplo n.º 6
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.º 7
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));
}
Ejemplo n.º 8
0
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();
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
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
}
Ejemplo n.º 11
0
// Lua: ip = wifi.ap.dhcp.config()
static int wifi_ap_dhcp_config( lua_State* L )
{
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  struct dhcps_lease lease;
  uint32_t ip;

  ip = parse_key(L, "start");
  if (ip == 0)
    return luaL_error( L, "wrong arg type" );

  lease.start_ip = ip;
  NODE_DBG(IPSTR, IP2STR(&lease.start_ip));
  NODE_DBG("\n");

  // use configured max_connection to determine end
  struct softap_config config;
  wifi_softap_get_config(&config);
  lease.end_ip = lease.start_ip;
  ip4_addr4(&lease.end_ip) += config.max_connection - 1;

  char temp[64];
  c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
  lua_pushstring(L, temp);
  c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
  lua_pushstring(L, temp);

  // note: DHCP max range = 101 from start_ip to end_ip
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_lease(&lease);
  wifi_softap_dhcps_start();

  return 2;
}
Ejemplo n.º 12
0
/**
 * Setup administrative access to the AirCore module
 */
LOCAL void ICACHE_FLASH_ATTR esp_wifi_setup_apmode_connection( struct softap_config *admin_config )
{
    uint8_t ap_auth = AUTH_WPA_WPA2_PSK;
    uint8_t ap_hidden = 0x00;
    char ap_ssid[ WIFI_SSID_LENGTH ] = WIFI_AP_SSID;
	char ap_password[ WIFI_PASSWORD_LENGTH ] = WIFI_AP_PASSWORD;
    
    // retrieve current configuration
    wifi_softap_get_config( admin_config );
    // check for stored SSID in flash
    /*if( esp_flash_read_parameter( ESP_WIFI_APMODE_SECURITY_ID, &ap_auth ) == 0x00 )
    {
        // save parameters in flash
        esp_flash_save_parameter( ESP_WIFI_APMODE_SECURITY_ID, &ap_auth, 1 );
        esp_flash_save_parameter( ESP_WIFI_APMODE_HIDDEN_ID, &ap_hidden, 1 );
        esp_flash_save_parameter( ESP_WIFI_SSID_APMODE_ID, ap_ssid, os_strlen( ap_ssid ) );
        esp_flash_save_parameter( ESP_WIFI_PASSWORD_APMODE_ID, ap_password, os_strlen( ap_password ) );
    } else {
        // read parameters
        esp_flash_read_parameter( ESP_WIFI_APMODE_HIDDEN_ID, &ap_hidden );
        esp_flash_read_parameter( ESP_WIFI_SSID_APMODE_ID, ap_ssid );
        esp_flash_read_parameter( ESP_WIFI_PASSWORD_APMODE_ID, ap_password );    
    }*/
    // set wifi authentication mode
	admin_config->authmode = ap_auth;
    admin_config->ssid_hidden = ap_hidden;
    admin_config->ssid_len = 0;
    // configure AP settings
	os_memset( admin_config->ssid, 0x00, WIFI_SSID_LENGTH );
	os_memcpy( admin_config->ssid, ap_ssid, admin_config->ssid_len = os_strlen( ap_ssid ) );
	os_memset( admin_config->password, 0x00, WIFI_PASSWORD_LENGTH );
	os_memcpy( admin_config->password, ap_password, os_strlen( ap_password ) );
}
Ejemplo n.º 13
0
void user_init(void) {
	char * ap = "SKUNKWILLEM";
	char * pass = "******";
	uart_init(BIT_RATE_115200, uart_receive, false);
	system_set_os_print(1);
	os_printf("\nUart init done... \n");


	wifi_softap_get_config(&apconf);
	memset(apconf.ssid, 0, 32);
	memset(apconf.password, 0, 64);

	os_strncpy((char*)apconf.ssid, ap, 32);
	os_strncpy((char*)apconf.password, pass, 64);
	apconf.authmode = AUTH_WPA_WPA2_PSK;
	apconf.max_connection = 5;
	apconf.ssid_hidden = 0;
	wifi_softap_set_config(&apconf);


	IP4_ADDR(&IpInfo.gw, 192, 168, 10, 1);
	IP4_ADDR(&IpInfo.ip, 192, 168, 10, 1);
	IP4_ADDR(&IpInfo.netmask, 255, 255, 255, 0);
	wifi_softap_dhcps_stop();
	dhcps_start(&IpInfo);
	wifi_set_ip_info(0x01, &IpInfo);


	os_timer_disarm(&waitTimer);
	os_timer_setfn(&waitTimer, init_udp, NULL);
	os_timer_arm(&waitTimer, 2000, 0);

}
Ejemplo n.º 14
0
/**
  * @brief  Setup commad of module as wifi ap.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCwsap(uint8_t id, char *pPara)
{
  char temp[64];
  int8_t len;
  struct softap_config apConfig;

  wifi_softap_get_config(&apConfig);

  if(at_wifiMode == STATION_MODE)
  {
    at_backError;
    return;
  }
  pPara++;
  len = at_dataStrCpy(apConfig.ssid, pPara, 32);
  if(len < 1)
  {
    uart0_sendStr("ssid ERROR\r\n");
    return;
  }
  pPara += (len+3);
  len = at_dataStrCpy(apConfig.password, pPara, 64);
  if(len < 8)
  {
    uart0_sendStr("pwd ERROR\r\n");
    return;
  }
  pPara += (len+3);
  apConfig.channel = atoi(pPara);
  if(apConfig.channel<1 || apConfig.channel>13)
  {
    uart0_sendStr("ch ERROR\r\n");
    return;
  }
  pPara++;
  pPara = strchr(pPara, ',');
  pPara++;
  apConfig.authmode = atoi(pPara);
  if(apConfig.authmode >= 5)
  {
    uart0_sendStr("s ERROR\r\n");
    return;
  }
//  os_sprintf(temp,"%s,%s,%d,%d\r\n",
//             apConfig.ssid,
//             apConfig.password,
//             apConfig.channel,
//             apConfig.authmode);
//  uart0_sendStr(temp);
  ETS_UART_INTR_DISABLE();
  wifi_softap_set_config(&apConfig);
  ETS_UART_INTR_ENABLE();
  at_backOk;
//  system_restart();
}
Ejemplo n.º 15
0
/**
 * Get the configured(Not-In-Flash) softAP SSID name.
 * @return String SSID.
 */
String ESP8266WiFiAPClass::softAPSSID() const {
	struct softap_config config;
	wifi_softap_get_config(&config);
	char* name = reinterpret_cast<char*>(config.ssid);
	char ssid[sizeof(config.ssid) + 1];
	memcpy(ssid, name, sizeof(config.ssid));
	ssid[sizeof(config.ssid)] = '\0';

	return String(ssid);
}
Ejemplo n.º 16
0
void ICACHE_FLASH_ATTR nixieSetSoftAP() {
        static struct softap_config config;
        wifi_softap_get_config(&config);
        INFO("Current SOFTAP APName: %s\n",config.ssid);
        os_sprintf(config.ssid,"Nixie_%08X", system_get_chip_id());
        config.ssid_len=os_strlen(config.ssid);
        wifi_softap_set_config(&config);
        INFO("New SOFTAP APName: %s\n",config.ssid);
        wifi_set_opmode(3);
}
Ejemplo n.º 17
0
/**
 * Get the configured(Not-In-Flash) softAP PSK or PASSWORD.
 * @return String psk.
 */
String ESP8266WiFiAPClass::softAPPSK() const {
	struct softap_config config;
	wifi_softap_get_config(&config);
	char* pass = reinterpret_cast<char*>(config.password);
	char psk[sizeof(config.password) + 1];
	memcpy(psk, pass, sizeof(config.password));
	psk[sizeof(config.password)] = '\0';

	return String(psk);
}
Ejemplo n.º 18
0
// Lua: wifi.ap.config(table)
static int wifi_ap_config( lua_State* L )
{
  struct softap_config config;
  size_t len;
  wifi_softap_get_config(&config);
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  lua_getfield(L, 1, "ssid");
  if (!lua_isnil(L, -1)){  /* found? */
    if( lua_isstring(L, -1) )   // deal with the ssid string
    {
      const char *ssid = luaL_checklstring( L, -1, &len );
      if(len>32)
        return luaL_error( L, "ssid:<32" );
      c_memset(config.ssid, 0, 32);
      c_memcpy(config.ssid, ssid, len);
      config.ssid_len = len;
      config.ssid_hidden = 0;
      NODE_DBG(config.ssid);
      NODE_DBG("\n");
    } 
    else
      return luaL_error( L, "wrong arg type" );
  }
  else
    return luaL_error( L, "wrong arg type" );

  lua_getfield(L, 1, "pwd");
  if (!lua_isnil(L, -1)){  /* found? */
    if( lua_isstring(L, -1) )   // deal with the password string
    {
      const char *pwd = luaL_checklstring( L, -1, &len );
      if(len>64)
        return luaL_error( L, "pwd:<64" );
      c_memset(config.password, 0, 64);
      c_memcpy(config.password, pwd, len);
      config.authmode = AUTH_WPA_WPA2_PSK;
      NODE_DBG(config.password);
      NODE_DBG("\n");
    }
    else
      return luaL_error( L, "wrong arg type" );
  }
  else{
    config.authmode = AUTH_OPEN;
  }

  config.max_connection = 4;

  wifi_softap_set_config(&config);
  // system_restart();
  return 0;  
}
Ejemplo n.º 19
0
// Lua: wifi.ap.getconfig()
static int wifi_ap_getconfig( lua_State* L )
{
  struct softap_config config;
  wifi_softap_get_config(&config);
  lua_pushstring( L, config.ssid );
  if(config.authmode = AUTH_OPEN)
    lua_pushnil(L);
  else
    lua_pushstring( L, config.password );
  return 2;
}
Ejemplo n.º 20
0
// print various Wifi information into json buffer
int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
  int len;
    //struct station_config stconf;
    wifi_station_get_config(&stconf);
    //struct softap_config apconf;
    wifi_softap_get_config(&apconf);

    uint8_t op = wifi_get_opmode() & 0x3;
    char *mode = wifiMode[op];
    char *status = "unknown";
    int st = wifi_station_get_connect_status();
    if (st >= 0 && st < sizeof(connStatuses)) status = connStatuses[st];
    int p = wifi_get_phy_mode();
    char *phy = wifiPhy[p&3];
    char *warn = wifiWarn[op];
    if (op == 3) op = 4; // Done to let user switch to AP only mode from Soft-AP settings page, using only one set of warnings
    char *apwarn = wifiWarn[op];
    char *apauth = apAuthMode[apconf.authmode];
    sint8 rssi = wifi_station_get_rssi();
    if (rssi > 0) rssi = 0;
    uint8 mac_addr[6];
    uint8 apmac_addr[6];
    wifi_get_macaddr(0, mac_addr);
    wifi_get_macaddr(1, apmac_addr);
    uint8_t chan = wifi_get_channel();

    len = os_sprintf(buff,
        "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", "
        "\"phy\": \"%s\", \"rssi\": \"%ddB\", \"warn\": \"%s\",  \"apwarn\": \"%s\", "
        "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", "
        "\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", "
        "\"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
        mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn,
        mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5],
        chan, (char*)apconf.ssid, (char*)apconf.password, apconf.channel, apconf.max_connection,
        apconf.ssid_hidden?"enabled":"disabled", apconf.beacon_interval,
        apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4],
        apmac_addr[5]);

    struct ip_info info;
    if (wifi_get_ip_info(0, &info)) {
        len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", IP2STR(&info.ip.addr));
        len += os_sprintf(buff+len, ", \"netmask\": \"%d.%d.%d.%d\"", IP2STR(&info.netmask.addr));
        len += os_sprintf(buff+len, ", \"gateway\": \"%d.%d.%d.%d\"", IP2STR(&info.gw.addr));
        len += os_sprintf(buff+len, ", \"hostname\": \"%s\"", flashConfig.hostname);
    } else {
        len += os_sprintf(buff+len, ", \"ip\": \"-none-\"");
    }
    len += os_sprintf(buff+len, ", \"staticip\": \"%d.%d.%d.%d\"", IP2STR(&flashConfig.staticip));
    len += os_sprintf(buff+len, ", \"dhcp\": \"%s\"", flashConfig.staticip > 0 ? "off" : "on");

    return len;
}
Ejemplo n.º 21
0
void ICACHE_FLASH_ATTR setup_ap() {
    setup_ap_ip();

    // Set STATION+AP mode
    wifi_set_opmode(STATIONAP_MODE);

    // Store MAC address
    wifi_get_macaddr(SOFTAP_IF, macaddr);
    char macstr[255];
    os_sprintf(macstr, MACSTR, MAC2STR(macaddr));
    //ets_uart_printf("Got mac addr %s\r\n", macstr);

    // Set AP info
    char ssid[32];
    os_sprintf(ssid, "Maia Setup 0x%x", DEVICE_ID);
    char password[64] = "heyamaia";

    // Create config struct
    struct softap_config apConfig;
    wifi_softap_get_config(&apConfig);

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

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

    // Set AP options
    apConfig.authmode = AUTH_WPA_WPA2_PSK;
    apConfig.channel = 7;
    apConfig.ssid_hidden = 0;
    apConfig.ssid_len = 0;
    apConfig.max_connection = 255;

    // Use config struct
    wifi_softap_set_config(&apConfig);
    //print("Set AP info");

    /* char info[1024]; */
    /* os_sprintf(info,"OPMODE: %u, SSID: %s, PASSWORD: %s, CHANNEL: %d, AUTHMODE: %d, MACADDRESS: %s\r\n", */
    /*         wifi_get_opmode(), */
    /*         apConfig.ssid, */
    /*         apConfig.password, */
    /*         apConfig.channel, */
    /*         apConfig.authmode, */
    /*         macstr); */
    //ets_uart_printf(info);

    wifi_station_scan(NULL, wifi_scan_done);
    mode = MODE_AP;
}
Ejemplo n.º 22
0
 // setMode must be called with AccessPoint or ClientAndAccessPoint
 // note: make sure there is enough stack space free otherwise mail cause reset (fatal exception)!
 // channel: 1..13
 void STC_FLASHMEM WiFi::configureAccessPoint(char const* SSID, char const* securityKey, uint8_t channel, SecurityProtocol securityProtocol, bool hiddenSSID)
 {						
     softap_config config = {0};
     wifi_softap_get_config(&config);
     f_strcpy((char *)config.ssid, SSID);
     config.ssid_len = f_strlen(SSID);
     f_strcpy((char *)config.password, securityKey);
     config.channel = channel;
     config.authmode = (AUTH_MODE)securityProtocol;
     config.ssid_hidden = (uint8)hiddenSSID;
     Critical critical;
     wifi_softap_set_config(&config);
 }
Ejemplo n.º 23
0
LOCAL void ICACHE_FLASH_ATTR
user_socket_probe_rx(void *arg, char *pusrdata, unsigned short length)
{
	struct softap_config apConfig;
    char DeviceBuffer[40] = {0};
    char Device_mac_buffer[60] = {0};
    char hwaddr[6];

    if (pusrdata == NULL) {
        return;
    }	
	wifi_softap_get_config(&apConfig);
	espconn_sent(&ptresp_probe, apConfig.ssid, os_strlen(apConfig.ssid));
}
Ejemplo n.º 24
0
void setap(char * ssid, int len) {
    static struct softap_config apconf;
    wifi_set_opmode(STATIONAP_MODE);
    wifi_softap_get_config(&apconf);
    memset(apconf.ssid, 0, 32);
    strncpy((char*) apconf.ssid, ssid, 32);
    apconf.authmode = AUTH_OPEN;
    apconf.max_connection = 20;
    apconf.ssid_hidden = 0;
    apconf.ssid_len = strlen(ssid);
    apconf.channel = 1;

    wifi_softap_set_config(&apconf);
}
Ejemplo n.º 25
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.º 26
0
/************************************************
*	name:			user_init
*	parameters:		none
*	return value:	none
*	purpose:		main logic
************************************************/
void user_init(void)
{	
	/* initialization */
	struct softap_config 	tWifiSettings = { 0 };
	uint8 					puMacAddress[6] = { 0 };

	os_memset((void *)&tWifiSettings, 0, sizeof(tWifiSettings));

	wifi_softap_get_config(&tWifiSettings);
	
	/* retrieve mac address */
	wifi_get_macaddr(1, puMacAddress);
	
	/* append to ssid name */
	memcpy(tWifiSettings.ssid, HOTSPOT_SSID_STRING, sizeof(HOTSPOT_SSID_STRING));

	os_sprintf(tWifiSettings.ssid + sizeof(HOTSPOT_SSID_STRING) - 1, "%x%x%x%x%x%x", puMacAddress[0],
							  												  	 	 puMacAddress[1],
							  												  	 	 puMacAddress[2],
							  												  	 	 puMacAddress[3],
							  												  	 	 puMacAddress[4],
							  												  	 	 puMacAddress[5]);
	/* set password */
	memcpy(tWifiSettings.password, HOTSPOT_PASSWORD_STRING, os_strlen(HOTSPOT_PASSWORD_STRING));
	
	/* update other settings */
	tWifiSettings.authmode = AUTH_WPA_WPA2_PSK;
	tWifiSettings.ssid_len = 0;
	tWifiSettings.channel = 6;
	tWifiSettings.max_connection = 4;
	
	/* update wifi configuration */
	wifi_softap_set_config(&tWifiSettings);
	
	/* initialize stdout */
	stdoutInit();
	
	/* initialize IOs */
	ioInit();
	
	/* initialize server */
	httpdInit(g_ptSupportedUrls, 80);
	
#ifdef USER_MAIN_DEBUG
	os_printf("user_init: ready; partition %d\n", system_upgrade_userbin_check());
#endif
}
Ejemplo n.º 27
0
LOCAL void ICACHE_FLASH_ATTR setup_ap_mode() {
	wifi_station_disconnect();
	wifi_station_dhcpc_stop();

	wifi_set_opmode(SOFTAP_MODE);

	struct softap_config apconfig;

	if (wifi_softap_get_config(&apconfig)) {
		wifi_softap_dhcps_stop();
		char macaddr[6];
		wifi_get_macaddr(SOFTAP_IF, macaddr);

		os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		os_memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, "MacGyver-IoT_%02x%02x%02x%02x%02x%02x", MAC2STR(macaddr));
		//os_sprintf(apconfig.password, "%02x%02x%02x%02x%02x%02x", MAC2STR(macaddr)); // 18fe349bc6b6
		//os_sprintf(apconfig.password, "test"); // 18fe349bc6b6
		//apconfig.authmode = AUTH_WPA_WPA2_PSK; // AUTH_OPEN
		apconfig.authmode = AUTH_OPEN;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 10;

		if (!wifi_softap_set_config(&apconfig)) {
			// CTRL not set AP config!
		}

		struct ip_info ipinfo;
		if (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);
			if (!wifi_set_ip_info(SOFTAP_IF, &ipinfo)) {
				// CTRL not set IP config!
			}
		}

		wifi_softap_dhcps_start();

	}

	if (wifi_get_phy_mode() != PHY_MODE_11N)
		wifi_set_phy_mode(PHY_MODE_11N);

}
Ejemplo n.º 28
0
void wifi_init(void) {

    struct softap_config config;

    wifi_set_opmode(STATIONAP_MODE);
    wifi_softap_get_config(&config); // Get config first.

    memset(config.ssid, 0, 32);
    memset(config.password, 0, 64);
    memcpy(config.ssid, "Indoorio Beta", 13);
    memcpy(config.password, "12345678", 8);
    config.authmode = AUTH_WPA_WPA2_PSK;
    config.ssid_len = 0;// or its actual length
    config.max_connection = 4; // how many stations can connect to ESP8266 softAP at most.

    wifi_softap_set_config(&config);// Set ESP8266 softap config .
}
Ejemplo n.º 29
0
void initslave(){
	char * ap = CLIENT_AP;
	char * pass = MASTER_PASSWORD;
	wifi_set_opmode(STATION_MODE);
	wifi_softap_get_config(&apconf);
	os_strncpy((char*)apconf.ssid, ap, 32);
	os_strncpy((char*)apconf.password, pass, 64);
	apconf.authmode = AUTH_WPA_WPA2_PSK;
	apconf.max_connection = 20;
	apconf.ssid_hidden = 0;
	wifi_softap_set_config(&apconf);
	scan_slave();
	reg_addlistener(callback_slave, 0x32);

	os_timer_setfn(&watchdog_slave, (os_timer_func_t *)slave_sendalive, NULL);
	os_timer_arm(&watchdog_slave, 2000, 0);
}
Ejemplo n.º 30
0
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel)
{
    if(_useClientMode) {
        // turn on AP+STA mode
        mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        mode(WIFI_AP);
    }

    if(!ssid || strlen(ssid) > 31) {
        // fail SSID to long or missing!
        return;
    }

    if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        return;
    }

    struct softap_config conf;
    wifi_softap_get_config(&conf);
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
    conf.channel = channel;
    conf.ssid_len = strlen(ssid);
    conf.ssid_hidden = 0;
    conf.max_connection = 4;
    conf.beacon_interval = 100;

    if (!passphrase || strlen(passphrase) == 0)
    {
        conf.authmode = AUTH_OPEN;
        *conf.password = 0;
    }
    else
    {
        conf.authmode = AUTH_WPA2_PSK;
        strcpy(reinterpret_cast<char*>(conf.password), passphrase);
    }

    ETS_UART_INTR_DISABLE();
    wifi_softap_set_config(&conf);
    ETS_UART_INTR_ENABLE();
}