-->
Page 1 of 1

esp8266 e-01 + arduino uno help

PostPosted: Fri Aug 14, 2015 12:10 pm
by Omry Isa
hi guys

i'm really having a difficulty to connect the esp to arduino.

wiring going like this:
GND to GND
VCC to 3.3v on arduino uno
URXD to RX=pin0
UTXD to TX=pin 1
CH_PD to 3.3v

I did upload a blank skitch to the arduino, set "Both NL & CR" and the baud rate to 115200.
AT command returns ok
AT+GMR returns:

AT+GMR

AT version:0.25.0.0(Jun 5 2015 16:27:16)
SDK version:1.1.1
Ai-Thinker Technology Co. Ltd.
Jun 5 2015 23:07:20

OK

can someone help me how to set it up as server so i can turn on and off a pin on arduino.
i've seen alot of youtube vids and read alot of tutrials but still nothing work out.

i did connect the esp module to my router ssid and i get ping replys from it.

can someone help please?
thanx

Re: esp8266 e-01 + arduino uno help

PostPosted: Fri Aug 14, 2015 2:15 pm
by martinayotte
Doing a server using AT commands is over complexifying things if your adruino doesn't do much other stuff than controlling a LED pin.
Maybe you should use a stand-alone ESP with ArduinoIDE WebServer sketch, it will be much more efficient.

Re: esp8266 e-01 + arduino uno help

PostPosted: Tue Aug 18, 2015 1:54 pm
by WStan
I do not remember where I found this code unfortunately .
I 've changed reading of DHT to constant values just for testing purpose.
Code: Select all
#include <SoftwareSerial.h>
 
#define DEBUG true

//#include <DHT.h>
//DHT dht(3, DHT11);
String  str1 ="";
SoftwareSerial espSerial(2,3); // UNO 2-RX. 3 TX

void setup()
{
  Serial.begin(9600);
  espSerial.begin(115200); // your esp's baud rate might be different

 // pinMode(3, INPUT);     // DHT11
 // dht.begin();
 
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure standard node

  sendData("AT+CWJAP=\"@HomeCA72\",\"\"\r\n",5000,DEBUG);
//  sendData("AT+CIPSTA=192.168.24.108\r\n",5000,DEBUG);
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
  digitalWrite(13, HIGH);
}
 
void loop()
{

//  sendData("AT+CIPSTATUS\r\n",1000, DEBUG);
//  sendData("AT+CIPCLOSE=0\r\n",1000, DEBUG);
//  sendData("AT+CIPCLOSE=1\r\n",1000, DEBUG);
 
  if(espSerial.available()) // check if the esp is sending a message
  {
   
    if(espSerial.find("+IPD,"))
    {
     delay(1000);
  Serial.println("------------------------------------------------------------------------------------connectionId= ");
     int connectionId = espSerial.read()-48; // subtract 48 because the read() function returns
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48
     
     Serial.print("connectionId= "); Serial.println(connectionId);

     
     float h = 22.2;//Humidity();
     float t = 21.0;//Temperature();

     String webpage = "<html><head><title>ESP8266 web server</title></head><body><h1>Hello world!</h1>";
     webpage += "<br>Temperature: ";
     webpage += t;
     webpage += "<br>Humidity: ";
     webpage += h;
     webpage += "</body></html>\r\n";
 
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,3000,DEBUG);
     
     delay(2000);
     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";
     
     sendData(closeCommand,1000,DEBUG);
     delay(1000);   
 
    }
  }
//  sendData("AT+CIPSTATUS\r\n",1000, DEBUG);

  delay(2000); //wsp
}
 
 
void sendData(String command, const int timeout, boolean debug)
{
   
    espSerial.print(command); // send the read character to the esp8266
   
    long int time = millis();
   
    while( (millis() - time) < timeout)
    {
      while(espSerial.available())
      {
        char c = espSerial.read(); // read the next character.
        Serial.print(c);
      } 
    }
}