ESP8266 Wi-Fi module can be configured as a Station / Client or an Access Point. Once it the ESP8266 module is configured in either mode or both mode simultaneously it can be used to communicate with other Access Points or Clients. ESP8266 module can handle multiple connections if configured and send / receive data.
Configure ESP8266 Server
Get local IP address.
Configure TCP Server.
A value of
1 creates the the server while
0 deletes the server in which case the module needs to restarted. The port can be optionally specified as a second argument otherwise it the default port of
333 is used.
Set connection mode.
Single connection mode is set with a
0 value while multiple connection mode is set with a value of
1. This mode can only be changed after all connections are disconnected. If server is started, reboot is required.
Set transfer mode.
Default value of
1 sets transfer to unvarnished transmission mode, while
0 sets it to normal mode.
Get current server timeout.
Set server timeout.
Server timeout value can range between
7200 seconds. Default value is
Start TCP or UDP connection in single connection mode.
The connection type can be either
192.168.0.65 is the IP address of the remove server the connection is being made to.
333 is the port of the same remote server.
Start TCP or UDP connection in multiple connection mode.
The first argument is the
id of the connection. All other arguments are identical to single connection mode.
Send data in single connection mode.
When in single connection mode only the length of the data in bytes is required. Maximum length is 2048 bytes. Send command should be immediately followed by the actual data that matches the length specified.
Send data in multiple connection mode.
When in multiple connection mode the first parameter is the
id of the connection followed by
length in bytes.
Receive data in single connection mode.
The length of the data that is to be received is specified first followed by a colon and the variable where the received data will be stored.
Receive data in multiple connection mode.
In addition to the length and data the connection id needs to be specified as the first argument.
Close TCP or UDP connection in single connection mode.
Close TCP or UDP connection in multi connection mode.
To close all connections a value of
5 can be used, otherwise the connection
id should be specified.
Check current connection status.
Current module condition is determined by the STATUS value which can be
2 for IP acquired,
3 for connected and
4 for disconnected. In multiple connection mode the
id of the connection is also listed. Connection type will be either
ip address and
port of the connection are listed as well. The last variable represents the module mode,
0 for client mode or
1 for server mode.