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 #2
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);

	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];
	sint8 rssi = wifi_station_get_rssi();
	if (rssi > 0) rssi = 0;
	uint8 mac_addr[6];
	wifi_get_macaddr(0, mac_addr);

	len = os_sprintf(buff,
		"\"mode\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", "
		"\"rssi\": \"%ddB\", \"warn\": \"%s\", \"passwd\": \"%s\", "
		"\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
		mode, (char*)stconf.ssid, status, phy, rssi, warn, (char*)stconf.password,
		mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

	struct ip_info info;
	if (wifi_get_ip_info(0, &info)) {
		len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"",
			(info.ip.addr>>0)&0xff, (info.ip.addr>>8)&0xff,
			(info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff);
	} else {
Example #3
0
//Template code for the WLAN page.
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
	char buff[1024];
	int x;
	static struct station_config stconf;
	if (token==NULL) return;
	wifi_station_get_config(&stconf);

	os_strcpy(buff, "Unknown");
	if (os_strcmp(token, "WiFiMode")==0) {
		x=wifi_get_opmode();
		if (x==1) os_strcpy(buff, "Client");
		if (x==2) os_strcpy(buff, "SoftAP");
		if (x==3) os_strcpy(buff, "STA+AP");
	} else if (os_strcmp(token, "currSsid")==0) {
		os_strcpy(buff, (char*)stconf.ssid);
	} else if (os_strcmp(token, "WiFiPasswd")==0) {
		os_strcpy(buff, (char*)stconf.password);
	} else if (os_strcmp(token, "WiFiapwarn")==0) {
		x=wifi_get_opmode();
		if (x==2) {
			os_strcpy(buff, "<b>Can't scan in this mode.</b> Click <a href=\"setmode.cgi?mode=3\">here</a> to go to STA+AP mode.");
		} else {
			os_strcpy(buff, "Click <a href=\"setmode.cgi?mode=2\">here</a> to go to standalone AP mode.");
		}
	}
	espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
}
Example #4
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
}
Example #5
0
int ICACHE_FLASH_ATTR nixieTplWlan(HttpdConnData *connData, char *token, void **arg) {
    char buff[1024];
    int x;
    static struct station_config stconf;
    if (token==NULL) return HTTPD_CGI_DONE;
    wifi_station_get_config(&stconf);
    
    os_strcpy(buff, "Unknown");
    if (os_strcmp(token, "WiFiMode")==0) {
        x=wifi_get_opmode();
        if (x==1) os_strcpy(buff, "Client");
        if (x==2) os_strcpy(buff, "SoftAP");
        if (x==3) os_strcpy(buff, "Client+AP");
    } else if (os_strcmp(token, "currSsid")==0) {
        os_strcpy(buff, (char*)stconf.ssid);
    } else if (os_strcmp(token, "WiFiPasswd")==0) {
        os_strcpy(buff, (char*)stconf.password);
    } else if (os_strcmp(token, "DeviceID")==0) {
        uint8_t client_id[16];
        os_sprintf(client_id, "%08X", system_get_chip_id());
        os_strcpy(buff, (char*)client_id);
    } else if (os_strcmp(token, "WiFiapwarn")==0) {
        x=wifi_get_opmode();
        if (x==2) {
            os_strcpy(buff, "<b>Can't scan in this mode.</b><a href=\"setmode.cgi?mode=3\">Go to STA+AP mode.</a>");
        } else if(x==1) {
            os_strcpy(buff, "<a href=\"setmode.cgi?mode=3\">Go back to Client+AP mode.</a>");
        } else {
            os_strcpy(buff, "<a href=\"setmode.cgi?mode=1\">Go to Client Only Mode</a><br /> To reset hold Button for 5 sec and release");
        }
    }
    httpdSend(connData, buff, -1);
    return HTTPD_CGI_DONE;
}
Example #6
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;
}
Example #7
0
/**
  * @brief  Query commad of join to wifi ap.
  * @param  id: commad id number
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_queryCmdCwjap(uint8_t id)
{
  char temp[64];
  struct station_config stationConf;
  wifi_station_get_config(&stationConf);
  struct ip_info pTempIp;

  wifi_get_ip_info(0x00, &pTempIp);
  if(pTempIp.ip.addr == 0)
  {
    at_backError;
    //    os_sprintf(temp, at_backTeError, 4);
    //    uart0_sendStr(at_backTeError"4\r\n");
    return;
  }
  mdState = m_gotip;
  if(stationConf.ssid != 0)
  {
    os_sprintf(temp, "%s:\"%s\"\r\n", at_fun[id].at_cmdName, stationConf.ssid);
    uart0_sendStr(temp);
    at_backOk;
  }
  else
  {
    at_backError;
    //    os_sprintf(temp, at_backTeError, 5);
    //    uart0_sendStr(at_backTeError"5\r\n");
  }
}
Example #8
0
/**
 * Return the current bssid / mac associated with the network if configured
 * @return String bssid mac
 */
