RTOS_MSPM0  1.1
ECE445M starter code
esp8266.h
1 //*********************** ESP8266.h ***********************
2 // Program written by:
3 // - Steven Prickett steven.prickett@gmail.com
4 //
5 // Driver for ESP8266 module to act as a WiFi client or server
6 //
7 //*********************************************************
8 /* Modified by Jonathan Valvano, Sept 19, 2015
9  Modified by Andreas Gerstlauer, Apr 13, 2020
10  */
11 
12 #ifndef ESP8266_H
13 #define ESP8266_H
14 
15 #include <stdint.h>
16 
17 #define ESP8266_ENCRYPT_MODE_OPEN 0
18 #define ESP8266_ENCRYPT_MODE_WEP 1
19 #define ESP8266_ENCRYPT_MODE_WPA_PSK 2
20 #define ESP8266_ENCRYPT_MODE_WPA2_PSK 3
21 #define ESP8266_ENCRYPT_MODE_WPA_WPA2_PSK 4
22 
23 #define ESP8266_WIFI_MODE_CLIENT 1
24 #define ESP8266_WIFI_MODE_AP 2
25 #define ESP8266_WIFI_MODE_AP_AND_CLIENT 3
26 
27 //-------------------ESP8266_Init --------------
28 // Initializes the module
29 // Inputs: RX and/or TX echo for debugging
30 // Outputs: 1 for success, 0 for failure (no ESP detected)
31 int ESP8266_Init(int rx_echo, int tx_echo);
32 
33 //-------------------ESP8266_Connect --------------
34 // Bring interface up and connect to Wifi
35 // Inputs: enable debug output
36 // Outputs: 1 on success, 0 on failure
37 int ESP8266_Connect(int verbose);
38 
39 //-------------------ESP8266_StartServer --------------
40 // Start server on specific port
41 // Inputs: port and server timeout
42 // Outputs: 1 on success, 0 on failure
43 int ESP8266_StartServer(uint16_t port, uint16_t timeout);
44 
45 //-------------------ESP8266_StopServer --------------
46 // Stop server and set to single-client mode
47 // Inputs: none
48 // Outputs: 1 on success, 0 on failure
49 int ESP8266_StopServer(void);
50 
51 //----------ESP8266_Reset------------
52 // Soft resets the esp8266 module
53 // Input: none
54 // Output: 1 if success, 0 if fail
55 int ESP8266_Reset(void);
56 
57 //---------ESP8266_Restore-----
58 // Restore the ESP8266 module to default values
59 // Inputs: none
60 // Outputs: 1 if success, 0 if fail
61 int ESP8266_Restore(void);
62 
63 //---------ESP8266_GetVersionNumber----------
64 // Get status
65 // Input: none
66 // Output: 1 if success, 0 if fail
67 int ESP8266_GetVersionNumber(void);
68 
69 //---------ESP8266_GetMACAddress----------
70 // Get MAC address
71 // Input: none
72 // Output: 1 if success, 0 if fail
73 int ESP8266_GetMACAddress(void);
74 
75 //---------ESP8266_SetWifiMode----------
76 // Configures the esp8266 to operate as a wifi client, access point, or both
77 // Input: mode accepts ESP8266_WIFI_MODE constants
78 // Output: 1 if success, 0 if fail
79 int ESP8266_SetWifiMode(uint8_t mode);
80 
81 //---------ESP8266_SetConnectionMux----------
82 // Enables the esp8266 connection mux, required for starting tcp server
83 // Input: 0 (single) or 1 (multiple)
84 // Output: 1 if success, 0 if fail
85 int ESP8266_SetConnectionMux(uint8_t enabled);
86 
87 //---------ESP8266_ListAccessPoints----------
88 // Lists available wifi access points
89 // Input: none
90 // Output: 1 if success, 0 if fail
91 int ESP8266_ListAccessPoints(void);
92 
93 //----------ESP8266_JoinAccessPoint------------
94 // Joins a wifi access point using specified ssid and password
95 // Input: SSID and PASSWORD
96 // Output: 1 if success, 0 if fail
97 int ESP8266_JoinAccessPoint(const char* ssid, const char* password);
98 
99 // ----------ESP8266_QuitAccessPoint-------------
100 // Disconnects from currently connected wifi access point
101 // Inputs: none
102 // Outputs: 1 if success, 0 if fail
103 int ESP8266_QuitAccessPoint(void);
104 
105 //----------ESP8266_ConfigureAccessPoint------------
106 // Configures esp8266 wifi soft access point settings
107 // Use this function only when in AP mode (and not in client mode)
108 // Input: SSID, Password, channel, security
109 // Output: 1 if success, 0 if fail
110 int ESP8266_ConfigureAccessPoint(const char* ssid, const char* password, uint8_t channel, uint8_t encryptMode);
111 
112 //---------ESP8266_GetIPAddress----------
113 // Get local IP address
114 // Input: none
115 // output: 1 if success, 0 if fail
116 int ESP8266_GetIPAddress(void);
117 
118 //---------ESP8266_SetSSLClientConfiguration----------
119 // Set SSL client configuration
120 // Requires certificates to be flashed into the ESP firmware
121 // Inputs: enable/disable client/server certificate checks
122 // Output: 1 if success, 0 if fail
123 int ESP8266_SetSSLClientConfiguration(int verifyClient, int verifyServer);
124 
125 //---------ESP8266_SetSSLBufferSize----------
126 // Set SSL buffer size
127 // Inputs: buffer size between 2048 and 4096
128 // Output: 1 if success, 0 if fail
129 int ESP8266_SetSSLBufferSize(uint16_t bufferSize);
130 
131 //---------ESP8266_MakeTCPConnection----------
132 // Establish TCP or SSL connection
133 // The ESP only seems to have limited SSL support, does not work with all servers
134 // Inputs: IP address or web page as a string, port, and keepalive time (0 if none)
135 // Output: 1 if success, 0 if fail
136 int ESP8266_MakeTCPConnection(char *IPaddress, uint16_t port, uint16_t keepalive, int ssl);
137 
138 //---------ESP8266_Send----------
139 // Send a packet to server
140 // Input: payload to send
141 // Output: 1 if success, 0 if fail
142 int ESP8266_Send(const char* fetch);
143 
144 //---------ESP8266_SendBuffered----------
145 // Send a string to server using ESP TCP-send buffer
146 // Input: payload to send
147 // Output: 1 if success, 0 if fail
148 int ESP8266_SendBuffered(const char* fetch);
149 
150 //---------ESP8266_SendBuferedStatus----------
151 // Check status of last buffered segment
152 // Input: none
153 // Output: 1 if success, 0 if fail
154 int ESP8266_SendBufferedStatus(void);
155 
156 //---------ESP8266_Receive----------
157 // Receive a string from server
158 // Reads from data input until end of line or max length is reached
159 // Input: buffer and max length
160 // Output: 1 and null-terminated string if success, 0 if fail (disconnected)
161 int ESP8266_Receive(char* fetch, uint32_t max);
162 
163 //---------ESP8266_CloseTCPConnection----------
164 // Close TCP connection
165 // Input: none
166 // Output: 1 if success, 0 if fail
167 int ESP8266_CloseTCPConnection(void);
168 
169 //---------ESP8266_SetDataTransmissionMode----------
170 // Set data transmission passthrough mode
171 // Input: 0 not data mode, 1 data mode; return "Link is builded"
172 // Output: 1 if success, 0 if fail
173 int ESP8266_SetDataTransmissionMode(uint8_t mode);
174 
175 //---------ESP8266_GetStatus----------
176 // Get network connection status
177 // Input: none
178 // Output: 1 if success, 0 if fail
179 int ESP8266_GetStatus(void);
180 
181 // --------ESP8266_EnableServer------------------
182 // Enables tcp server on specified port
183 // Inputs: port number
184 // Outputs: 1 if success, 0 if fail
185 int ESP8266_EnableServer(uint16_t port);
186 
187 // ----------ESP8266_SetServerTimeout--------------
188 // Set connection timeout for tcp server, 0-28800 seconds
189 // Inputs: timeout parameter
190 // Outputs: 1 if success, 0 if fail
191 int ESP8266_SetServerTimeout(uint16_t timeout);
192 
193 // ----------ESP8266_WaitForConnection--------------
194 // Wait for incoming connection on server
195 // Inputs: none
196 // Outputs: 1 if success, 0 if fail
197 int ESP8266_WaitForConnection(void);
198 
199 //---------ESP8266_DisableServer----------
200 // Disables tcp server
201 // Input: none
202 // Output: 1 if success, 0 if fail
203 int ESP8266_DisableServer(void);
204 
205 #endif