mbed official WiflyInterface (interface for Roving Networks Wifly modules)

Dependents:   Wifly_HelloWorld Websocket_Wifly_HelloWorld RPC_Wifly_HelloWorld HTTPClient_Wifly_HelloWorld ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WiflyInterface.h Source File

WiflyInterface.h

00001 /* WiflyInterface.h */
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019  
00020 #ifndef WIFLYINTERFACE_H_
00021 #define WIFLYINTERFACE_H_
00022 
00023 #include "Wifly.h"
00024 
00025  /**
00026  * Interface using Wifly to connect to an IP-based network
00027  */
00028 class WiflyInterface: public Wifly {
00029 public:
00030 
00031     /**
00032     * Constructor
00033     *
00034     * \param tx mbed pin to use for tx line of Serial interface
00035     * \param rx mbed pin to use for rx line of Serial interface
00036     * \param reset reset pin of the wifi module ()
00037     * \param tcp_status connection status pin of the wifi module (GPIO 6)
00038     * \param ssid ssid of the network
00039     * \param phrase WEP or WPA key
00040     * \param sec Security type (NONE, WEP_128 or WPA)
00041     */
00042   WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec = NONE);
00043 
00044   /** Initialize the interface with DHCP.
00045   * Initialize the interface and configure it to use DHCP (no connection at this point).
00046   * \return 0 on success, a negative number on failure
00047   */
00048   int init(); //With DHCP
00049 
00050   /** Initialize the interface with a static IP address.
00051   * Initialize the interface and configure it with the following static configuration (no connection at this point).
00052   * \param ip the IP address to use
00053   * \param mask the IP address mask
00054   * \param gateway the gateway to use
00055   * \return 0 on success, a negative number on failure
00056   */
00057   int init(const char* ip, const char* mask, const char* gateway);
00058 
00059   /** Connect
00060   * Bring the interface up, start DHCP if needed.
00061   * \return 0 on success, a negative number on failure
00062   */
00063   int connect();
00064   
00065   /** Disconnect
00066   * Bring the interface down
00067   * \return 0 on success, a negative number on failure
00068   */
00069   int disconnect();
00070   
00071   /** Get IP address
00072   *
00073   * \return ip address
00074   */
00075   char* getIPAddress();
00076   
00077 private:
00078     char ip_string[20];
00079     bool ip_set;
00080 };
00081 
00082 #include "TCPSocketConnection.h"
00083 #include "TCPSocketServer.h"
00084 #include "UDPSocket.h"
00085 
00086 #endif /* WIFLYINTERFACE_H_ */