Simple Communication through ESP8266 Wifi module

Previously….

My previous post shows how I got life from my ESP8266 here: https://petestechprojects.wordpress.com/2014/11/30/esp8266-4-wifi-module-bring-up/

Once I got life and updated to latest firmware, I changed my baud rate to 9600 by giving “AT+CIOBAUD=9600”.

Connecting to my Wifi AP

  1. Set my mode to “AT+CWMODE=3” to allow for both client and server mode (at least that is what I think it is).
  2. Scan for access points with AT+CWLAP command.
  3. Join the AP by sending AT+CWJAP=”[YourNetwork]”,”[YourPassword]”
    1. I used an AP with WEP encryption and it worked for me.
    2. I used an AP with WPA encryption and it doesn’t work for me.  Need to debug later.
  4. Check that you get IP assignment from the router with AT+CIFSR
    1. I got to IP’s, 192.168.4.1 and 192.168.0.128.
    2. The first one (192.168.4.1) is the IP of the AP that the ESP8266 when operating as an AP (remember I set to CWMODE=3 in step one).  Not sure how to use it yet.
    3. The second one (192.168.0.128) is the one my Dlink AP assigned to the ESP8266.  This is the one I know how to use for now.

Here is a log capture of my TeraTerm window.


AT+CWMODE=3

OK
AT+CWLAP
+CWLAP:(4,”HOME-2372″,-93,”14:ab:f0:09:23:70″,1)
+CWLAP:(0,”xfinitywifi”,-94,”16:ab:f0:09:23:70″,1)
+CWLAP:(2,”OfficeWireless”,-49,”06:26:5a:b8:c3:e3″,11)
+CWLAP:(4,”SureWest-1C”,-87,”6c:b0:ce:e8:a5:1c”,6)
+CWLAP:(2,”n_Network”,-49,”00:26:5a:b8:c3:e3″,11)
+CWLAP:(1,”PetesPrivateNetwork”,-49,”0a:26:5a:b8:c3:e3″,11)
+CWLAP:(3,”Home Network”,-86,”74:44:01:93:84:78″,10)
+CWLAP:(2,”n_Network”,-58,”bc:ae:c5:b0:e1:f4″,11)

OK
AT+CWJAP=”PetesPrivateNetwork”,”xxxxxxxxxxx”)

OK

AT+CIFSR
192.168.4.1
192.168.0.128

OK


Setting up the ESP8266 as a server on Wifi network.

Now that I have the ESP8266 connected to my Dlink Wifi router, I want to communicate through it.  I found that I can use a simple Telnet client to talk to the ESP8266 after setting up the ESP8266 as a server.

Need for CIPMUX first

I spent a long time trying to determine why I couldn’t initiate the server on the ESP8966.  Googl’ing and stumbled on that the CIPMUX mode needed to be set first.  I used AT+CIPMUX=1 for multiple connections.  (I had problems later with with sending out data with mode 0 which is single connections.)

Starting and connecting to the Server

To start the server at port 8888….  AT+CIPSERVER=1,8888.  (Remember the IP address is found above when I gave the AT+CIFSR command.)

Once the server is started, I opened a Telnet window from TeraTerm like this….

TeraTermTelnetOpening

Whala… I get “Link” out of the ESP8266 serial port.

Sending strings back and forth

Typing in the telnet window and hitting carriage return will send the string through Wifi -> ESP8266 -> Serial pins on 8266 -> FTDI cable -> TeraTerm on serial port at 9600 baud.  You should get something like this….

+IPD,0,44:asdkdsflljlasdhf

The 0 in the above string that shows up in the serial port is the channel.  If you have multiple clients hook up to it, this is how you tell who is “talking”.  This is also how you send back strings using the AT+CIPSEND command.  For example, if you want to send back “what was that?” to the client that send the jumble above…

In your serail port window, send AT+CIPSEND=0,16

This will bring up a “>” prompt.  The ESP8266 is waiting to send 16 characters.  Now type in “what was that?” and it should magically -> FTDI cable -> ESP8266 -> Wifi ->Telenet window.

Here is a screen shot of the full exchange (click on image so you can read the text)…

ExampleDataTransfer

I installed a simple Telnet App on my Android tablet and could do exchanges to my ESP8266 from across the house.  Yupiieeee!!!!

