3

I am testing the wifi module esp8266 with my arduino uno. I made it work with direct connection RX/TX and through softwareserial.

This is my code:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(3, 2); // RX | TX

#define DEBUG true

int ERROR_PIN = 7;
int OK_PIN = 6;

char serialbuffer[400];//serial buffer for request url
const String ssid = "XXX";
const String pw = "XXX";

int state = 0;

void setup() 
{
    delay(1000);
    /**
    // init leds
    pinMode(ERROR_PIN, OUTPUT);
    pinMode(OK_PIN, OUTPUT);

    state = 0;

    digitalWrite(ERROR_PIN, HIGH);
    digitalWrite(OK_PIN, LOW);
    /**/
    // init ports
    Serial.begin(19200);
    Serial.println("initializing esp8266 port...");
    esp8266.begin(19200);
    delay(400);
    // init WIFI
    /**/
    while(!esp8266.available())
    {
        Serial.print("...");
        delay(300);
    }
    Serial.println();
    Serial.println("FINISH esp8266 initializing!");
    //
    /**
    digitalWrite(ERROR_PIN, LOW);
    digitalWrite(OK_PIN, HIGH);
    state = 1;
    /**/
    /**/
    // Setup connection
    sendData("AT+RST\r\n",2000,DEBUG);
    sendData("AT+CWMODE?\r\n",1000,DEBUG);
    //sendData("AT+CWMODE=1\r\n",2000,DEBUG);
    //sendData("AT+RST\r\n",3000,DEBUG);
    //sendData("AT+CWLAP\r\n",6000,DEBUG);
    sendData("AT+CWJAP=\"" + ssid + "\",\""+ pw +"\"\r\n",12000,DEBUG);
    sendData("AT+CIFSR\r\n",8000,DEBUG);
    sendData("AT+CIPMUX=1\r\n", 6000, DEBUG);
    webRequest("");
    /**/
    /**/
}

void loop() 
{
    if (esp8266.available())
    {
        char c = esp8266.read() ;
        Serial.print(c);
        /**
        if(state == 0)
        {
            state = 1;
            digitalWrite(ERROR_PIN, LOW);
            digitalWrite(OK_PIN, HIGH);
        }
        /**/
    }
    else
    {
        /**
        if(state > 0)
        {
            state = 0;
            digitalWrite(ERROR_PIN, HIGH);
            digitalWrite(OK_PIN, LOW);
        }
        /**/
    }   
    if (Serial.available())
    {  
        char c = Serial.read();
        esp8266.print(c);
    }
}

//////////////////////////////////////////////////////////////////////////////
String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    esp8266.print(command); // send the read character to the esp8266
    long int time = millis();
    while( (time+timeout) > millis())
    {
        while(esp8266.available())
        {
            // The esp has data so display its output to the serial window
            char c = esp8266.read(); // read the next character.
            response+=c;
        }
    }
    if(debug)
    {
        Serial.print(response);
    }
    return response;
}
//////////////////////////////////////////////////////////////////////////////////
String webRequest(String url)
{
    String response = "";
    url = "www.google.es";
    //String tmpCommand = "AT+CIPSTART=4," + "\"TCP\",\"" + url + "\",80";
    String tmpSTARTCommmand = "AT+CIPSTART=0,\"TCP\",\"retro.hackaday.com\",80\r\n\r\n";
    String tmpGETCommand = "GET / HTTP/1.1\r\nHost: "; 
    tmpGETCommand += "retro.hackaday.com";
    tmpGETCommand += ":80\r\n\r\n";
    String tmpSENDCommand = "AT+CIPSEND=0," + String(tmpGETCommand.length()) + "\r\n";
    sendData(tmpSTARTCommmand, 8000, DEBUG);
    sendData(tmpSENDCommand, 8000, DEBUG);
    sendData(tmpGETCommand, 15000, DEBUG);
}

This works until the point where I do the webrequest. I receive a Bad request response.

initializing esp8266 port...
.........
FINISH esp8266 initializing!
BâÂúØÐPÊþ^X8Â�Ä^Âú[8ÐûÈâ·CâËØè[8Ð{Èâ·GâÃØRÈ蚉5˜‰0
bÕ
ready
AT+CWMODE?
+CWMODE:3

OK
AV®)AB•«Ë—mX·et","XXX"

OK
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"1a:fe:34:9b:c3:83"
+CIFSR:STAIP,"192.168.1.89"
+CIFSR:STAMAC,"18:fe:34:9b:c3:83"

OK
AT+CIPMUX=1

OK
AV%AMEÕÕ*$‘²troÐ…�‘½µ‰,80
0,CONNECT

OK
AVCIPSEND=0,47
> GE@/!QQAŠrŠ%åõÑ: ÊÑɽB�……¹½µÂ‚%\n\r\nbusy s...

SEND OK

+IPD,0,323:HTTP/1.1 400 Bad Request
Server: nginx/1.6.2
Date: Sat, 04 Apr 2015 16:17:29 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>

OK
"qXÑzÂC!É1âø‚h[•�™cü    ÐQ!}Ñfócú   I]Ø÷ÃBj 1¤(ÑÃÖa”K!~CóbÕ
ready

Any idea?

mpromonet
  • 11,326
  • 43
  • 62
  • 91
blfuentes
  • 2,731
  • 5
  • 44
  • 72

4 Answers4

1
  1. Check if it works perfectly, if you use Hardware serial Rx(pin0), Tx(pin1) and Serial monitor, ESP8266 responds properly.
  2. Try lowering baud rate. Most the time SoftwareSerial and Arduino Uno are not able to handle fast response and loose bit of information.

If you still receiving the garbage response most likely you module have got damaged.

Shankar Gurav
  • 1,057
  • 9
  • 17
  • I tried also through hardware serial and it responds the same... the "busy s..." I am waiting for a different module and I will try with a dedicated power supply to check. I read it could be problem related to it. – blfuentes Apr 22 '15 at 06:31
  • Does the new module resolved your problem? If yes...do you see any difference between framework version? tried your not working module to burn with the version from working module? – Shankar Gurav Jan 03 '16 at 15:38
1

I secceded using this code:

https://github.com/itead/ITEADLIB_Arduino_WeeESP8266/blob/master/ESP8266.cpp

but I have mega2560.. hardware connection: https://github.com/McOffsky/Arduino_ESP8266_HTTP_Client

Atheel
  • 187
  • 1
  • 3
  • 16
  • Could you post please the schema and the code you are using? – blfuentes Aug 23 '15 at 12:53
  • its same Code from tHis example: https://github.com/itead/ITEADLIB_Arduino_WeeESP8266/blob/master/examples/HTTPGET/HTTPGET.ino my prob was witH tHe url... it seems I must tipe http:// befor tHe url. – Atheel Aug 24 '15 at 06:01
0

You shouldn't include port number in get command. Port already specified at cipstart.Something wrong in your http request text. Everything else (sending request and getting response )is ok. http://en.m.wikipedia.org/wiki/Hypertext_Transfer_Protocol

Tamer Aktaş
  • 416
  • 4
  • 13
0

Check your power supply. I have had these random characters showed up every once in a while when I simply connected the module directly to the Arduino power pins. Those seems like the module is resetting itself constantly and spits out the module info.

My solution was to connect another 3.3v regulator in parallel with Arduino. Connect the grounds together, and supply ESP8266 from that 3.3v power source. Problem solved.

gcmike
  • 1