ESP8266: Send & Receive Data

Send & Receive Data with ESP8266 Wi-Fi Module

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.

AT+CIFSR

 

Configure TCP Server.

AT+CIPSERVER=1

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.

AT+CIPMUX=1

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.

AT+CIPMODE=0

Default value of 1 sets transfer to unvarnished transmission mode, while 0 sets it to normal mode.

 

Get current server timeout.

AT+CIPSTO?

 

Set server timeout.

AT+CIPSTO=10

Server timeout value can range between 0 and 7200 seconds. Default value is 10 seconds.

 

Start TCP or UDP connection in single connection mode.

AT+CIPSTART="TCP","192.168.0.65","333"

The connection type can be either TCP or UDP. 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.

AT+CIPSTART=1,"TCP","192.168.0.65","333"

The first argument is the id of the connection. All other arguments are identical to single connection mode.

 

Send Data

Send data in single connection mode.

AT+CIPSEND=15

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.

AT+CIPSEND=1,15

When in multiple connection mode the first parameter is the id of the connection followed by length in bytes.

 

Receive Data

Receive data in single connection mode.

+IPD,4:data

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.

+IPD,1,4:data

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.

AT+CIPCLOSE

 

Close TCP or UDP connection in multi connection mode.

AT+CIPCLOSE=1

To close all connections a value of 5 can be used, otherwise the connection id should be specified.

 

Check current connection status.

AT+CIPSTATUS

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 TCP or UDP. The 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.

  • Sanix

    Thank’s, it was very helpful for my personal project!

  • சௌந்திரராசன் சண்முகம்

    Hello…

    I am developing a new IOT Project. I need to connect bluetooth or WI-FI Modules 5 or more than that. Can anyone suggest me good Module..

    ONE MASTER TO MULTIPLE SLAVE…

    Thanks in Advance..

  • vicky

    How can i upload data of temprature and humidity on specific server if i used esp8266 wifi module and aurdino