ESP8266 WIFI module
I just got a ESP8266 WIFI module I ordered a few weeks ago. This is the pinout:
Just a quick warning: It seems that the inputs are not 5V tolerant, so be careful and do not connect the module to Arduino or USB serial adapter running at 5V or you may fry it. You must use 5V to 3.3V level converter if you want to connect it to 5V.
I suggest trying it out with USB to TTL converter first – you send commands from the PC and then advancing onto microcontroller.
I first tried to connect with it by just connecting GND to ground, VCC to 3.3V from Arduino UNO with 100uF capacitor added between GND and 3.3V and UTXD to RXD and URXD to TXD of CP2102 USB to serial converter (similiar to this but using external usb serial converter). I just couldn’t get it working, but after some searching around the internet I found out that there are actually two flavours of this board around (take a look here). Mine also needed to have CH_PD connected to 3.3V. The last link also says that GPIO0 needs to be connected to GND, however just for testing it doesn’t seem to be needed.
When CH_PD is connected to 3.3V the module boots up. The red led will stay on, the blue will blink on bootup. The module will send some garbage data at the serial connection and then a \r\n ready\r\n. My module works at 115200 baud.
If you got the “ready” message you can send a test command “AT\r\n” or maybe “AT+RST\r\n” to see the module responding. Each command should end with \r\n (0x13 0x10) characters (in RealTerm you should check the CR and LF checkboxes and use Send ASCII button to send the command in the box). When the module receives the command the blue led will flash. The AT+RST command will reset the module. The AT command won’t do anything but the module will respond with OK.
Following are some more complicated commands, if you want more in depth knowledge of what they actually do and how to use them you should check out the following manuals: 😉
http://www.electrodragon.com/w/Wi07c
You can check the working mode by command AT+CWMODE? and set it by command AT+CWMODE=3 (mode 3 STA+AP for example). The module may need a restart to get into the desired mode. In mode 1 and 3 you can use the command AT+CWLAP to check for the available access points and their RSSI data.
You can connect the module to access point by AT+CWJAP=”id”,”password” command. The password should be actual password not a passphrase, if you look at the settings of your router, you should proabably see them both. The AT+CWJAP? command won’t tell you anything about connection status, but AT+CIFSR will (Error if no connection, IP otherwise). You can quit the AP by AT+CWQAP.
When in mode 3 STA+AP the module can be connected to another access point and a PC can be connected to it, however the forwarding doesn’t seem to work so the PC can only access the module and not the external network (the module doesn’t seem to work as a router). When connected with PC to the module, you can check the PC and module IP by running the ipconfig command. My module has IP of 192.168.4.1 and PC from 192.168.4.101 on.
When you have PC connected to the module you can try the server and client connections to the module.
For connecting to the server on the PC you can use the AT+CIPSTART command. You can quickly set up a terminal running as a server on PC by using RealTerm. Type server:9999 in port field and click open. Windows may ask you for permission to let the program access the internet. For connecting to server either single connection mode (AT+CIPMUX=0) or multiconnection mode (AT+CIPMUX=1) can be used. Here only multiconnection mode will be demonstrated as it is more useful. In single connection mode just omit the connection id number in CIPSEND command. The PC should be connected to the module WIFI and the server should be set up on PC. Now you can switch to multiconnection mode and then open a connection to PC (AT+CIPSTART=4,”TCP”,”192.168.4.100″,9999). When the connection is estabilished you can try sending some data from PC via the socket. The data will be received using +IPD command. You can also try sending some data from the module using AT+CIPSEND=4,5 command (4 is the id of connection and 5 is the number of bytes to send). You should enter 5 bytes of data after you receive the > character from the module. The data should show up in the receiving terminal.
Server terminal:
Closing link:
For the server mode on module to work multiconnection mode has to be enabled. This can be done by command AT+CIPMUX=1. To open a server on a specifed port a command AT+CIPSERVER=1,8888 Here the 1 means open server port and 8888 is the port number. After you configure the server port on the module you can use RealTerm to connect to it. If you type 192.168.4.1:8888 into the port and click Open button you will connect to the module (WIFI to the module must be estabilished). When the PC connects to the module, the module will output “Link”. Any characters typed into the terminal or sent by Send command will be received by the module by +IPD command. You may use AT+CIPSEND command to reply to the connecting terminal.
So that’s it for now. Note that this test has been done on close range and for now only on direct connection (wifi pc to module), I have not yet tested a connection via router or to the internet. However the module seems to connect to my router which is ca. 20m away in another building (some android devices have issues with getting a connection) so the range doesn’t seem to be too bad. One thing that would also have to be checked is if the MAC addresses of the modules are unique and fixed.
Be sure to also check the follow-up about connecting to internet / fetching a webpage here. You can also check out how to update the firmware of the module.
Thank you for this. It help me test my module.
Thank you very much!!!
Hi would you mind letting me know which webhost you’re using?
I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a
lot quicker then most. Can you suggest a good
internet hosting provider at a fair price? Thank you, I appreciate
it!
This actually doesn’t have anything to do with the post 😛 I’m using a local hosting provider on a shared hosting for this site. For quick loading you should minimize the graphics and content needed for the site (no big background images, only use plugins that are really needed for the site, eliminate unneeded external fonts). I’m using Responsive theme for this blog, which helps to speed things up and also allows users to view the blog from different devices.
If you are a bit of a hacker, you can get a decent price for a VPS at digitalocean, but if you just want to blog, you should probably get a managed hosting plan…
Hi,
I try connect to my server application and I get an answer:
ERROR
AT+CIPSTART=4,”TCP”,”192.168.1.2″,2000
4,CLOSED
Check if you can connect to another known working server (eg. a website port 80) so you know that your connection is OK. Also try connecting to your server from another computer / client to check that you don’t have any firewall issues.