ACTUALIZED LIBRARY 0 Open (Default) 1 WEP-128 2 WPA1 3 Mixed WPA1 & WPA2-PSK 4 WPA2-PSK 5 Not Used 6 Adhoc, Join any Adhoc network

Dependents:   mbed_Arduino_sensor

Fork of WiflyInterface by Samuel Mokrani

Committer:
sherckuith
Date:
Fri Aug 24 12:29:57 2012 +0000
Revision:
11:002225507f44
Parent:
8:9a3cd07ed7e8
WLAN Parameters FULL ACTUALIZED!; 0 Open (Default); 1 WEP-128; 2 WPA1; 3 Mixed WPA1 & WPA2-PSK; 4 WPA2-PSK; 5 Not Used; 6 Adhoc, Join any Adhoc network

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 7:a92dbed32890 1 /* Copyright (C) 2012 mbed.org, MIT License
samux 7:a92dbed32890 2 *
samux 7:a92dbed32890 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 7:a92dbed32890 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
samux 7:a92dbed32890 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
samux 7:a92dbed32890 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
samux 7:a92dbed32890 7 * furnished to do so, subject to the following conditions:
samux 7:a92dbed32890 8 *
samux 7:a92dbed32890 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 7:a92dbed32890 10 * substantial portions of the Software.
samux 7:a92dbed32890 11 *
samux 7:a92dbed32890 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 7:a92dbed32890 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 7:a92dbed32890 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 7:a92dbed32890 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 7:a92dbed32890 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 7:a92dbed32890 17 *
samux 7:a92dbed32890 18 * @section DESCRIPTION
samux 7:a92dbed32890 19 *
samux 7:a92dbed32890 20 * Wifly RN131-C, wifi module
samux 7:a92dbed32890 21 *
samux 7:a92dbed32890 22 * Datasheet:
samux 7:a92dbed32890 23 *
samux 7:a92dbed32890 24 * http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/WiFi/WiFly-RN-UM.pdf
samux 7:a92dbed32890 25 */
samux 7:a92dbed32890 26
samux 7:a92dbed32890 27 #ifndef WIFLY_H
samux 7:a92dbed32890 28 #define WIFLY_H
samux 7:a92dbed32890 29
samux 7:a92dbed32890 30 #include "mbed.h"
samux 7:a92dbed32890 31 #include "CBuffer.h"
samux 7:a92dbed32890 32
samux 7:a92dbed32890 33 #define DEFAULT_WAIT_RESP_TIMEOUT 500
samux 7:a92dbed32890 34
samux 7:a92dbed32890 35 enum Security {
samux 7:a92dbed32890 36 NONE = 0,
samux 7:a92dbed32890 37 WEP_128 = 1,
sherckuith 11:002225507f44 38 WPA = 2,
sherckuith 11:002225507f44 39 MIX = 3,
sherckuith 11:002225507f44 40 WPA2 = 4,
sherckuith 11:002225507f44 41 Adhoc = 6
samux 7:a92dbed32890 42 };
samux 7:a92dbed32890 43
sherckuith 11:002225507f44 44 class Wifly
sherckuith 11:002225507f44 45 {
samux 7:a92dbed32890 46
samux 7:a92dbed32890 47 public:
samux 7:a92dbed32890 48 /*
samux 8:9a3cd07ed7e8 49 * Constructor
samux 7:a92dbed32890 50 *
samux 7:a92dbed32890 51 * @param tx mbed pin to use for tx line of Serial interface
samux 7:a92dbed32890 52 * @param rx mbed pin to use for rx line of Serial interface
samux 7:a92dbed32890 53 * @param reset reset pin of the wifi module ()
samux 7:a92dbed32890 54 * @param tcp_status connection status pin of the wifi module (GPIO 6)
samux 7:a92dbed32890 55 * @param ssid ssid of the network
samux 7:a92dbed32890 56 * @param phrase WEP or WPA key
samux 8:9a3cd07ed7e8 57 * @param sec Security type (NONE, WEP_128 or WPA)
samux 7:a92dbed32890 58 */
samux 7:a92dbed32890 59 Wifly( PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec);
samux 7:a92dbed32890 60
samux 7:a92dbed32890 61 /*
samux 7:a92dbed32890 62 * Send a string to the wifi module by serial port. This function desactivates the user interrupt handler when a character is received to analyze the response from the wifi module.
samux 7:a92dbed32890 63 * Useful to send a command to the module and wait a response.
samux 7:a92dbed32890 64 *
samux 7:a92dbed32890 65 *
samux 7:a92dbed32890 66 * @param str string to be sent
samux 7:a92dbed32890 67 * @param len string length
samux 7:a92dbed32890 68 * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
samux 7:a92dbed32890 69 * @param res this field will contain the response from the wifi module, result of a command sent. This field is available only if ACK = "NO" AND res != NULL (default: NULL)
samux 7:a92dbed32890 70 *
samux 7:a92dbed32890 71 * @return true if ACK has been found in the response from the wifi module. False otherwise or if there is no response in 5s.
samux 7:a92dbed32890 72 */
samux 7:a92dbed32890 73 int send(const char * str, int len, const char * ACK = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT);
samux 7:a92dbed32890 74
samux 7:a92dbed32890 75 /*
samux 7:a92dbed32890 76 * Connect the wifi module to the ssid contained in the constructor.
samux 7:a92dbed32890 77 *
samux 7:a92dbed32890 78 * @return true if connected, false otherwise
samux 7:a92dbed32890 79 */
samux 7:a92dbed32890 80 bool join();
sherckuith 11:002225507f44 81
samux 7:a92dbed32890 82 /*
samux 7:a92dbed32890 83 * Close a connection with the access point
samux 7:a92dbed32890 84 *
samux 7:a92dbed32890 85 * @ returns true if successful
samux 7:a92dbed32890 86 */
samux 7:a92dbed32890 87 bool leave();
samux 7:a92dbed32890 88
samux 7:a92dbed32890 89 /*
samux 7:a92dbed32890 90 * Read a string if available
samux 7:a92dbed32890 91 *
samux 7:a92dbed32890 92 *@param str pointer where will be stored the string read
samux 7:a92dbed32890 93 */
samux 7:a92dbed32890 94 bool read(char * str);
samux 7:a92dbed32890 95
samux 7:a92dbed32890 96 /*
samux 7:a92dbed32890 97 * Reset the wifi module
samux 7:a92dbed32890 98 */
samux 7:a92dbed32890 99 void reset();
samux 7:a92dbed32890 100
samux 7:a92dbed32890 101 /*
samux 7:a92dbed32890 102 * Check if characters are available
samux 7:a92dbed32890 103 *
samux 7:a92dbed32890 104 * @return number of available characters
samux 7:a92dbed32890 105 */
samux 7:a92dbed32890 106 int readable();
sherckuith 11:002225507f44 107
samux 7:a92dbed32890 108 /*
samux 7:a92dbed32890 109 * Check if characters are available
samux 7:a92dbed32890 110 *
samux 7:a92dbed32890 111 * @return number of available characters
samux 7:a92dbed32890 112 */
samux 7:a92dbed32890 113 int writeable();
sherckuith 11:002225507f44 114
samux 7:a92dbed32890 115 /*
samux 7:a92dbed32890 116 * Check if a tcp link is active
samux 7:a92dbed32890 117 *
samux 7:a92dbed32890 118 * @returns true if successful
samux 7:a92dbed32890 119 */
samux 7:a92dbed32890 120 bool is_connected();
samux 7:a92dbed32890 121
samux 7:a92dbed32890 122 /*
samux 7:a92dbed32890 123 * Read a character
samux 7:a92dbed32890 124 *
samux 7:a92dbed32890 125 * @return the character read
samux 7:a92dbed32890 126 */
samux 7:a92dbed32890 127 char getc();
samux 7:a92dbed32890 128
samux 7:a92dbed32890 129 /*
samux 7:a92dbed32890 130 * Flush the buffer
samux 7:a92dbed32890 131 */
samux 7:a92dbed32890 132 void flush();
samux 7:a92dbed32890 133
samux 7:a92dbed32890 134 /*
samux 7:a92dbed32890 135 * Write a character
samux 7:a92dbed32890 136 *
samux 7:a92dbed32890 137 * @param the character which will be written
samux 7:a92dbed32890 138 */
samux 7:a92dbed32890 139 int putc(char c);
samux 7:a92dbed32890 140
samux 7:a92dbed32890 141
samux 7:a92dbed32890 142 /*
samux 7:a92dbed32890 143 * To enter in command mode (we can configure the module)
samux 7:a92dbed32890 144 *
samux 7:a92dbed32890 145 * @return true if successful, false otherwise
samux 7:a92dbed32890 146 */
samux 7:a92dbed32890 147 bool cmdMode();
samux 7:a92dbed32890 148
samux 7:a92dbed32890 149 /*
samux 7:a92dbed32890 150 * To exit the command mode
samux 7:a92dbed32890 151 *
samux 7:a92dbed32890 152 * @return true if successful, false otherwise
samux 7:a92dbed32890 153 */
samux 7:a92dbed32890 154 bool exit();
sherckuith 11:002225507f44 155
samux 7:a92dbed32890 156 /*
samux 7:a92dbed32890 157 * Close a tcp connection
samux 7:a92dbed32890 158 *
samux 7:a92dbed32890 159 * @ returns true if successful
samux 7:a92dbed32890 160 */
samux 7:a92dbed32890 161 bool close();
sherckuith 11:002225507f44 162
samux 7:a92dbed32890 163 /*
samux 7:a92dbed32890 164 * Send a command to the wify module. Check if the module is in command mode. If not enter in command mode
samux 7:a92dbed32890 165 *
samux 7:a92dbed32890 166 * @param str string to be sent
samux 7:a92dbed32890 167 * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO")
samux 7:a92dbed32890 168 * @param res this field will contain the response from the wifi module, result of a command sent. This field is available only if ACK = "NO" AND res != NULL (default: NULL)
samux 7:a92dbed32890 169 *
samux 7:a92dbed32890 170 * @returns true if successful
samux 7:a92dbed32890 171 */
samux 7:a92dbed32890 172 bool sendCommand(const char * cmd, const char * ack = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT);
sherckuith 11:002225507f44 173
samux 7:a92dbed32890 174 bool dnsLookup(const char * host, char * ip);
sherckuith 11:002225507f44 175
sherckuith 11:002225507f44 176 static Wifly * getInstance() {
sherckuith 11:002225507f44 177 return inst;
sherckuith 11:002225507f44 178 };
samux 7:a92dbed32890 179
samux 7:a92dbed32890 180 protected:
samux 7:a92dbed32890 181 Serial wifi;
samux 7:a92dbed32890 182 DigitalOut reset_pin;
samux 7:a92dbed32890 183 DigitalIn tcp_status;
samux 7:a92dbed32890 184 bool wpa;
samux 7:a92dbed32890 185 bool dhcp;
samux 7:a92dbed32890 186 char phrase[30];
samux 7:a92dbed32890 187 char ssid[30];
samux 7:a92dbed32890 188 const char * ip;
samux 7:a92dbed32890 189 const char * netmask;
samux 7:a92dbed32890 190 const char * gateway;
samux 7:a92dbed32890 191 int channel;
samux 7:a92dbed32890 192 CircBuffer<char> buf_wifly;
samux 7:a92dbed32890 193 Security security;
samux 7:a92dbed32890 194 char * getStringSecurity();
sherckuith 11:002225507f44 195
samux 7:a92dbed32890 196 bool cmd_mode;
sherckuith 11:002225507f44 197
samux 7:a92dbed32890 198 static Wifly * inst;
samux 7:a92dbed32890 199
samux 7:a92dbed32890 200 void attach_rx(bool null);
samux 7:a92dbed32890 201 void handler_rx(void);
samux 7:a92dbed32890 202 };
samux 7:a92dbed32890 203
samux 0:6ffb0aeb3972 204 #endif