-->
Page 1 of 1

Multiple issues and out of time

PostPosted: Fri Mar 20, 2015 1:16 pm
by MartinV279
Heya guys. I've just received my ESP8266 (via AliExpress) and I've instantly hit problems. I am more than 90% sure it's not the hardware but any help will be more than welcome.
I have on my disposal Arduino Leonardo (original), Arduino MEGA 2560 R3 clone and ESP8266. The connections I've used are:
- For the Leonardo (esp -> leonardo) : Vcc ->3.3V; GND -> GND; Rx ->Tx1; Tx->Rx1; CH_PD -> 3.3V; RST,GPIO0,GPIO2 -> Not attached).
- For the Mega (esp ->mega): Vcc ->3.3V; GND -> GND; Rx ->Tx1; Tx->Rx1; CH_PD -> 3.3V; RST,GPIO0,GPIO2 -> Not attached).

When I use the Leonardo with this setup (and the following attached code) I get something, but with the Mega nothing. This is a code found somewhere on the internet and is for reading from a server. My first question is, can the ESP8266 go faster than 9600 baud? It seems like that's the rate because it's the only rate in which it works. And my second question is, how to send data to another computer via WiFi( probably ad-hoc) or a server? And for the last, how to create a server and make it listen.

Here's the code:

Code: Select all#define SSID        "internet"
#define PASS        "asdfghjkl"
#define DST_IP      "https://data.sparkfun.com/streams/QG4OX6A7XVFlRnXOQEmj"    //baidu.com
void setup()
{
  // Open serial communications and wait for port to open:
  Serial1.begin(9600);
  Serial1.setTimeout(5000);
  Serial.begin(9600);  //can't be faster than 19200 for softserial
 
  delay(6000);
 
 
  Serial.println("ESP8266 Demo");
  //test if the module is ready
  Serial1.println("AT+RST");
  delay(1000);
  while( Serial1.find("ready") < 1);
  Serial.println("Module is ready");
  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
  Serial1.println("AT+CIPMUX=0");
}


void loop()
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += DST_IP;
  cmd += "\",80";
  Serial1.println(cmd);
  Serial.println(cmd);
  if (Serial1.find("Error")) return;
  cmd = "GET / HTTP/1.0\r\n\r\n";
  Serial1.print("AT+CIPSEND=");
  Serial1.println(cmd.length());
  if (Serial1.find(">"))
  {
    Serial.print(">");
  } else
  {
    Serial1.println("AT+CIPCLOSE");
    Serial.println("connect timeout");
    delay(1000);
    return;
  }
 
  Serial1.print(cmd);
  delay(4000);
  //Serial.find("+IPD");
  while (Serial1.available())
  {
    char c = Serial1.read();
    Serial.write(c);
    if (c == '\r') Serial.print('\n');
  }
  Serial.println("====");
  delay(1000);
}


boolean connectWiFi()
{
  Serial1.println("AT+CWMODE=1");
  String cmd = "AT+CWJAP=\"";
  cmd += SSID;
  cmd += "\",\"";
  cmd += PASS;
  cmd += "\"";
 
  Serial1.println(cmd);
  delay(2000);
  if (Serial1.find("OK"))
  {
    Serial.println("OK, Connected to WiFi.");
    return true;
  } else
  {
    Serial.println("Can not connect to the WiFi.");
    return false;
  }
}


And this is the output I get when using Arduino Leonardo:

Image

The red squares are (I suppose) what the module reads. The information is inconsistent as sometimes it prints out SEND OK and sometimes not. Sometimes loads of information, sometimes minimal sometimes not at all.

Thank you in advance! Also, any tutorial or anything that can help please send/post it.

Re: Multiple issues and out of time

PostPosted: Fri Mar 27, 2015 10:14 pm
by ricg
Checkout this site: http://www.electrodragon.com/w/ESP8266
It should have answers to your questions. Including documentation on the AT cmd set, examples, info about firmware, etc..