Update ESP8266.h to increase size of ssid & phrase to Wifi standards of 32 & 64
Fork of ESP8266Interface by
ESP8266/ESP8266.h@15:37a7a56a424f, 2014-11-30 (annotated)
- Committer:
- michaeljkoster
- Date:
- Sun Nov 30 21:56:03 2014 +0000
- Revision:
- 15:37a7a56a424f
- Parent:
- 14:4d1128f72e00
- Child:
- 16:3f0efaa57a12
reorganize
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:fb4494783863 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
samux | 1:fb4494783863 | 2 | * |
samux | 1:fb4494783863 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
samux | 1:fb4494783863 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
samux | 1:fb4494783863 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
samux | 1:fb4494783863 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
samux | 1:fb4494783863 | 7 | * furnished to do so, subject to the following conditions: |
samux | 1:fb4494783863 | 8 | * |
samux | 1:fb4494783863 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
samux | 1:fb4494783863 | 10 | * substantial portions of the Software. |
samux | 1:fb4494783863 | 11 | * |
samux | 1:fb4494783863 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
samux | 1:fb4494783863 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
samux | 1:fb4494783863 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
samux | 1:fb4494783863 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
samux | 1:fb4494783863 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
samux | 1:fb4494783863 | 17 | * |
samux | 1:fb4494783863 | 18 | * @section DESCRIPTION |
samux | 1:fb4494783863 | 19 | * |
michaeljkoster | 13:41098c907200 | 20 | * ESP8266 RN131-C, wifi module |
samux | 1:fb4494783863 | 21 | * |
samux | 1:fb4494783863 | 22 | * Datasheet: |
samux | 1:fb4494783863 | 23 | * |
michaeljkoster | 13:41098c907200 | 24 | * http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/WiFi/ESP8266-RN-UM.pdf |
samux | 1:fb4494783863 | 25 | */ |
samux | 1:fb4494783863 | 26 | |
michaeljkoster | 13:41098c907200 | 27 | #ifndef ESP8266_H |
michaeljkoster | 13:41098c907200 | 28 | #define ESP8266_H |
samux | 1:fb4494783863 | 29 | |
samux | 1:fb4494783863 | 30 | #include "mbed.h" |
samux | 1:fb4494783863 | 31 | #include "CBuffer.h" |
samux | 1:fb4494783863 | 32 | |
samux | 1:fb4494783863 | 33 | #define DEFAULT_WAIT_RESP_TIMEOUT 500 |
samux | 1:fb4494783863 | 34 | |
screamer | 5:81e264dbbf03 | 35 | /** |
michaeljkoster | 13:41098c907200 | 36 | * The ESP8266 class |
screamer | 5:81e264dbbf03 | 37 | */ |
michaeljkoster | 13:41098c907200 | 38 | class ESP8266 |
samux | 1:fb4494783863 | 39 | { |
samux | 1:fb4494783863 | 40 | |
samux | 1:fb4494783863 | 41 | public: |
screamer | 5:81e264dbbf03 | 42 | /** |
samux | 1:fb4494783863 | 43 | * Constructor |
samux | 1:fb4494783863 | 44 | * |
samux | 1:fb4494783863 | 45 | * @param tx mbed pin to use for tx line of Serial interface |
samux | 1:fb4494783863 | 46 | * @param rx mbed pin to use for rx line of Serial interface |
samux | 1:fb4494783863 | 47 | * @param reset reset pin of the wifi module () |
samux | 1:fb4494783863 | 48 | * @param ssid ssid of the network |
screamer | 9:f2439377c172 | 49 | * @param phrase WEP, WPA or WPA2 key |
samux | 1:fb4494783863 | 50 | */ |
michaeljkoster | 13:41098c907200 | 51 | ESP8266( PinName tx, PinName rx, PinName reset, const char * ssid, const char * phrase ); |
samux | 1:fb4494783863 | 52 | |
screamer | 5:81e264dbbf03 | 53 | /** |
samux | 1:fb4494783863 | 54 | * Connect the wifi module to the ssid contained in the constructor. |
samux | 1:fb4494783863 | 55 | * |
samux | 1:fb4494783863 | 56 | * @return true if connected, false otherwise |
samux | 1:fb4494783863 | 57 | */ |
samux | 1:fb4494783863 | 58 | bool join(); |
samux | 1:fb4494783863 | 59 | |
screamer | 5:81e264dbbf03 | 60 | /** |
michaeljkoster | 15:37a7a56a424f | 61 | * Same as Join: connect to the ssid and get DHCP settings |
screamer | 6:5176e0864078 | 62 | * @return true if successful |
samux | 1:fb4494783863 | 63 | */ |
michaeljkoster | 13:41098c907200 | 64 | bool connect(); |
michaeljkoster | 13:41098c907200 | 65 | |
screamer | 5:81e264dbbf03 | 66 | /** |
michaeljkoster | 13:41098c907200 | 67 | * Check connection to the access point |
screamer | 6:5176e0864078 | 68 | * @return true if successful |
samux | 1:fb4494783863 | 69 | */ |
michaeljkoster | 13:41098c907200 | 70 | bool is_connected(); |
samux | 1:fb4494783863 | 71 | |
screamer | 5:81e264dbbf03 | 72 | /** |
michaeljkoster | 15:37a7a56a424f | 73 | * Disconnect the ESP8266 module from the access point |
michaeljkoster | 15:37a7a56a424f | 74 | * |
michaeljkoster | 15:37a7a56a424f | 75 | * @return true if successful |
michaeljkoster | 15:37a7a56a424f | 76 | */ |
michaeljkoster | 15:37a7a56a424f | 77 | bool disconnect(); |
michaeljkoster | 15:37a7a56a424f | 78 | |
michaeljkoster | 15:37a7a56a424f | 79 | /** |
michaeljkoster | 15:37a7a56a424f | 80 | * Close a tcp connection |
michaeljkoster | 15:37a7a56a424f | 81 | * |
michaeljkoster | 15:37a7a56a424f | 82 | * @return true if successful |
michaeljkoster | 15:37a7a56a424f | 83 | */ |
michaeljkoster | 15:37a7a56a424f | 84 | bool close(); |
michaeljkoster | 15:37a7a56a424f | 85 | |
michaeljkoster | 15:37a7a56a424f | 86 | /** |
michaeljkoster | 14:4d1128f72e00 | 87 | * Return the IP address |
michaeljkoster | 14:4d1128f72e00 | 88 | * @return IP address as a string |
michaeljkoster | 14:4d1128f72e00 | 89 | */ |
michaeljkoster | 14:4d1128f72e00 | 90 | char* getIPAddress(); |
michaeljkoster | 15:37a7a56a424f | 91 | |
michaeljkoster | 15:37a7a56a424f | 92 | /** |
michaeljkoster | 15:37a7a56a424f | 93 | * Return the IP address from host name |
michaeljkoster | 15:37a7a56a424f | 94 | * @return IP address as a string |
michaeljkoster | 15:37a7a56a424f | 95 | */ bool gethostbyname(const char * host, char * ip); |
michaeljkoster | 15:37a7a56a424f | 96 | |
michaeljkoster | 14:4d1128f72e00 | 97 | /** |
samux | 1:fb4494783863 | 98 | * Reset the wifi module |
samux | 1:fb4494783863 | 99 | */ |
samux | 1:fb4494783863 | 100 | void reset(); |
samux | 3:9aa05e19c62e | 101 | |
screamer | 5:81e264dbbf03 | 102 | /** |
samux | 3:9aa05e19c62e | 103 | * Reboot the wifi module |
samux | 3:9aa05e19c62e | 104 | */ |
samux | 3:9aa05e19c62e | 105 | bool reboot(); |
samux | 1:fb4494783863 | 106 | |
screamer | 5:81e264dbbf03 | 107 | /** |
samux | 1:fb4494783863 | 108 | * Check if characters are available |
samux | 1:fb4494783863 | 109 | * |
samux | 1:fb4494783863 | 110 | * @return number of available characters |
samux | 1:fb4494783863 | 111 | */ |
samux | 1:fb4494783863 | 112 | int readable(); |
samux | 1:fb4494783863 | 113 | |
screamer | 5:81e264dbbf03 | 114 | /** |
samux | 1:fb4494783863 | 115 | * Check if characters are available |
samux | 1:fb4494783863 | 116 | * |
samux | 1:fb4494783863 | 117 | * @return number of available characters |
samux | 1:fb4494783863 | 118 | */ |
samux | 1:fb4494783863 | 119 | int writeable(); |
samux | 1:fb4494783863 | 120 | |
screamer | 5:81e264dbbf03 | 121 | /** |
samux | 1:fb4494783863 | 122 | * Read a character |
samux | 1:fb4494783863 | 123 | * |
samux | 1:fb4494783863 | 124 | * @return the character read |
samux | 1:fb4494783863 | 125 | */ |
samux | 1:fb4494783863 | 126 | char getc(); |
samux | 1:fb4494783863 | 127 | |
screamer | 5:81e264dbbf03 | 128 | /** |
samux | 1:fb4494783863 | 129 | * Write a character |
samux | 1:fb4494783863 | 130 | * |
samux | 1:fb4494783863 | 131 | * @param the character which will be written |
samux | 1:fb4494783863 | 132 | */ |
samux | 1:fb4494783863 | 133 | int putc(char c); |
samux | 1:fb4494783863 | 134 | |
screamer | 5:81e264dbbf03 | 135 | /** |
michaeljkoster | 15:37a7a56a424f | 136 | * Flush the buffer |
michaeljkoster | 15:37a7a56a424f | 137 | */ |
michaeljkoster | 15:37a7a56a424f | 138 | void flush(); |
michaeljkoster | 15:37a7a56a424f | 139 | |
michaeljkoster | 15:37a7a56a424f | 140 | /** |
michaeljkoster | 15:37a7a56a424f | 141 | * Send a command to the wify module. Check if the module is in command mode. If not enter in command mode |
michaeljkoster | 15:37a7a56a424f | 142 | * |
michaeljkoster | 15:37a7a56a424f | 143 | * @param str string to be sent |
michaeljkoster | 15:37a7a56a424f | 144 | * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO") |
michaeljkoster | 15:37a7a56a424f | 145 | * @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 | 1:fb4494783863 | 146 | * |
screamer | 6:5176e0864078 | 147 | * @return true if successful |
samux | 1:fb4494783863 | 148 | */ |
michaeljkoster | 15:37a7a56a424f | 149 | bool sendCommand(const char * cmd, const char * ack = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT); |
michaeljkoster | 15:37a7a56a424f | 150 | |
screamer | 5:81e264dbbf03 | 151 | /** |
samux | 1:fb4494783863 | 152 | * 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 | 1:fb4494783863 | 153 | * Useful to send a command to the module and wait a response. |
samux | 1:fb4494783863 | 154 | * |
samux | 1:fb4494783863 | 155 | * |
samux | 1:fb4494783863 | 156 | * @param str string to be sent |
samux | 1:fb4494783863 | 157 | * @param len string length |
samux | 1:fb4494783863 | 158 | * @param ACK string which must be acknowledge by the wifi module. If ACK == NULL, no string has to be acknoledged. (default: "NO") |
samux | 1:fb4494783863 | 159 | * @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 | 1:fb4494783863 | 160 | * |
samux | 1:fb4494783863 | 161 | * @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 | 1:fb4494783863 | 162 | */ |
samux | 1:fb4494783863 | 163 | int send(const char * str, int len, const char * ACK = NULL, char * res = NULL, int timeout = DEFAULT_WAIT_RESP_TIMEOUT); |
samux | 1:fb4494783863 | 164 | |
michaeljkoster | 13:41098c907200 | 165 | static ESP8266 * getInstance() { |
samux | 1:fb4494783863 | 166 | return inst; |
samux | 1:fb4494783863 | 167 | }; |
samux | 1:fb4494783863 | 168 | |
samux | 1:fb4494783863 | 169 | protected: |
samux | 1:fb4494783863 | 170 | Serial wifi; |
samux | 1:fb4494783863 | 171 | DigitalOut reset_pin; |
samux | 1:fb4494783863 | 172 | char phrase[30]; |
samux | 1:fb4494783863 | 173 | char ssid[30]; |
michaeljkoster | 14:4d1128f72e00 | 174 | char ipString[20]; |
michaeljkoster | 13:41098c907200 | 175 | CircBuffer<char> buf_ESP8266; |
samux | 1:fb4494783863 | 176 | |
michaeljkoster | 13:41098c907200 | 177 | static ESP8266 * inst; |
samux | 1:fb4494783863 | 178 | |
samux | 1:fb4494783863 | 179 | void attach_rx(bool null); |
samux | 1:fb4494783863 | 180 | void handler_rx(void); |
samux | 1:fb4494783863 | 181 | |
samux | 1:fb4494783863 | 182 | |
samux | 1:fb4494783863 | 183 | typedef struct STATE { |
samux | 1:fb4494783863 | 184 | bool associated; |
samux | 1:fb4494783863 | 185 | } State; |
samux | 1:fb4494783863 | 186 | |
samux | 1:fb4494783863 | 187 | State state; |
samux | 1:fb4494783863 | 188 | }; |
samux | 1:fb4494783863 | 189 | |
samux | 1:fb4494783863 | 190 | #endif |