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.
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.
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);
}
}
}
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 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.
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.
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.
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.
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?