Wi07c

From ElectroDragon
Revision as of 12:00, 4 September 2014 by Chao (talk | contribs) (new version 091)
Jump to navigation Jump to search

Other specifications

  • Module power 3.3V, regular current consumption at 70ma, peak current at 240mA (300mA must be able to provided)
  • +20Dbm power, 100M max transmitting distance on ideal circumstance.
  • It is common and correct to see some random error data when module is power up, and end up with "ready" (Turn baud rate to 115200 can see this actual debug data, this is used for firmware updating)

AT Commands

Format

  • Baud rate at 57600, use option "send new line" for each command
  • x is the commands
Set Inquiry Test Execute
AT+<x>=<…> AT+<x>? AT+<x>=? AT+<x>
AT+CWMODE=<mode> AT+CWMODE? AT+CWMODE=? -
Set the network mode Check current mode Return which modes supported -

Commands

  • carefully there are must be no any spaces between the " and IP address or port
Commands Description Type Set/Execute Inquiry test Parameters Examples
AT+RST restart the module basic - - - -
AT+CWMODE wifi mode wifi AT+CWMODE=<mode> AT+CWMODE? AT+CWMODE=? 1= Sta, 2= AP, 3=both
AT+CWJAP join the AP wifi AT+ CWJAP =<ssid>,< pwd > AT+ CWJAP? - ssid = ssid, pwd = wifi password
AT+CWLAP list the AP wifi AT+CWLAP
AT+CWQAP quit the AP wifi AT+CWQAP - AT+CWQAP=?
AT+ CWSAP set the parameters of AP wifi AT+ CWSAP= <ssid>,<pwd>,<chl>, <ecn> AT+ CWSAP? ssid, pwd, chl = channel, ecn = encryption Connect to your router: :AT+CWJAP="www.electrodragon.com","helloworld"; and check if connected: AT+CWJAP?
AT+ CIPSTATUS get the connection status TCP/IP AT+ CIPSTATUS
AT+CIPSTART set up TCP or UDP connection TCP/IP 1)single connection (+CIPMUX=0) AT+CIPSTART= <type>,<addr>,<port>; 2) multiple connection (+CIPMUX=1) AT+CIPSTART= <id><type>,<addr>, <port> - AT+CIPSTART=? id = 0-4, type = TCP/UDP, addr = IP address, port= port Connect to another TCP server, set multiple connection first: AT+CIPMUX=1; connect: AT+CIPSTART=4,"TCP","X1.X2.X3.X4",9999
AT+CIPSEND send data TCP/IP 1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length> AT+CIPSEND=? send data: AT+CIPSEND=4,15 and then enter the data
AT+CIPCLOSE close TCP or UDP connection TCP/IP AT+CIPCLOSE=<id> or AT+CIPCLOSE AT+CIPCLOSE=?
AT+CIFSR Get IP address TCP/IP AT+CIFSR AT+ CIFSR=?
AT+ CIPMUX set mutiple connection TCP/IP AT+ CIPMUX=<mode> AT+ CIPMUX? 0 for single connection 1 for mutiple connection
AT+ CIPSERVER set as server TCP/IP AT+ CIPSERVER= <mode>[,<port> ] mode 0 to close server mode, mode 1 to open; port = port turn on as a TCP server: AT+CIPSERVER=1,8888, check the self server IP address: AT+CIFSR=?
+IPD received data

Pin Definition

200px

First time use guide

Using arduino as serial port montior

  • Connect VCC and GND of module to 3v3 and GND of arduino, RXD to TXD of arduino, and TXD to RXD of arduino (should add resistors or logic level shifter for logic level and protect IOs)
  • Simply upload blink sketch to arduino, to ensure MCU won't use serial port
  • User any other serial port montior like SSCOM32 we used here, available here UART
  • Send AT will receive OK in return

