Reference Home

MWiFi Introduction

This library has 3 main tasks :

  • to connect Arduino with the network using WiFi approach
  • to open sockets with a port number
  • to read and write to remote IP using sockets

WIFI connection can be done with an access point, that usually gives you a dynamic local IP (DHCP mode); or directly (ad hoc mode) with another computer (point to point). In this case the shield behaves like an access point and assign an IP to remote computer when it tries to join Arduino.

Moreover, MWiFi library has functions for scanning WiFi active hot spots in the environment.

These functions (scanNets(),getNetScanned(),getSSIDBestOpen() and existSSID()) can return informations like SSID, protection and power of hot spots signal, or directly the SSID of the best open (not protect) hot spot.

 

In a computer communication it is impossible to synchronize link opening, if none of them stays listening on an application port. Therefore, when connection is established you have to decide if act as a server or a client.

A server has to listen on a port number for accepting possible join attempts.

A client, unlike the server, has just to try to connect with a remote IP.

Link is done by a socket object on the server and a socket object on client. So, the point is to make a socket, both for server and client.

If Arduino acts as a server you have to create a socket listener and put pollingAccept() function in loop() routine. When join is required, pollingAccept() returns a socket linked to remote IP.

If Arduino acts as a client you have just to create a socket that try to connect with remote IP on a particular port number.

 

Socket

 

When link is done, you can write or read using socket.

writeData() functions have different arguments. You can give a pointer to an unsigned char array and its length, or a pointer to a char array (null terminated string) with or without a line feed (like print or println). But, in any case, writing function is buffer oriented (not character oriented) because the overload of MCW controller.

readData() functions can read a buffer of bytes or a record of characters (line feed terminated string). But the max length of record is defined by LINEBUFFLEN (81 at present: 80+null terminator). If no line feed is reached the line returned is a null terminated string 80 char long.

Unfortunately, there isn't any available() function (because MCW), and you have just to read ; read function can return the number of really read bytes or 0.

See Also:

Reference Home