esp8266 with arduino

Hello guys,

I have recently bought a ESP8266 WiFi module, and I’m trying to configure with my arduino board.
I providing 3.3V and GND from arduino itself, Also TX and RX pins are connected directly on digital pins 5 and 6 (SoftwareSerial). Whenever I’m trying to read the response from module (which I store in a String buffer), it shows some junk data. Here is my code. Also I have attached the responses I’ve received from module. Please help…

#include <SoftwareSerial.h>

void send_data(void);

SoftwareSerial mySerial(5,6); // RX, TX
String buff="";
String data = "4";
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
unsigned long lastConnectionTime = 0; 
void setup() 
{
  
  mySerial.begin(115200);
  while(!mySerial){
    //Wait
  }
  Serial.begin(9600);
  while(!Serial){
    //Wait
  }
  mySerial.println("AT");
  if(mySerial.available()){
    buff += mySerial.read();
  }
  if(buff="OK"){
    Serial.println("AT OK");
    //Serial.println(buff);
    buff="";
  }
  else{
    Serial.println("System failed");
    exit(0);
  }
  mySerial.println("AT+RST");
  delay(100);
  if(mySerial.available()){
    buff += mySerial.read();
  }
  Serial.println("AT+RST data rx is:");
  Serial.println(buff);
  buff="";
  mySerial.println("AT+CIPMUX=1");
  if(mySerial.available()){
    buff += mySerial.read();
  }
  if(buff="OK"){
    Serial.println("AT+CIPMUX=1    OK");
    //Serial.println(buff);
    buff="";
  }else{
    Serial.println("AT+CIPMUX = 1 Error!");
    exit(0);
  }
   delay(100);
    
}
  
  

void loop() { // run over and over
if (millis() - lastConnectionTime > postingInterval){
   send_data();
}





  
 
}

void send_data(){
  Serial.println("Opening TCP connection: rohirto.ddns.net,8080, CH4");
 mySerial.println("AT+CIPSTART=4,\"TCP\",\"rohirto.ddns.net\",8080");
     if(mySerial.available()){
     buff += mySerial.read();
     }
  Serial.println("AT+CIPSTART Data recieved is:");
  Serial.println(buff); 
  buff="";
   delay(100);
 mySerial.println("AT+CIPSEND=4,139");
      if(mySerial.available()){
      buff += mySerial.read();
      }
  Serial.println("AT+CIPSEND Data recieved is:");
  Serial.println(buff); 
  buff="";
   delay(100);
 http_post();
 if(mySerial.available()){
 buff += mySerial.read();
      }
  Serial.println("POST REQUEST Data recieved is:");
  Serial.println(buff); 
  buff="";
   delay(100);
  

lastConnectionTime = millis(); 
}

void http_post(){
  Serial.println("POST request");
    mySerial.println("POST /process_post HTTP/1.1");
    mySerial.println("Host: rohirto.ddns.net:8080");
    mySerial.println("Content-Type: application/x-www-form-urlencoded");
    mySerial.print("Content-Length: ");
    mySerial.println(data.length());
    mySerial.println("Connection: Keep-Alive");
    mySerial.println();
    mySerial.println(data);
    mySerial.println();
}

I am pretty sure it should be
[b]  if (buff == "OK")[/b]
and not

[b]  if (buff = "OK")[/b]

/Joe

rohirto:
I have recently bought a ESP8266 WiFi module, and I'm trying to configure with my arduino board.
I providing 3.3V and GND from arduino itself, Also TX and RX pins are connected directly on digital pins 5 and 6 (SoftwareSerial).

Which ESP8266 (there are many variants) and which Arduino (there are many variants) are you using?

For 5V Arduinos:

  • the ESP8266 RX line needs a level-shift (if you want to run the module inside the specs)
  • the 3.3V of an Arduino is incapable to supply enougth current to an ESP8266

@JoeSto I'm sorry, yeah it's buff==OK

@Whandall I'm using UNO, and ESP8266, ESP-1 I guess.

So you will need an extra power supply (3.3V, >300mA) and some levelshift for the ESP-RX line.