String ESP8266WiFiSTAClass::BSSIDstr(void) {
    struct station_config conf;
    char mac[18] = { 0 };
    wifi_station_get_config(&conf);
    sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", conf.bssid[0], conf.bssid[1], conf.bssid[2], conf.bssid[3], conf.bssid[4], conf.bssid[5]);
    return String(mac);
}
Example #9
0
int http_wifi_api_get_status(http_connection *c)
{
    CGI_WIFI_DBG("wifi get_status\n");

    //wait for whole body
    if(c->state <HTTPD_STATE_BODY_END) {
        return HTTPD_CGI_MORE;
    }

    api_cgi_status * status = c->cgi.data;

    //first call, send headers
    if(status==NULL)
    {
        status = (api_cgi_status*)os_malloc(sizeof(api_cgi_status));
        status->state=1;
        c->cgi.data=status;

        http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE);
        http_response_OK(c);

        return HTTPD_CGI_MORE;
    }
    else if(status->state==1)
    {
        wifi_station_get_config(&wifi_status.station_config);
        uint8_t c_status = wifi_station_get_connect_status();

        //return JSON
        cJSON *root = cJSON_CreateObject();
        cJSON_AddBoolToObject(root,"scanning",wifi_status.scanning);
        cJSON_AddStringToObject(root,"ssid",(const char *)wifi_status.station_config.ssid);
        cJSON_AddNumberToObject(root,"mode",wifi_get_opmode());
        cJSON_AddNumberToObject(root,"station_status",c_status);

        //got ip
        if(c_status==5)
        {
            struct ip_info ip;
            wifi_get_ip_info(0x0,&ip);
            char *ip_str = (char*)ipaddr_ntoa(&ip.ip);
            cJSON_AddStringToObject(root,"ip",ip_str);
        }
        else {
            cJSON_AddStringToObject(root,"ip","");
        }

        http_write_json(c,root);
        cJSON_Delete(root);

        status->state=99;
        return HTTPD_CGI_MORE;
    }
    else
    {
        os_free(c->cgi.data);
        return HTTPD_CGI_DONE;
    }
}
Example #10
0
/**
 * Return the current SSID associated with the network
 * @return SSID
 */
String ESP8266WiFiSTAClass::SSID() const {
    struct station_config conf;
    wifi_station_get_config(&conf);
    char tmp[33]; //ssid can be up to 32chars, => plus null term
    memcpy(tmp, conf.ssid, sizeof(conf.ssid));
    tmp[32] = 0; //nullterm in case of 32 char ssid
    return String(reinterpret_cast<char*>(tmp));
}
Example #11
0
/**
 * Return the current pre shared key associated with the network
 * @return  psk string
 */
