ESP8266 connection - somtimes some characters are not transmitted correctly

Hi folks,

I have connected an ESP9266 module with the help of a SoftwareSerial to my Arduino board and I successfully connected this combination with an existing WiFi network.

SoftwareSerial esp8266(2,3);
esp8266.begin(115200);

So I've implemented a small webserver on the Arduino and now I want to detect which GET parameter was transmitted to the Arduino.

But a esp8266.readString(); will result in different(!) results for nearly every request. as you can see in the attached examples there are some flipped/changed characters in the response.

,82;GET /?pin=1 HTTP/1.1
Host: 10.10.00.139
User,Agent: curl

,82:GET /?phn=1 HTTP/1.0
Host: 10.00.10.139
User-Agent: cur/

has anybody any idea or a hint what may be the problem right here?

Cheers
Dennis

has anybody any idea or a hint what may be the problem right here?

Your software is the ONLY possibility.

Hi PaulS,

many thanks for your quick reply! maybe this here helps:)

#include <SoftwareSerial.h>

#define DEBUG true

/*
* make RX Arduino line is pin 2, make TX Arduino line is pin 3. This means that
* you need to connect the TX line from the esp to the Arduino's pin 2 and the RX
* line from the esp to the Arduino's pin 3.
*/
SoftwareSerial esp8266(2,3);


#pragma mark -
#pragma mark helper methods


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;
}


void setupWifi() {
   // reset module
   sendData("AT+RST\r\n",2000,DEBUG);
   
   // configure as access point
   sendData("AT+CWMODE=1\r\n",1000,DEBUG);
   
   // connect to the mushroom kingdom :)
   sendData("AT+CWJAP=\"MY_SSID\",\"PW!\"\r\n",10000,DEBUG);
   
   // get ip address
   sendData("AT+CIFSR\r\n",1000,DEBUG);
   
   // configure for multiple connections
   sendData("AT+CIPMUX=1\r\n",1000,DEBUG);
   
   // turn on server on port 80
   sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG);
}


void setup() {
   Serial.begin(9600);
   //esp8266.begin(115200); // your esp's baud rate might be different
   esp8266.begin(57600); // your esp's baud rate might be different
   
   pinMode(11,OUTPUT);
   digitalWrite(11,LOW);
   
   setupWifi();
}


void loop() {
   if(esp8266.available()) { // check if the esp is sending a message
       if(esp8266.find("+IPD,")) {
           Serial.println("IDP found!!!!");
           delay(1000);
   

           
           // subtract 48 because the read() function returns the ASCII decimal value and 0 (the first decimal number) starts at 48
           int connectionId = esp8266.read()-48;
           
           
// HERE SOMETHING WENT WRONG! the request String differs nearly every run
           String request = esp8266.readString();
           Serial.println(request);

           
           // make close command
           String closeCommand = "AT+CIPCLOSE=";
           closeCommand+=connectionId; // append connection id
           closeCommand+="\r\n";

           // close connection
           sendData(closeCommand,1000,DEBUG); 
       }
   }
}
   long int time = millis();

millis() returns an unsigned long.

Which Arduino do you have? You overuse of Strings is NOT helping.

       if(esp8266.find("+IPD,")) {
           Serial.println("IDP found!!!!");
           delay(1000);

Might I respectfully suggest that you get your thumb out of your ass? That delay() is completely pointless.

PaulS:
millis() returns an unsigned long.

Thanks - but am I right that this fail isn't related to my issue? But I will change it - of course!

PaulS:
Might I respectfully suggest that you get your thumb out of your ass? That delay() is completely pointless.

You might :slight_smile: I've seen it somewhere in the web and thought ... maybe it helps :-/

I'm using an Arduino Uno.

And what do you mean by "overuse of Strings"? For memory reasons? Or is there something else whats wrong with Strings?

Just some sentences about my background:
I'm a software developer who normally deals with objectivec, java or javascript - thus memory respecting programming is not my biggest skill;) Therefore I'm very interested in getting more information about this topic.

Cheers
Dennis

How are you powering the ESP8266 ?

You may find the examples in Serial Input Basics of interest. The concept applies to most forms of communication.

...R

Hi Robin2,

many thanks for that link! Very interesting and as soon as I get the basic stuff working I will change the code to your approach!

I've attached the current wiring, not the best quality but I hope you can get all the needed information from this "picture".

Cheers
Dennis

Missing File

AFAIK the Arduino 3.3v pin can only provide about 50 mA and the ESP8266 needs about 3 times that or more. I think there must be a risk of damage to your Arduino.

I powered my ESP8266 from the Arduino 5v pin via an LM317 voltage regulator. Someone else said it is sufficient to drop the 5v with a couple of diodes in series - but I have not tried that.

...R

The below seems to indicate that an ESP8266 can be powered to some extent from the arduino 3.3v pin.

http://forum.arduino.cc/index.php?topic=283043.msg2410822#msg2410822

Hi,

I've bought these little guys right here (http://www.amazon.de/gp/product/B00VWVA8GC?psc=1&redirect=true&ref_=oh_aui_detailpage_o01_s00) and will check if it helps in this afternoon.

I will inform you as soon as I have any new information :slight_smile:

Cheers
Dennis

Hi guys,

now I tried it with a LD33V power regulator, but I got the same result. I've attached the "new" wiring.

Any other ideas?

Cheers
Dennis

jakez:
I've attached the "new" wiring.

Did Not ! :slight_smile:

...R

This is - in my opinion - a bug in the forum software. If I try to upload an image bigger than 1MB I'm looked for 10minutes - but hey - here it is;)

One can say bug, one can say part of the spam filtering.

CrossRoads:
One can say bug, one can say part of the spam filtering.

:slight_smile:

Does anybody has another idea how to solve this problem? :frowning:

Cheers

jakez:
This is - in my opinion - a bug in the forum software. If I try to upload an image bigger than 1MB I'm looked for 10minutes - but hey - here it is;)

So why not reduce the size of your image? Remember I have to pay to download it.

...R

Is the code in Reply #2 is the latest version you are trying?

I notice that you are trying to use SoftwareSerial at 57600 baud. Try it at 9600 and then maybe move up to 19200. SoftwareSerial does not perform well.

...R

I'd similarly suggest slowing down the baud rate, and also, you should never use a linear regulator without it's associated caps - .1uF on the in and 10uf on the out in this case.

This is - in my opinion - a bug in the forum software. If I try to upload an image bigger than 1MB I'm looked for 10minutes - but hey - here it is;)

Learn to make pix of reasonable size. What is the measured voltage on the arduino and the ESP8266 chip using your wiring setup? How many ma is the ESP8266 pulling from the arduino?