Driver for the ESP8266 WiFi module using ATParser library. Espressif Firmware.
Dependencies: ATParser
Fork of ESP8266 by
ESP8266.h
00001 /* ESP8266Interface Example 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ESP8266_H 00018 #define ESP8266_H 00019 00020 #include "ATParser.h" 00021 00022 /** ESP8266Interface class. 00023 This is an interface to a ESP8266 radio. 00024 */ 00025 class ESP8266 00026 { 00027 public: 00028 ESP8266(PinName tx, PinName rx, bool debug=false); 00029 00030 /** 00031 * Startup the ESP8266 00032 * 00033 * @param mode mode of WIFI 1-client, 2-host, 3-both 00034 * @return true only if ESP8266 was setup correctly 00035 */ 00036 bool startup(int mode); 00037 00038 /** 00039 * Reset ESP8266 00040 * 00041 * @return true only if ESP8266 resets successfully 00042 */ 00043 bool reset(void); 00044 00045 /** 00046 * Enable/Disable DHCP 00047 * 00048 * @param enabled DHCP enabled when true 00049 * @param mode mode of DHCP 0-softAP, 1-station, 2-both 00050 * @return true only if ESP8266 enables/disables DHCP successfully 00051 */ 00052 bool dhcp(bool enabled, int mode); 00053 00054 /** 00055 * Connect ESP8266 to AP 00056 * 00057 * @param ap the name of the AP 00058 * @param passPhrase the password of AP 00059 * @return true only if ESP8266 is connected successfully 00060 */ 00061 bool connect(const char *ap, const char *passPhrase); 00062 00063 /** 00064 * Disconnect ESP8266 from AP 00065 * 00066 * @return true only if ESP8266 is disconnected successfully 00067 */ 00068 bool disconnect(void); 00069 00070 /** 00071 * Get the IP address of ESP8266 00072 * 00073 * @return null-teriminated IP address or null if no IP address is assigned 00074 */ 00075 const char *getIPAddress(void); 00076 00077 /** 00078 * Get the MAC address of ESP8266 00079 * 00080 * @return null-terminated MAC address or null if no MAC address is assigned 00081 */ 00082 const char *getMACAddress(void); 00083 00084 /** 00085 * Check if ESP8266 is conenected 00086 * 00087 * @return true only if the chip has an IP address 00088 */ 00089 bool isConnected(void); 00090 00091 /** 00092 * Open a socketed connection 00093 * 00094 * @param type the type of socket to open "UDP" or "TCP" 00095 * @param id id to give the new socket, valid 0-4 00096 * @param port port to open connection with 00097 * @param addr the IP address of the destination 00098 * @return true only if socket opened successfully 00099 */ 00100 bool open(const char *type, int id, const char* addr, int port); 00101 00102 /** 00103 * Sends data to an open socket 00104 * 00105 * @param id id of socket to send to 00106 * @param data data to be sent 00107 * @param amount amount of data to be sent - max 1024 00108 * @return true only if data sent successfully 00109 */ 00110 bool send(int id, const void *data, uint32_t amount); 00111 00112 /** 00113 * Receives data from an open socket 00114 * 00115 * @param id id to receive from 00116 * @param data placeholder for returned information 00117 * @param amount number of bytes to be received 00118 * @return the number of bytes received 00119 */ 00120 int32_t recv(int id, void *data, uint32_t amount); 00121 00122 /** 00123 * Closes a socket 00124 * 00125 * @param id id of socket to close, valid only 0-4 00126 * @return true only if socket is closed successfully 00127 */ 00128 bool close(int id); 00129 00130 /** 00131 * Allows timeout to be changed between commands 00132 * 00133 * @param timeout_ms timeout of the connection 00134 */ 00135 void setTimeout(uint32_t timeout_ms); 00136 00137 /** 00138 * Checks if data is available 00139 */ 00140 bool readable(); 00141 00142 /** 00143 * Checks if data can be written 00144 */ 00145 bool writeable(); 00146 00147 private: 00148 BufferedSerial _serial; 00149 ATParser _parser; 00150 00151 char _ip_buffer[16]; 00152 char _mac_buffer[18]; 00153 }; 00154 00155 #endif
Generated on Wed Jul 20 2022 22:18:34 by 1.7.2