String ESP8266WiFiSTAClass::psk() const {
    struct station_config conf;
    wifi_station_get_config(&conf);
    char tmp[65]; //psk is 64 bytes hex => plus null term
    memcpy(tmp, conf.password, sizeof(conf.password));
    tmp[64] = 0; //null term in case of 64 byte psk
    return String(reinterpret_cast<char*>(tmp));
}
Example #12
0
static ICACHE_FLASH_ATTR int
configure(void)
{
    char ch;
    int ret; 
    static struct station_config st_config;
    wifi_station_get_config(&st_config);
    do
    {
        printf("\r\nConfiguration:\r\n");
        printf("1: Wifi SSID [%s]\r\n", st_config.ssid);
        printf("2: Wifi Password [%s]\r\n", st_config.password);
        printf("3: HTTP host[%s]\r\n", user_config.host);
        printf("4: HTTP port[%d]\r\n", user_config.port);
        printf("5: HTTP path/query [%s]\r\n", user_config.get_cmd);
        printf("0: Exit configuration\r\n");
        // ch = uart_getchar();
        xQueueReceive(xUARTQueue, &ch, -1);
        switch (ch)
        {
        case '1':
            printf("Enter Wifi SSID: ");
            uart_gets(&xUARTQueue, st_config.ssid, 32);
            break;
        case '2':
            printf("Enter Wifi Password: "******"Enter HTTP host: ");
            uart_gets(&xUARTQueue, user_config.host, HOST_LEN+1);
            break;
        case '4':
            printf("Enter HTTP port: ");
            char buf[6];
            uart_gets(&xUARTQueue, buf, 6);
            user_config.port = atoi(buf);
            break;
        case '5':
            printf("Enter HTTP path and query string: ");
            uart_gets(&xUARTQueue, user_config.get_cmd, GET_LEN+1);
            break;
        case '0':
            DBG("setting config [%s] [%s]\n", st_config.ssid, st_config.password);
            wifi_station_set_config(&st_config);
            save_user_config(&user_config);
            break;
        default:
            printf("Invalid choice\r\n");
        }
    } while (ch != '0');
    printf("System will now restart\r\n");
    system_restart();
}
Example #13
0
String StationClass::getSSID()
{
	station_config config = {0};
	if (!wifi_station_get_config(&config))
	{
		debugf("Can't read station configuration!");
		return "";
	}
	debugf("SSID: %s", (char*)config.ssid);
	return String((char*)config.ssid);
}
Example #14
0
String StationClass::getPassword()
{
	station_config config = {0};
	if (!wifi_station_get_config(&config))
	{
		debugf("Can't read station configuration!");
		return "";
	}
	debugf("Pass: %s", (char*)config.password);
	return String((char*)config.password);
}
Example #15
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;
}
Example #16
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "getStationConfig",
  "generate" : "jswrap_ESP8266WiFi_getStationConfig",
  "return"   : ["JsVar","A Station Config"],
  "return_object" : "StationConfig"
}*/
JsVar *jswrap_ESP8266WiFi_getStationConfig() {
  struct station_config config;
  wifi_station_get_config(&config);
  JsVar *jsConfig = jspNewObject(NULL, "StationConfig");
  //char ssid[33];
  //nullTerminateString(ssid, (char *)config.ssid, 32);
  jsvUnLock(jsvObjectSetChild(jsConfig, "ssid", jsvNewFromString((char *)config.ssid)));
  //char password[65];
  //nullTerminateString(password, (char *)config.password, 64);
  jsvUnLock(jsvObjectSetChild(jsConfig, "password", jsvNewFromString((char *)config.password)));
  return jsConfig;
}
Example #17
0
void ICACHE_FLASH_ATTR
user_sta_setup_config(void)
{
	// Build our Access Point configuration details
	struct station_config config; 
	wifi_station_get_config(&config);

	os_memset(config.ssid, 0, 32);
	os_memset(config.password, 0, 64);
	os_memcpy(config.ssid, SSID, strlen(SSID));
	os_memcpy(config.password, WIFI_KEY, strlen(WIFI_KEY));

	config.bssid_set = 0; 
	wifi_station_set_config(&config);
}
Example #18
0
//Template code for the Tcp server status
void ICACHE_FLASH_ATTR tplTcpServerStatus(HttpdConnData *connData, char *token, void **arg) {
	char buff[512];
	static struct station_config stconf;
	if (token==NULL) return;
	wifi_station_get_config(&stconf);
	os_strcpy(buff, "Unknown");
	if (os_strcmp(token, "WiFiSettings")==0) {
		os_printf("-%s-%s Getting ip settings to replace token: %s \r\n", __FILE__, __func__, token);		
		char ipSettings[256] = { 0};
		GetTcpServerStatus(ipSettings);
		os_strcpy(buff, ipSettings);
		os_printf("-%s-%s Found ip settings: %s \r\n", __FILE__, __func__, buff);		
	}
	espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
}
Example #19
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);
		}
	}
}
Example #20
0
void wifi_enter_sta()
{
	struct station_config config;

	//Connect to the defined access point.
	wifi_station_get_config(&config);

	os_memset(&config, 0x0, sizeof(struct station_config));
	strcpy(config.ssid, AP_NAME);
	strcpy(config.password, AP_PASS);

	wifi_set_opmode(STATIONAP_MODE);
	wifi_station_set_config(&config);
	wifi_station_disconnect();
	wifi_station_connect();
}
Example #21
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);
}
Example #22
0
/**
  * @brief  Query commad of join to wifi ap.
  * @param  id: commad id number
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_queryCmdCwjap(uint8_t id)
{
  char temp[64];
  struct station_config stationConf;
  wifi_station_get_config(&stationConf);
  if(stationConf.ssid != 0)
  {
    os_sprintf(temp, "%s:\"%s\"\r\n", at_fun[id].at_cmdName, stationConf.ssid);
    uart0_sendStr(temp);
    at_backOk;
  }
  else
  {
    at_backError;
  }
}
Example #23
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void)
{
	int i;

    // rom use 74880 baut_rate, here reinitialize
    uart_init(BIT_RATE_115200, BIT_RATE_115200);

	uart_tx_one_char('\r');
	__printf("NodeLua %s (With liblua %s) Copyright (C) 2014 NodeLua.org free mem=%d\n", NODELUA_RELEASE NODELUA_RELEASE_LOC, LUA_RELEASE, system_get_free_heap_size());

	// char *argv[] = {"lua", "-e", (char*)buf};
	// for(i = 0; 1; i ++)
	// {
	// 	uint16_t val = system_adc_read();
	// 	__printf("adc=%d\n", val);
	// 	luamain(sizeof(argv)/sizeof(char*), argv);
	// }

    struct station_config config;
    wifi_station_get_config(&config);
	if (wifi_get_opmode() == STATION_MODE && os_strlen(config.ssid) > 0)
	{
		os_timer_disarm(&check_sta_timer);
		os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, 1);
		os_timer_arm(&check_sta_timer, 100, 0);
	}
	else
	{
		__printf("Please set wifi parameters to connect to an exist AP!\n");
		luainit("");
	}

	return;

// #if ESP_PLATFORM
//     user_esp_platform_init();
// #endif
//
//     user_devicefind_init();
// #ifdef SERVER_SSL_ENABLE
//     user_webserver_init(SERVER_SSL_PORT);
// #else
//     user_webserver_init(SERVER_PORT);
// #endif
}
Example #24
0
void ICACHE_FLASH_ATTR
GetWifiConfig(char * data)
{
  struct softap_config apConfig;
  struct station_config stationConfig;
  os_printf("-%s-%s \r\n", __FILE__, __func__); 
  wifi_station_get_config(&stationConfig);
  wifi_softap_get_config(&apConfig);
  os_sprintf(data, " \"%s\",\"%s\",%d,%d <br />\r\n",
             apConfig.ssid,
             apConfig.password,
             apConfig.channel,
             apConfig.authmode);

  os_sprintf(data, "%s \"%s\",\"%s\"<br />\r\n",
             data,
             stationConfig.ssid,
             stationConfig.password);
}
Example #25
0
// ----------------------------------------------------------------------------
// Set up and connect for STA Mode
// ----------------------------------------------------------------------------
void connect_st_mode(void)
{
     struct station_config stconfig;
     wifi_set_opmode(STATION_MODE);
     wifi_station_disconnect();       // just in case
     wifi_station_dhcpc_stop();
     if(wifi_station_get_config(&stconfig))  {
         os_memset(stconfig.ssid,     0, sizeof(stconfig.ssid));
         os_memset(stconfig.password, 0, sizeof(stconfig.password));
         os_sprintf((char *)stconfig.ssid,     "%s", WIFI_CLIENTSSID);
         os_sprintf((char *)stconfig.password, "%s", WIFI_CLIENTPASSWORD);
         if(!wifi_station_set_config(&stconfig)) {
             os_printf("ESP8266 not set station config!\n");
        }
    }
    wifi_station_connect();
    wifi_station_dhcpc_start();
    os_printf("ESP8266 in STA mode configured.\n");
}
Example #26
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 WiFiConnector::use_smartconfig_wifi()
{
    static struct station_config conf;
    wifi_station_get_config(&conf);
    const char* ssid = reinterpret_cast<const char*>(conf.ssid);

    WIFI_DEBUG_PRINT("SSID (");
    WIFI_DEBUG_PRINT(strlen(ssid));
    WIFI_DEBUG_PRINT("): ");
    WIFI_DEBUG_PRINTLN(ssid);

    const char* password = reinterpret_cast<const char*>(conf.password);
    WIFI_DEBUG_PRINT("PASSWORD (");
    WIFI_DEBUG_PRINT(strlen(password));
    WIFI_DEBUG_PRINT("): ");
    WIFI_DEBUG_PRINTLN(password);

    init_config(ssid, password);
}
Example #28
0
/**
  * wifi.sta.getconfig()
  * Description:
  * 	Get current Station configuration.
  * 	Note:  if bssid_set==1 STATION is configured to connect to specified BSSID
  * 		   if bssid_set==0 specified BSSID address is irrelevant.
  * Syntax:
  * 	ssid, pwd, bssid_set, bssid=wifi.sta.getconfig()
  * Parameters:
  * 	none
  * Returns:
  * 	SSID, Password, BSSID_set, BSSID
  */
