Yesterday I started working with the ESP8266-01 module, hooked up to my Arduino Nano. I used a 3.3V step down power converter, connected to 5V pin. I connected the ESP module to RX/TX a communicated through Serial monitor in Arduino IDE. Everything went fine. I found my wifi and connected.
Then I tried using the Software Serial to communicate to the module directly from the Arduino. I only had to deal with AT+CIPSTART, as the module was automatically connecting to my wifi. Sending data to my website worked fine. But I thought this was not good, I wanted it to connect to the wifi everytime it turns on. So I included a function to connect to the wifi and before that, I called AT+RST.... And that was the time it got stuck. It was not able to connect and did not respond to any commands. So I uploaded bare minimum to my Arduino and tried to talk to the board over Serial monitor (BTW I changed ESP's baud rate to 9600) but I got no response. When I power it up, the blue LED on ESP is on all the time as well as the TX LED on my Arduino...
This is the code:
#include <SoftwareSerial.h>
#include <dht.h>
dht DHT;
#define DHT22_PIN 7
const byte rxPin = 2; // Wire this to Tx Pin of ESP8266
const byte txPin = 3; // Wire this to Rx Pin of ESP8266
int chk;
String hum,tem;
String ssid ="XXX";
String password="XXX";
String data;
String server = "XXX"; // www.example.com
String uri = "XXX";// our example is /esppost.php
void setup() {
Serial.begin(115200);
ESP8266.begin(9600); // Change this to the baudrate used by ESP8266
delay(1000); // Let the module self-initialize
reset();
delay(1000);
connectWifi();
}
void loop() {
chk = DHT.read22(DHT22_PIN);
delay(100);
hum = String(DHT.humidity);
tem = String(DHT.temperature);
data = String("temp="+tem+"&hum="+hum);
Serial.println("Commencing httpost...");
httppost();
delay(600000);
}
void reset() {
ESP8266.println("AT+RST");
delay(1000);
if(ESP8266.find("OK") ) Serial.println("Module Reset");
}
void connectWifi() {
cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
Serial.println(cmd);
ESP8266.println(cmd);
delay(4000);
if(ESP8266.find("OK")) {
Serial.println("Connected!");
}
else {
connectWifi();
Serial.println("Cannot connect to wifi");
}
}
void httppost () {
ESP8266.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
if( ESP8266.find("OK")) {
Serial.println("TCP connection ready");
}
delay(1000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
ESP8266.print(sendCmd);
ESP8266.println(postRequest.length() );
delay(500);
if(ESP8266.find(">")) { Serial.println("Sending.."); ESP8266.print(postRequest);
if( ESP8266.find("SEND OK")) { Serial.println("Packet sent");
while (ESP8266.available()) {
String tmpResp = ESP8266.readString();
Serial.println(tmpResp);
}
ESP8266.println("AT+CIPCLOSE");
}
}
}I read something about the ESP not being able to boot properly after reset, so I opened minicom and used anybaud to change baud rate to 74880. This is what I get when I power the ESP:
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 1396, room 16
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4
tail 8
chksum 0xc0
csum 0xc0
2nd boot version : 1.4(b1)
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000
do�13˳L�Q
!��
�DK � Please, do you know what might be causing my problems?