Provide an easy-to-use way to manipulate ESP8266.

Dependencies:   ArduinoAPI

Fork of WeeESP8266 by ITEAD STUDIO

Committer:
itead
Date:
Fri Feb 06 00:55:22 2015 +0000
Revision:
2:fb209f93f3f1
Parent:
ESP8266AT.h@1:edc634cad906
Child:
3:9f745022331a
Rename ESP8266AT to ESP8266

Who changed what in which revision?

UserRevisionLine numberNew contents of line
itead 1:edc634cad906 1 /**
itead 2:fb209f93f3f1 2 * @file ESP8266.h
itead 2:fb209f93f3f1 3 * @brief The definition of class ESP8266.
itead 1:edc634cad906 4 * @author Wu Pengfei<pengfei.wu@itead.cc>
itead 1:edc634cad906 5 * @date 2015.02
itead 1:edc634cad906 6 *
itead 1:edc634cad906 7 * @par Copyright:
itead 1:edc634cad906 8 * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
itead 1:edc634cad906 9 * This program is free software; you can redistribute it and/or
itead 1:edc634cad906 10 * modify it under the terms of the GNU General Public License as
itead 1:edc634cad906 11 * published by the Free Software Foundation; either version 2 of
itead 1:edc634cad906 12 * the License, or (at your option) any later version. \n\n
itead 1:edc634cad906 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
itead 1:edc634cad906 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
itead 1:edc634cad906 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
itead 1:edc634cad906 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
itead 1:edc634cad906 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
itead 1:edc634cad906 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
itead 1:edc634cad906 19 * THE SOFTWARE.
itead 1:edc634cad906 20 */
itead 2:fb209f93f3f1 21 #ifndef __ESP8266_H__
itead 2:fb209f93f3f1 22 #define __ESP8266_H__
itead 0:d3b93948c925 23
itead 1:edc634cad906 24 #include "ArduinoAPI.h"
itead 0:d3b93948c925 25
itead 1:edc634cad906 26 /**
itead 1:edc634cad906 27 * Provide an easy-to-use way to manipulate ESP8266.
itead 1:edc634cad906 28 */
itead 2:fb209f93f3f1 29 class ESP8266 {
itead 1:edc634cad906 30 public:
itead 1:edc634cad906 31
itead 1:edc634cad906 32 /* Constructors */
itead 2:fb209f93f3f1 33 ESP8266(PinName tx, PinName rx, int32_t baud_rate = 9600);
itead 1:edc634cad906 34
itead 1:edc634cad906 35 /**
itead 1:edc634cad906 36 * Verify ESP8266 live or not.
itead 1:edc634cad906 37 *
itead 1:edc634cad906 38 * Actually, this method will send command "AT" to ESP8266 and waiting for "OK".
itead 1:edc634cad906 39 *
itead 1:edc634cad906 40 * @retval true - alive.
itead 1:edc634cad906 41 * @retval false - dead.
itead 1:edc634cad906 42 */
itead 1:edc634cad906 43 bool kick(void);
itead 1:edc634cad906 44
itead 1:edc634cad906 45 /**
itead 1:edc634cad906 46 * Restart ESP8266 by "AT+RST".
itead 1:edc634cad906 47 *
itead 1:edc634cad906 48 * This method will take 3 seconds or more.
itead 1:edc634cad906 49 *
itead 1:edc634cad906 50 * @retval true - success.
itead 1:edc634cad906 51 * @retval false - failure.
itead 1:edc634cad906 52 */
itead 1:edc634cad906 53 bool restart(void);
itead 1:edc634cad906 54
itead 1:edc634cad906 55 /**
itead 1:edc634cad906 56 * Get the version of AT Command Set.
itead 1:edc634cad906 57 *
itead 1:edc634cad906 58 * @return the string of version.
itead 1:edc634cad906 59 */
itead 1:edc634cad906 60 String getVersion(void);
itead 1:edc634cad906 61
itead 1:edc634cad906 62 /**
itead 1:edc634cad906 63 * Set operation mode to staion.
itead 1:edc634cad906 64 *
itead 1:edc634cad906 65 * @retval true - success.
itead 1:edc634cad906 66 * @retval false - failure.
itead 1:edc634cad906 67 */
itead 1:edc634cad906 68 bool setOprToStation(void);
itead 1:edc634cad906 69
itead 1:edc634cad906 70 /**
itead 1:edc634cad906 71 * Set operation mode to softap.
itead 1:edc634cad906 72 *
itead 1:edc634cad906 73 * @retval true - success.
itead 1:edc634cad906 74 * @retval false - failure.
itead 1:edc634cad906 75 */
itead 1:edc634cad906 76 bool setOprToSoftAP(void);
itead 1:edc634cad906 77
itead 1:edc634cad906 78 /**
itead 1:edc634cad906 79 * Set operation mode to station + softap.
itead 1:edc634cad906 80 *
itead 1:edc634cad906 81 * @retval true - success.
itead 1:edc634cad906 82 * @retval false - failure.
itead 1:edc634cad906 83 */
itead 1:edc634cad906 84 bool setOprToStationSoftAP(void);
itead 1:edc634cad906 85
itead 1:edc634cad906 86 /**
itead 1:edc634cad906 87 * Search available AP list and return it.
itead 1:edc634cad906 88 *
itead 1:edc634cad906 89 * @return the list of available APs.
itead 1:edc634cad906 90 * @note This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes).
itead 1:edc634cad906 91 * Do not call this method unless you must and ensure that your board has enough memery left.
itead 1:edc634cad906 92 */
itead 1:edc634cad906 93 String getAPList(void);
itead 1:edc634cad906 94
itead 1:edc634cad906 95 /**
itead 1:edc634cad906 96 * Join in AP.
itead 1:edc634cad906 97 *
itead 1:edc634cad906 98 * @param ssid - SSID of AP to join in.
itead 1:edc634cad906 99 * @param pwd - Password of AP to join in.
itead 1:edc634cad906 100 * @retval true - success.
itead 1:edc634cad906 101 * @retval false - failure.
itead 1:edc634cad906 102 * @note This method will take a couple of seconds.
itead 1:edc634cad906 103 */
itead 1:edc634cad906 104 bool joinAP(String ssid, String pwd);
itead 1:edc634cad906 105
itead 1:edc634cad906 106 /**
itead 1:edc634cad906 107 * Leave AP joined before.
itead 1:edc634cad906 108 *
itead 1:edc634cad906 109 * @retval true - success.
itead 1:edc634cad906 110 * @retval false - failure.
itead 1:edc634cad906 111 */
itead 1:edc634cad906 112 bool leaveAP(void);
itead 1:edc634cad906 113
itead 1:edc634cad906 114 /**
itead 1:edc634cad906 115 * Set SoftAP parameters.
itead 1:edc634cad906 116 *
itead 1:edc634cad906 117 * @param ssid - SSID of SoftAP.
itead 1:edc634cad906 118 * @param pwd - PASSWORD of SoftAP.
itead 1:edc634cad906 119 * @param chl - the channel (1 - 13, default: 7).
itead 1:edc634cad906 120 * @param ecn - the way of encrypstion (0 - OPEN, 1 - WEP,
itead 1:edc634cad906 121 * 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 0).
itead 1:edc634cad906 122 * @note This method should not be called when station mode.
itead 1:edc634cad906 123 */
itead 1:edc634cad906 124 bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 0);
itead 1:edc634cad906 125
itead 1:edc634cad906 126 /**
itead 1:edc634cad906 127 * Get the IP list of devices connected to SoftAP.
itead 1:edc634cad906 128 *
itead 1:edc634cad906 129 * @return the list of IP.
itead 1:edc634cad906 130 * @note This method should not be called when station mode.
itead 1:edc634cad906 131 */
itead 1:edc634cad906 132 String getDeviceIP(void);
itead 1:edc634cad906 133
itead 1:edc634cad906 134
itead 1:edc634cad906 135 private:
itead 1:edc634cad906 136 ArduinoSerial m_uart; /* The UART to communicate with ESP8266 */
itead 1:edc634cad906 137
itead 1:edc634cad906 138 };
itead 0:d3b93948c925 139
itead 2:fb209f93f3f1 140 #endif /* #ifndef __ESP8266_H__ */