static int wifi_station_getconfig( lua_State* L )
{
	struct station_config sta_conf;
	char bssid[17];
	wifi_station_get_config(&sta_conf);
	if(sta_conf.ssid==0)
	{
		lua_pushnil(L);
	    return 1;
	}
	else
	{
	    lua_pushstring( L, sta_conf.ssid );
	    lua_pushstring( L, sta_conf.password );
	    lua_pushinteger( L, sta_conf.bssid_set);
	    c_sprintf(bssid, MACSTR, MAC2STR(sta_conf.bssid));
	    lua_pushstring( L, bssid);
	    return 4;
	}
}
Example #29
0
//Template code for the WLAN page.
void ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token, void **arg) {
	char buff[1024];
	int x;
	static struct station_config stconf;
	if (token==NULL) return;
	wifi_station_get_config(&stconf);

	os_strcpy(buff, "Unknown");
	if (os_strcmp(token, "WiFiMode")==0) {
		x=wifi_get_opmode();
		if (x==1) os_strcpy(buff, "Client");
		if (x==2) os_strcpy(buff, "SoftAP");
		if (x==3) os_strcpy(buff, "STA+AP");
	} else if (os_strcmp(token, "currSsid")==0) {
		os_strcpy(buff, (char*)stconf.ssid);
	} else if (os_strcmp(token, "WiFiPasswd")==0) {
		os_strcpy(buff, (char*)stconf.password);
	}
	espconn_sent(connData->conn, (uint8 *)buff, os_strlen(buff));
}
Example #30
0
LOCAL void ICACHE_FLASH_ATTR setup_wifi_st_mode(void)
{
	wifi_set_opmode(STATION_MODE);
	struct station_config stconfig;
	wifi_station_disconnect();
	wifi_station_dhcpc_stop();
	if(wifi_station_get_config(&stconfig))
	{
		os_memcpy(&stconfig.ssid, WIFI_CLIENTSSID, sizeof(WIFI_CLIENTSSID));
		os_memcpy(&stconfig.password, WIFI_CLIENTPASSWORD, sizeof(WIFI_CLIENTPASSWORD));
		wifi_station_set_config(&stconfig);
		ets_uart_printf("SSID: %s\n",stconfig.ssid);
		stringDraw(2, 1, (char*)stconfig.ssid);
	}
	wifi_station_connect();
	wifi_station_dhcpc_start();
	wifi_station_set_auto_connect(1);
	ets_uart_printf("STA mode\n");

}