Steps

  • restart the module, received some strange data, and "ready"
  • change the working mode to 3, AP+STA
  • search available wifi spot
  • join the mercury router spot (ops, the wifi password is here :) )
  • check if connected successfully
  • turn on multiple connection
  • connect to remote TCP server 192.168.1.104 (the PC)
  • send data via channel 4, 5 bytes length (see socket test result below, only "elect" received)
  • setup TCP server, on port 9999
  • check module IP address
  • PC as a TCP client connect to module using socket test, send data

ESP8266-test-1.pngESP8266-test-2.png

Socket test running result

ESP8266-test-3.pngESP8266-test-4.png

Other Arduino Demo Code

  • In this case, the wifi module still connect to hardware serial (software serial port can not higher than 19200 baud rate), and another software serial port should be created on arduino and print out via another serial port
  • So the connection should be
Wifi's uart to arduino hardware uart; 
arduino's sotware UART to another serial port device, for example like FTDI basic, CP2102 breakout, etc, and this serial port device can connect to PC to read data
  • change the SSID and password in code for your wifi router
 
#include <SoftwareSerial.h>
#define SSID        "xxxxxxxx"
#define PASS        "xxxxxxxx"
#define DST_IP      "220.181.111.85"    //baidu.com
SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  Serial.setTimeout(5000);
  dbgSerial.begin(9600);  //can't be faster than 19200 for softserial
  dbgSerial.println("ESP8266 Demo");
  //test if the module is ready
  Serial.println("AT+RST");
  delay(1000);
  if (Serial.find("ready"))
  {
    dbgSerial.println("Module is ready");
  }
  else
  {
    dbgSerial.println("Module have no response.");
    while (1);
  }
  delay(1000);
  //connect to the wifi
  boolean connected = false;
  for (int i = 0; i < 5; i++)
  {
    if (connectWiFi())
    {
      connected = true;
      break;
    }
  }
  if (!connected) {
    while (1);
  }
  delay(5000);
  //print the ip addr
  /*Serial.println("AT+CIFSR");
  dbgSerial.println("ip address:");
  while (Serial.available())
    dbgSerial.write(Serial.read());*/
  //set the single connection mode
  Serial.println("AT+CIPMUX=0");
}
void loop()
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += DST_IP;
  cmd += "\",80";
  Serial.println(cmd);
  dbgSerial.println(cmd);
  if (Serial.find("Error")) return;
  cmd = "GET / HTTP/1.0\r\n\r\n";
  Serial.print("AT+CIPSEND=");
  Serial.println(cmd.length());
  if (Serial.find(">"))
  {
    dbgSerial.print(">");
  } else
  {
    Serial.println("AT+CIPCLOSE");
    dbgSerial.println("connect timeout");
    delay(1000);
    return;
  }
  Serial.print(cmd);
  delay(2000);
  //Serial.find("+IPD");
  while (Serial.available())
  {
    char c = Serial.read();
    dbgSerial.write(c);
    if (c == '\r') dbgSerial.print('\n');
  }
  dbgSerial.println("====");
  delay(1000);
}
boolean connectWiFi()
{
  Serial.println("AT+CWMODE=1");
  String cmd = "AT+CWJAP=\"";
  cmd += SSID;
  cmd += "\",\"";
  cmd += PASS;
  cmd += "\"";
  dbgSerial.println(cmd);
  Serial.println(cmd);
  delay(2000);
  if (Serial.find("OK"))
  {
    dbgSerial.println("OK, Connected to WiFi.");
    return true;
  } else
  {
    dbgSerial.println("Can not connect to the WiFi.");
    return false;
  }
}

Debug and Note

  • Better use standalone power source, not using power from USB-TTL module, it may not able to provide sufficient current.

new version 091

Our engineers are working on the new version, it has a slightly different layout with the image we posted on store, if you receive this one, please note:

  • Connect all the four pins (or only CH_PD) in between to VCC, not necessary to connect 10K resistor, CH_PD ensure the module start from flash, and low mode will enter into updating firmware mode, pin RST can restart the module.

200px Esp8266 wiring.jpg

  • There are two leds on the board, one is power led, another one is status LED, when power up, pwr led keeps on and status led will blink once.
  • baud rate may work at 115200 or 57600