Пример #1
0
/*************************************************************************
//Initialize port

	mode:	setting operation mode
		STA: 	Station
		AP:	 	Access Point
		AT_STA:	Access Point & Station

	chl:	channel number
	ecn:	encryption
		OPEN          0
		WEP           1
		WAP_PSK       2
		WAP2_PSK      3
		WAP_WAP2_PSK  4		

	return:
		true	-	successfully
		false	-	unsuccessfully

***************************************************************************/
bool WIFI::Initialize(byte mode, String ssid, String pwd, byte chl, byte ecn)
{
	if (!wifiPresent) return false;

	if (mode == STA)
	{	
		bool b = confMode(mode);
		if (!b)
		{
			return false;
		}
		Reset();
		confJAP(ssid, pwd);
	}
	else if (mode == AP)
	{
		bool b = confMode(mode);
		if (!b)
		{
			return false;
		}
		Reset();
		confSAP(ssid, pwd, chl, ecn);
	}
	else if (mode == AP_STA)
	{
		bool b = confMode(mode);
		if (!b)
		{
			return false;
		}
		Reset();
		confJAP(ssid, pwd);
		confSAP(ssid, pwd, chl, ecn);
	}
	
	return true;
}
//////////////////////////////////////////////////////////////////////////
//整合接口
bool WIFI::Initialize(byte a, String ssid, String pwd, byte chl, byte ecn)
{
	if (a == 1)
	{	
		bool b = confMode(a);
		if (!b)
		{
			return false;
		}
		Reset();
		confJAP(ssid, pwd);
	}
	else if (a == 2)
	{
		bool b = confMode(a);
		if (!b)
		{
			return false;
		}
		Reset();
		confSAP(ssid, pwd, chl, ecn);
	}
	else if (a == 3)
	{
		bool b = confMode(a);
		if (!b)
		{
			return false;
		}
		Reset();
		confJAP(ssid, pwd);
		confSAP(ssid, pwd, chl, ecn);
	}
	
	return true;
}