Advertisements

14 thoughts on “Simple Communication through ESP8266 Wifi module

  1. Pingback: LED’s Control through TTY | PetesTechProjects

  2. Pingback: Mini Server on Arduino + ESP8266 | PetesTechProjects

    • I haven’t tried using the ESP8266 as a Wifi repeater. The only thing I have tried is to use the ESP8266 as access point in CWMODE=3. I could directly connect my Android tablet or phone to that ESP8266 (without using a Wifi router) and send and receive data to the connected Arduino.

      If it were possible, I would think you would still need to have some code on the Arduino that would echo data from one channel to the other. Interesting idea but from my experience with the ESP8266 so far, I think there would be a lot of stability issues since I am seeing a lot of ESP8266 resets when just trying to implement a very simple web server on the Arduino.

      Like

      Reply
  3. Hello Peter,

    Thank you for this post. By following your description I could easily get the same reaction as you “I installed a simple Telnet App on my Android tablet and could do exchanges to my ESP8266 from across the house. Yupiieeee!!!!”.

    With kind regards,
    Wim Dossche

    Like

    Reply
  4. It all works, but can I use the telnet strings in my arduino code?
    for example I want if i send ‘x’ to the ESP8266, I want to turn a led on.
    (serial.read does’nt work when using ESP8266)

    Please tell we how this would be possible.
    Thanks in advance.

    Like

    Reply
    • Casper,

      In my later posts, I am doing a lot more complicated serial communication controls. I have a routine that does use serial.read to read 1 character at a time and builds a string until reaching the CR/LF.

      Take a look at my post “LED’s Control through TTY“. My entire Arduino code is there. I read for key words from a TTY client and turn on LED’s when specific keywords are found. That should get you a good start.

      Good Luck,
      Peter

      Like

      Reply
  5. Hi Peter .
    Very good post . I learn a lot from your posts.
    have some thing not understand :
    The esp8266 setup server Ip adress is 192.168.4.1 or 192.168.0.128 ?
    is the AP and Server ip adress here same ?

    Thanks
    zq

    Like

    Reply
    • zq,

      The ESP8266 can connect to a Wifi router (client mode) and operate as a Wifi access point simultaneously.

      192.168.4.1 is the IP address if you are connecting to the ESP8266 Wifi AP. You can use a client device to join the ESP8266 Wifi AP and then communicate to it at 192.168.4.1. You don’t need to have any other Wifi AP or Wifi router this way.

      192.168.0.128 is the IP address that the ESP8266 was given by the router that I connected to (ESP8266 acting as client). That address will change depending on the router. If you have another device connected to the same Wifi router as the ESP8266 joined, you use the 192.168.0.128 address to communicate with the ESP8266.

      Hope that helps clarify.

      Regards,
      Peter

      Like

      Reply
  6. hey thanks for the post great post.
    Can I establish communication between 2 esp’s by setting mode 3.
    Also can i change ssid and password of each chip.?
    If yes then how.
    please leave a reply.

    Like

    Reply
    • Ashwini,

      I don’t recall where I found the original AT command list, but here is one that came up near the top of a Google search for “ESP8266 AT Commands”…. http://wiki.iteadstudio.com/ESP8266_Serial_WIFI_Module. There you will find the command to set the SSID and password by using “AT+ CWSAP”. The table in the link should give you the details to set your SSID, password and some other parameters if you would like.

      I have not tried using 2 esp’s to communicate between each other, but I don’t see a reason why that wouldn’t work as long as you set up one to be the AP and the other connects up to it as a client. I would think you would just need to

      1. Set both ESP8266’s to “AT+CWMODE=3”
      2. Set up ESP8266#1 with a unique SSID …. ie: AT+CWSAP=MyTestESPn1,Hello
      3. Send command to ESP8266#2 to join ESP8266#1’s Wifi network… ie: AT+CWJAP=MyTestESPn1,Hello

      I didn’t test it but think that should work.

      Good Luck,
      Peter

      Like

      Reply
      • thanks peter.
        I got it. I tried it in nodemcu firmware and it works properly.
        Hav u work with modemcu. I want to sort the string in lua.
        i need proper syntax. If you know it or if u can try it please leave a reply.

        Thank u so much again….

        Like

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