Reference Home

Connection

Description

Connection phase needs setting connection specifications before, and then trying connection. But you can use convenience functions to prepare&connect in a single step.

When connection to net is established led 1 becomes on

When connection is lost led 1 becomes off (actually, also reset is induced in this version)

To set network mode connection

Syntax

MWiFi.setNetMode(int mode)

Parameters

mode : 1 = infrastucture (access point) (default); 2 = ad hoc

 

To connect an access point (ssid) in a single step:

Syntax

If connection without password (open WIFI net)

MWiFi.ConnectOpen(char *ssid)

If connection with WPA secure system (WPA or WPA2).
If password is used, it can take up 1m. Whereas using key is quite fast.
Key is given back only if connection with password is established using ConnectWPAandGetKey function.

MWiFi.ConnectWPAwithPsw(char *ssid, char *password)

MWiFi.ConnectWPAandGetKey(char *ssid,char *password,byte key[32])

MWiFi.ConnectWPAwithKey(char *ssid,byte key[32])

If you want use EEPROM to directly store and manage key

MWiFi.ConnectWPAandGetKeyEE(char *ssid,char *password,int EEadd)

MWiFi.ConnectWPAwithKeyEE(char *ssid,int EEadd)

Parameters

ssid: access point name

password: pasword for WPA(or WPA2) access

key: 32 bytes buffer for key calculated (from password).

(key is a buffer input (filled by function), in getKey function or buffer output, in withKey function.)

EEadd: EEPROM start address (note: used 33 bytes, 1 flag + 32 key)

Returns

1 if connection successful

0 otherwise

 

To manage EEPROM for key

 

MWiFi.storeKeyOnEEPROM(uint8_t key[32],int EEadd)

MWiFi.isKeyInEEPROM(int EEadd)

Parameters

key: 32 bytes buffer for key calculated (from password).

EEadd: EEPROM start address (note: used 33 bytes, 1 flag + 32 key)

Returns

nothing from first function

true/false from second

 

To set connection specification (outdated functions):

Syntax

If connection without password (open WIFI net)

MWiFi.ConnSetOpen(char *ssid, int ssidlength)

MWiFi.ConnSetOpen(char *ssid) //if ssid null terminated string

If connection with WPA secure system (WPA or WPA2)

MWiFi.ConnSetWPA(char *ssid,int ssidlength, char *password,int passwordlen)

MWiFi.ConnSetWPA(char *ssid,char *password) //if null terminated strings

Parameters

ssid : access point name

ssidlength : its length

password : password for WPA

passwordlen : length

Returns

nothing

 

To connect:

Syntax

MWiFi.Connect()

Parameters

none

Returns

1 if connection successful

0 otherwise

Example:

#include <MWiFi.h> //library include

 

MWiFi WIFI; //instance of MWiFi

 

void setup() {
    WIFI.begin(); // startup shield
:
WIFI.ConnectOpen("DLink-casa");

:
}

void loop() {}


or

byte key[32];
void
setup() {
    WIFI.begin(); // startup shield
:

if (key[0]==0) WIFI.ConnectWPAandGetKey("DLink-casa","password",key);
else WIFI.ConnectWPAwithKey("DLink-casa",key);

:
}

void loop() {}

Reference Home