I am running the code below, in my Arduino Pro Mini, but I keep getting the following results, my SSID is CREATEC with no password:
AT+CWJAP="CREATEC",""
b
Not connected to WiFi.
AT+CWJAP="CREATEC",""
ÿ
Not connected to WiFi.
AT+CWJAP="CREATEC",""
b
Not connected to WiFi.
AT+CWJAP="CREATEC",""
b
Not connected to WiFi.
AT+CWJAP="CREATEC",""
ÿ
Not connected to WiFi.
Halted... wifi not connected
the code is the following, as you can see, this code was originally using Serial1 (I guess a hardware RXI/TXO perhaps from Arduino UNO) and instead I replaced each of the lines to use two digital pins according to SoftwareSerial ss(3, 2), the code is supposed to send text messages to my cell phone by using pushingbox.com api;
#include <SoftwareSerial.h>
#define SSID "CREATEC" //name of wireless access point to connect to
#define PASS "" //wifi password
#define DST_IP "213.186.33.19" // IP of api.pushingbox.com maybe it changes, so take DST_HOST
#define DST_HOST "api.pushingbox.com"
#define LED 13
String sMessage_1 = "vxyxyxaxjasdasdas";
String sMessage_2 = "vsfdkjfkjsdhfkdsjfh";
String sMessage_3 = "sdkfhshfkdshfksdas";
SoftwareSerial ss(3, 2);
void setup() //initialise device & connect to access point in setup
{
pinMode(LED,OUTPUT);
reset();
//Serial1.begin(115200); // hardware serial connects to esp8266 module
ss.begin(9600);
Serial.begin(9600); // usb serial connects to to pc
delay(4000); //wait for usb serial enumeration on 'Serial' & device startup
boolean wifi_connected=false; //not connected yet...
for(int i=0;i<5;i++) //attempt 5 times to connect to wifi - this is a good idea
{
if(connectWiFi()) //are we connected?
{
wifi_connected = true; //yes
break; //get outta here!
}
}
if (!wifi_connected) hang("wifi not connected"); //these seem ok - never had a problem
delay(250);
if(!cipmux0()) hang("cipmux0 failed");
delay(250);
if(!cipmode0()) hang("cipmode0 failed");
delay(250);
}
void loop()
{
// !!!! ONLY TESTING OF METHOD TO PUSH THE MESSAGES TO MY PHONE :-)
sendToPushingBox(sMessage_1);
delay(1000);
sendToPushingBox(sMessage_2);
delay(1000);
sendToPushingBox(sMessage_3);
delay(1000);
while(1);
}
//------------------------------------------------------------------------------------
void sendToPushingBox(String devid)
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_HOST;
cmd += "\",80";
//Serial1.println(cmd); //send command to device
ss.println(cmd); //send command to device
delay(2000); //wait a little while for 'Linked' response - this makes a difference
cmd = "GET /pushingbox?devid=";
cmd += devid;
cmd += " HTTP/1.1\r\n"; //construct http GET request
cmd += "Host: api.pushingbox.com\r\n\r\n";
//Serial1.print("AT+CIPSEND=");
ss.print("AT+CIPSEND=");
//Serial1.println(cmd.length()); //esp8266 needs to know message length of incoming message - .length provides this
ss.println(cmd.length());
//if(Serial1.find(">")) //prompt offered by esp8266
if(ss.find(">"))
{
//Serial1.println(cmd); //this is our http GET request
ss.println(cmd);
}
else
{
//Serial1.println("AT+CIPCLOSE"); //doesn't seem to work here?
ss.println("AT+CIPCLOSE");
//Serial.println("No '>' prompt received after AT+CPISEND");
ss.println("AT+CIPCLOSE");
}
//Serial1.println("AT+CIPCLOSE");
ss.println("AT+CIPCLOSE");
}
boolean connectWiFi()
{
String cmd="AT+CWJAP=\""; //form eg: AT+CWJAP="dynamode","55555555555555555555555555"
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
//Serial1.println(cmd);
Serial.println(cmd);
ss.println(cmd);
delay(5000); //give it time - my access point can be very slow sometimes
Serial.println(char(ss.read()));
//if(Serial1.find("OK")) //healthy response
if(ss.find("OK"))
{
Serial.println("Connected to WiFi...");
return true;
}
else
{
Serial.println("Not connected to WiFi.");
return false;
}
}
//--------------------------------------------------------------------------------
//ditch this in favour of hardware reset. Done
boolean softwarereset()
{
//Serial1.println("AT+RST");
ss.println("AT+RST");
//if (Serial1.find("ready"))
if (ss.find("ready"))
{
return true;
}
else
{
return false;
}
}
//--------------------------------------------------------------------------------
void reset()
{
//Serial1.println("AT+RST");
ss.println("AT+RST");
digitalWrite(LED,HIGH);
delay(100);
digitalWrite(LED,LOW);
}
//------------------------------------------------------------------------------
boolean cwmode3()
// Odd one. CWMODE=3 means configure the device as access point & station. This function can't fail?
{
//Serial1.println("AT+CWMODE=3");
ss.println("AT+CWMODE=3");
//if (Serial1.find("no change")) //only works if CWMODE was 3 previously
if (ss.find("no change"))
{
return true;
}
else
{
return false;
}
}
//----------------------------------------------------------------------------------
boolean cipmux0()
{
//Serial1.println("AT+CIPMUX=0");
ss.println("AT+CIPMUX=0");
//if (Serial1.find("OK"))
if (ss.find("OK"))
{
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------
boolean cipmode0()
{
//Serial1.println("AT+CIPMODE=0");
ss.println("AT+CIPMODE=0");
//if (Serial1.find("OK"))
if (ss.find("OK"))
{
return true;
}
else
{
return false;
}
}
//------------------------------------------------------------------------
void hang(String error_String) //for debugging
{
Serial.print("Halted... ");
Serial.println(error_String);
while(1)
{
digitalWrite(LED,HIGH);
delay(100);
digitalWrite(LED,LOW);
delay(100);
}
}
//----------------------------------------------------------------------------
void hangreset (String error_String) //for debugging
{
Serial.print(error_String);
Serial.println(" - resetting");
reset();
}
The esp starts at 115200 while booting then switches to 9600 after it boot's
You'll see a bunch of gunk till it boot's.
And one more thing esp2866 does not come with AT commands you have to flash it with firmware that has AT commands or you have a really old one that had AT commands but the newer ones don't.
And one more thing esp2866 does not come with AT commands you have to flash it with firmware that has AT commands or you have a really old one that had AT commands but the newer ones don't.
Wait, dont scare me, because according to sparkfun, my supplier, in this link WiFi Module - ESP8266 (4MB Flash) - WRL-17146 - SparkFun Electronics "Each ESP8266 module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino device and get about as much WiFi-ability as a WiFi Shield offers (and that’s just out of the box)!"
To johnwasser, here my comments:
Did you configure the ESP8266 baud rate from 115200 to 9600?
I did not do any configuration all I am doing is trying that code I got from and older Arduino Forum post which explained that it did work as it was originally using the Serial1 instead of what I need that is to use SoftwareSerial ss(3, 2); which is not working.
enrique_acuna:
I did not do any configuration; all I am doing is trying that code I got from and older Arduino Forum post which explained that it did work as it was originally using the Serial1 instead of what I need. That is to use SoftwareSerial ss(3, 2); which is not working.
When you switched from Serial1 to SoftwareSerial you also switched from 115200 to 9600 baud. If the sketch worked before (at 115200) I would not expect it to work at 9600. I don't think SoftwareSerial works at 115200 so you will need to use AT commands (at 115200 on Serial) to tell the ESP8266 to switch to 9600 and store that for future use.
Where did you send AT+CIOBAUD?115200
Your esp8266 is not set to send at 115200 and none of them I no of do send at that speed without setting it to do so. Try sending and receiving your code at 9600 and see how that goes.
I went to the basics and wrote the short code below to test ONLY the reset function AT+RST at 115200 using only the hardware serial pins RXI and TXO of my Arduino Pro Mini, which I connect to the ESP8266 after I have uploaded the code to the Arduino. And I was able to see three resets happening in about 100 times that I left run, so this means that the ESP did come flashed correctly from factory and I dont have to flash it (this a brand new ESP chip I just purchased a few days ago from sparfun). So I have several questions:
Do you think I need some extra power supply other than my computer USB?
How much current should I supply to the ESP chip?
I must use SoftwareSerial to program two digital pins in my Arduino Pro Mini, what is the highest speed this can handle? If it is less than 115200, what should I do? I cannot find the command usage of of AT+CIOBAUD in the ESP documents.
#include <SoftwareSerial.h>
#define LED 13
void setup() //initialise device & connect to access point in setup
{
//Enable the Onboard LED to act as a Status indicator light
pinMode(LED,OUTPUT);
Serial.begin(115200); // usb serial connects to to pc
//Send a series of flashes to show us we are in the bootup phase.
blinkcode ();
}
void loop()
{
//Reset the ESP8266
if(softwarereset())
{
Serial.println("ESP is reset");
return;
}
else
{
Serial.println("ESP cannot be reset");
}
//Wait for the WiFi module to bootup
delay(1000);
}
//--------------------------------------------------------------------------------
//ditch this in favour of hardware reset. Done
boolean softwarereset()
{
//Serial1.println("AT+RST");
Serial.println("AT+RST");
//Serial.println(char(Serial.read()));
delay(800);
//Serial.println(char(Serial.read()));
if (Serial.find("OK"))
{
return true;
}
else
{
return false;
}
}
//----------------------------------------------------------------------------
void blinkcode ()
{
//Simply loop a few times flashing the status light (this is used during boot up)
int i;
for (i = 1; i <= 10; i++)
{
delay (100);
digitalWrite(LED,HIGH);
delay (100);
digitalWrite(LED,LOW);
}
}
I don't think your understanding what happens here you have to send the AT command to change baud rate.
and all esp8266 come flashed with some kind of firmware.
USB from where the the esp uses from 200 to 250 mA some say it's not a good idea to use the 3.3 volts from a uno.
What you need to do is hook it up to the arduino with a diode on the RX pin of the esp to the TX pin of the arduino the TX pin of the esp to the arduino RX pin, Can be a wire make sure you put diode the right way. Tie the grounds and power the esp at 3.3 volts and the power your arduino open the serial monitor and make sure it's set at 9600 and post what it shows .
Look at the pic I attached
Here a copy AT commands
LOL no wonder your having problems I looked at the sparkfun site and there esp8266 LOL the stuff they have posted is almost 2 years old these esp 8266 change almost daily.
And I would bet you a dollar you have a way newer chip on yours then the link you been looking at.
thanks for the replies. I am finding that the problem is that SoftwareSerial cannot support high baud rates, since I just found out that my WiFi ESP8266 module runs at 115200, and there is a new SoftwareSerial version that supports this speed so that we can use digital pins instead of RXI and TXO, you can see this in the link GitHub - plerup/espsoftwareserial: Implementation of the Arduino software serial for ESP8266, however now my problem is that I cannot load this library correctly to the IDE environment, it gives me a compilation error:
C:\Users\Enrique\Documents\Arduino\libraries\espsoftwareserial-master\SoftwareSerial.cpp:27:18: fatal error: gpio.h: No such file or directory #include "gpio.h"
^
compilation terminated.
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\Enrique\Documents\Arduino\libraries\espsoftwareserial-master
Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial
Error compiling.
I cannot change the baud rate to a slower one, since for that I should have the ESP module communicating and it is not. I also found out that the AT command AT+CIOBAUD is no longer used and that AT+UART and AT+IPR have replaced it, as explained in AT+UART / AT+IPR breaks firmware? - Everything ESP8266. I dont want to use extra hardware nor reflash the ESP, since it seems to be working well accordiing to espsoftwareserial above. And also although you can get AT+UART=9600,1,0,3 and AT+IPR=9600 and received 'OK' responses, then the person that did this can no longer communicate with the module, eventhough he tried all standard bauds and on power cycle just get gibberish.
Good luck hope you get it working.
The 115200 is to flash it the link you posted tells you that they bricked there esp using the wrong AT commands the AT command pdf I posted is from the people who wrote the SDK that's used to make the firmware.
There using v0.9.2.2 AT Firmware.bin It's It's 0.9.6 now the only way to see is like I posted in post
7 find out for sure what you have. These things change daily and see how cheap they are the information you get on the net is even cheaper.
Hello be80be, thanks a lot for your replies. I owe you an apology I found out why I cannot upload the library, I got a separate reply from Peter Lerup, the writer of the espsoftwareserial, he explained this library is only for the ESP8266 itself when using the ESP8266-Arduino setup: GitHub - esp8266/Arduino: ESP8266 core for Arduino, and that Ishould use the standard library. But this was not clear in the post.
But I have some better news, I found in the link ESP8266 Arduino Code and 3.3V Schematic to Send and Receive Data the following code, and now I can see my ESP8266 communicating through SoftwareSerial for first time, unfortunatelly I am getting garbage characters with all baud rates, but it is at least talking with the Arduino Soft pins RX/TX for first time. I am guessing I need to provide more current to the ESP. The code is the following,
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); // 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
void setup()
{
Serial.begin(57600);
esp8266.begin(57600); // your esp's baud rate might be different
}
void loop()
{
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
}
}
if(Serial.available())
{
// the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
// In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
// but we want to send everything at the same time.
delay(1000);
String command="";
while(Serial.available()) // read the command character by character
{
// read one character
command+=(char)Serial.read();
}
esp8266.println(command); // send the read character to the esp8266
}
}
From everything I know about these chips it's a pain in the butt LOL the arduino libarays there are two one works fine with the arduino ide one does cause they name files with same names. As the ide.
But I'm telling you the frist thing you need to do is get a USB to 3.3 serial converter and find what baud it's using most boot at 115200 and then send data 9600 that's the default from espressif http://bbs.espressif.com/viewforum.php?f=46
After all they are the people who made the SDK. That's code you have in the chip is compiled with.
Now you go back a year and have firmware that had the MIT AT commands some chips run slower but still they have fixed bauds of 115200 or 76800 I think it's 76800 but this is for flashing.
That's why you see people saying I flashed my chip and it don't work now.
Your best bet is to use the usb to serial converter or the arduino as one it works to. I use the LUA loader to
find this cause it's a great tool that can print the stuff as it boots Putty works the serial monitor works
just use a diode on the RX pin if you use the arduino the resistor dividers don't work to well at high speed.
If you look they are using a diode on there RX it' shown left center of pic.
The thing here is you have to find what baud it's talking at then set it to what you want to use these things are able to use serail way faster then 115200 and as low as 300 it like 300 to 921,600 some even faster.
But that's used for fashing and evey one I've used talked a 9600 for sending commands I then changed to to what i what to use.
hello be80be,
again thanks for your valuable advice. I dediced to dedicate several hours to studying all documenation from Expressif. And after many hours of trials I was able to flash successfully one of the two ESP modules, I will send or share all full detailed proecess later. I was able to finally see my ESP talking with the serial monitor, directly through my USB to FTDI breakout, using an external power supply. All this at 112500. So this is where I am now, I am doing all the process step by step, so next is to change the baud rate to 9600. For this I found the new command for this: AT+UART_DEF. But again, I still have to do that next. I will keep you posted and everybody else up to date.
Flashing can be a bit hair raising as the firmware is spilt into parts and based on the esp you have there loaded different. They have different ram chips unlike the atemga with it made in the chip.
Ok, now the ESP is communicating and working well, can you believe that? Since I am so behind with the overall project I will not write or share the full details on what I did (flashing, etc), yet, but I can tell you briefly that I did the following:
Programmed the ESP with latest four bin files from Expressif.
Powered the ESP with a separate Regulated DC Power Supply at 3.4 V and 650 mA (max). The ESP is requiring 110 - 120 mA while operating as TPC client.
Used AT+UART_CUR = 9600,8,1,0,0 (this means no flow control, if this is set to 3 with full flow control it does not work)
I found that this last command DOES save to flash the new speed, contrary to what the Expressif manual says.
Now I can get my Arduino Pro Mini talking at 9600 through digital pins 3 and 2. It took about 7 full working days.