Go Down

Topic: esp8266 with arduino (Read 431 times) previous topic - next topic

rohirto

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...


Code: [Select]

#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();
}


JoeSto

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

/Joe
If all you have is a hammer, everything looks like a nail!
------------------------------------
Arduino OS: see https://github.com/joe7575/Arduino-MOS

Whandall

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
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

rohirto

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

rohirto

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

Whandall

#5
Apr 24, 2016, 10:30 pm Last Edit: Apr 24, 2016, 10:32 pm by Whandall
So you will need an extra power supply (3.3V, >300mA) and some levelshift for the ESP-RX line.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy