Implementation of the WifiPlusClick hardware module.

Dependents:   WifiPlusKlickExample

WifiPlusClick Libary

Overview

http://www.mikroe.com/img/development-tools/accessory-boards/click/wifi-plus/wifi_plus_click_main.png

This library implements the functionality exposed by a WifiPlusClick module from MikroElektronika (http://www.mikroe.com/click/wifi-plus/).

The WifiPlusClick module is an easy to handle module which provides access to up to 8 simultaneous socket objects - which is an an important aspect when you want to implement your own web server.

When I first started with the more commonly used Wifly module, I found out that the Wifly module does not reliably serve webpages which include other resources like images, JavaScript files or CSS files. The root cause seems to be the limitation that Wifly is only able to handle a single socket at this time. So I searched for an alternative and found this (actually cheaper) alternative :

WifiPlusClick HW Module

This module comes with its own limitations. The WifiPlusClick Module interface does not allow to use broadcasting or multicasting on UDP sockets. There are some additional limitations, but I think these are not so important. The following functionality is provided by the module and my library implementation :

  1. Wifi functionality
    1. Connections using AD-HOC or INFRASTRUCTURE mode
    2. List all available Wifi beacons
    3. WEP and WPA/WPA2 security modes including binary and ASCII keys
    4. reading binary WPA key after successfull Connection to speed up connection time
  2. Socket functionality
    1. UDP sockets
    2. TCP sockets

Limitations

I found the following limitations:

  1. UDP sockets cannot use multicasting or broadcasting
  2. set_option functionality is not provided by the HW
  3. 8 sockets can be configured with 1024 bytes of buffer each or 1 socket with 8192 bytes of buffer.

Sample application

Here is my sample application which you can use as a starting point.

Import programWifiPlusKlickExample

Example application of the WifiPlusClick library for use of WifiPlusClick HW Module from Mikroe.com

NOTE

The implementation of the Sockets in this library is still not completely tested. I only tested the TCP part of the sockets. Please let me know what your experiences are when using the library. I will be working on a multithreaded version of this library...

Socket/UDPSocket.h

Committer:
leihen
Date:
2013-07-29
Revision:
0:2a179bd4cc02

File content as of revision 0:2a179bd4cc02:

/* Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __UDPSOCKET_H__
#define __UDPSOCKET_H__

#include "Socket/Socket.h"
#include "Socket/Endpoint.h"

/** Class UDPSocket, inherits from class Socket and implements the functionality of a UDP Socket when using a WifiPlusClick module.
  * @note Please note that the functionality provided by a WifiPlusClick module is limited. Neither broadcasting nor multicasting functionality is possible.
  */
class UDPSocket : public Socket
{
public:
    /** UDPSocket constructor to instantiate a UDPSocket object.  */
    UDPSocket();
    
    /** Function init provides initialization of the UDPSocket object.
      * @returns : true if successfull, or false otherwise.
      */
    int init(void);
    
    /** Function bind will bind a UDPSocket to a local port. The socket object should not already have been used for other purposes before.
      * @note Please note that there is currently no check implemented as to wheather or not the socket has already been used before.
      * @parameter port : The port to which to bind the UDPSocket to. If the port is specified as zero, a non-zero value beginning with 1024 will be selected.
      * @returns : 0 if successfull, or -1 otherwise.
      */
    int bind(unsigned int port = 0);
    
    /** Function join_multicast_group.
      * @note This function is not implemented as the WifiPlusClick module does not support this functionality.
      */
    int join_multicast_group(const char *address);
    
    /** Function set_broadcasting.
      * @note This fnction is not implemented as the WifiPlusClick module does not support this functionality.
      */
    int set_broadcasting(bool broadcast=true);
    
    /** Function sendTo implements sending of a packet to a specific endpoint. Make sure to use it on an initialized or bound socket.
      * @param remote : a reference to a valid endpoint specifying the remote ip-address and the remote port where to send the packet.
      * @param packet : a pointer to a valid buffer containing the packet data to send.
      * @param length : Specifies the number of data bytes to send.
      * @returns : the number of databytes actually sent or -1 on failure.
      */
    int sendTo(Endpoint &remote, char *packet, int length);
    
    /** Function receiveFrom implements receiving a packet of data on a socket. The remote address will be provided on return. Make sure to use it on an initialized or bound socket.
      * @param remote : a reference to an endpoint, which will receive the remote ip-address and the remote port from where data was returned.
      * @param packet : a data buffer which will receive the received data. The buffer must be at least as larget as length bytes.
      * @param length : The maximum number of bytes to receive. Please make sure that the buffer packet is large enough to hold this data completely.
      * @returns : the number of databytes actually received or -1 on failure. @note there may be more data received than what the buffer can store. Any data that does not fit in the buffer is discarded !
      */
    int receiveFrom(Endpoint &remote, char *packet, int length);
};

#endif // __UDPSOCKET_H__