Hi Readers,

Today I would like to present you how we can create TCP Server and Client on ESP8266 modules. For purposes of this post we are assuming that an Access point will be also a TCP Server and a Station will be also a Client.

We will reuse commands from my previous posts with list of commands needed to create a Station and an Access point.

Server

So let’s start with the Server. To do that first we need to set one of the modules to work as an Access point to create Wifi network on which we could operate, send commands and etc.

 // Creating Access point – described here:  https://gettoknowthebob.wordpress.com/2016/04/02/second-contact-esp8266-access-point/

AT+RST

AT+CWMODE=2

AT+CWSAP=””,””,,

AT+CIFSR

// Creating TCP Server

AT+CIPMUX=1 – This commands prepares ESP8266 to work with multiple connections. But also we need to remember that if this settings is not set to 1 then Server will not work.

AT+CIPSERVER=1, – Creating and starting Server you can set port number bnut if you don’t want to set it default port number will be set to 333.

Example:

 // Creating Access point

AT+RST

AT+CWMODE=2

AT+CWSAP=”TestNetworkSSID”,”TestPassword”,5,3

AT+CIFSR

// Creating TCP Server

AT+CIPMUX=1

AT+CIPSERVER=1,80

TCP/UDP Client

We need to set second module to work as an Station which will connect to our example Access point and Server.

 // Creating Station – described here:  https://gettoknowthebob.wordpress.com/2016/04/02/second-contact-esp8266-access-point/

AT+RST

AT+CWMODE=1

AT+CWLAP

AT+CWJAP=””,””

AT+CIFSR

// Creating TCP Client

AT+CIPSTART=”TCP”,””, – This command starts the TCP Client (you can replace TCP with UDP)

Example:

 // Creating Station

AT+RST

AT+CWMODE=1

AT+CWLAP

AT+CWJAP=”TestNetworkSSID”,”TestPassword”

AT+CIFSR

// Creating TCP Client

AT+CIPSTART=”TCP”,”192.168.4.1″,80

Github repository: https://goo.gl/ii9xsz

Be positive and stay calm!

Cheers,

Radek

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s