Arduino Leonardo and duinotech Wifi Shield

ok im kind of confused of editing this example code from wifiesp:

/*
 WiFiEsp example: WebServerAP

 A simple web server that shows the value of the analog input 
 pins via a web page using an ESP8266 module.
 This sketch will start an access point and print the IP address of your
 ESP8266 module to the Serial monitor. From there, you can open
 that address in a web browser to display the web page.
 The web page will be automatically refreshed each 20 seconds.

 For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

char ssid[] = "TwimEsp";         // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
int reqCount = 0;                // number of requests received

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(9600);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true); // don't continue
  }

  Serial.print("Attempting to start AP ");
  Serial.println(ssid);

  // uncomment these two lines if you want to set the IP address of the AP
  //IPAddress localIp(192, 168, 111, 111);
  //WiFi.configAP(localIp);
  
  // start access point
  status = WiFi.beginAP(ssid, 10, pass, ENC_TYPE_WPA2_PSK);

  Serial.println("Access point started");
  printWifiStatus();
  
  // start the web server on port 80
  server.begin();
  Serial.println("Server started");
}


void loop()
{
  WiFiEspClient client = server.available();  // listen for incoming clients

  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer

        // you got two newline characters in a row
        // that's the end of the HTTP request, so send a response
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }
      }
    }
    
    // give the web browser time to receive the data
    delay(10);

    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}

void sendHttpResponse(WiFiEspClient client)
{
  client.print(
    "HTTP/1.1 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Connection: close\r\n"  // the connection will be closed after completion of the response
    "Refresh: 20\r\n"        // refresh the page automatically every 20 sec
    "\r\n");
  client.print("<!DOCTYPE HTML>\r\n");
  client.print("<html>\r\n");
  client.print("<h1>Hello World!</h1>\r\n");
  client.print("Requests received: ");
  client.print(++reqCount);
  client.print("
\r\n");
  client.print("Analog input A0: ");
  client.print(analogRead(0));
  client.print("
\r\n");
  client.print("</html>\r\n");
}

void printWifiStatus()
{
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, connect to ");
  Serial.print(ssid);
  Serial.print(" and open a browser to http://");
  Serial.println(ip);
  Serial.println();
}

because i have no idea where to put the edited string of code in this do i just remove this:

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

or should i leave it because this is driving me nuts and i know these things are for learning, no problem. I just get stuck because i kind of find these things hard to use but its interesting and i got the ethernet shield to work, no problem... but tyhe wifi shield seems to be the hardest out of them all anyway please help.

i did some toying around with the wifiesp code and i got this:

[WiFiEsp] Initializing ESP moduleEOUT >>>
[WiFiEsp] Initializing ESP module
AT
[WiFiEsp] Initializing ESP module
AT
AT
AT+RST
ATE0
AT+CWMODE=1
AT+CIPMUX=1
AT+CIPDINFO=1
AT+CWAUTOCONN=0
AT+CWDHCP=1,1
AT+GMR
[WiFiEsp] Initilization successful - 1.3.0
AT+CIPSTATUS
WiFi shield not present

kind of strange...

@OfficialEnlightGames you should really take the time to understand what every line of the sketch does.

#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

This checks if the board you're using has a second hardware serial interface available (Serial1). If not it assumes you are going to be using software serial on pins 6 and 7 and names the SoftwareSerial object Serial1 (not to be confused with the hardware serial object of that same name). If a second hardware serial interface is available on the board you're using then it will be used. Since the Uno doesn't have a second hardware serial interface that code will cause the sketch to use software serial. If you have the shield plugged into your Uno then it's connected to Serial, not pin 6 and 7 so this will not work. In that case you need to delete the lines of code shown above, as you guessed, but you also need to make another change.

 WiFi.init(&Serial1);    // initialize ESP module

That line passes the serial object to the WiFiEsp library so it can use it to communicate with the ESP8266. Since the ESP8266 is connected to Serial on your Uno, not Serial1 that is wrong. You need to change it to:

 WiFi.init(&Serial);    // initialize ESP module

As I said in my previous reply, you also need to edit the library source code to turn off debug output as this is also sent to Serial and will interfere with communication with the ESP8266. Follow these steps:

  • File > Examples > WiFiESP > ConnectWPA
  • Sketch > Show Sketch Folder - this will open the folder {sketchbook}/libraries/WiFiEsp/examples/ConnectWPA
  • Navigate to {sketchbook}/libraries/WiFiEsp/src/utility
  • Open debug.h in a text editor
  • Change line 31 from:
#define _ESPLOGLEVEL_ 3

to

#define _ESPLOGLEVEL_ 0
  • Save the file

Keep in mind that you can have debug output turned on in the WiFiEsp library when you're using it with your Leonardo so you may want to revert this change if you need to do troubleshooting in that configuration but otherwise I recommend always having debug output turned off as it uses a lot of memory and slows down your Arduino.

pert:
It says you use the AT+IPR command to change the baud rate. This is disturbing to me because recent versions of Espressif AT firmware use "AT+UART_CUR" or "AT+UART_DEF" for this, which indicates there are significant differences between the AI-Thinker firmware and the Espressif firmware.

Since you're using SoftwareSerial I don't think that is necessary.

Thanks for your detailed reply.

Using the unstacked arrangement, I tried in setup() with SoftwareSerial to slow down the speed talking to the "AI" firmware ESP8266 from an Arduino by initially connecting at 115200 in setup and then using AT+IPR=9600. Followed by a Serial1.begin(9600). No dice from some time of mucking about and adding delays and such.

I saw that the Espressif "AT+UART_DEF" effect a change save to flash and thought that would be a reasonable approach. Specifically: "AT+UART_DEF=9600,8,1,0,0".

I downloaded the Espressif user1.bin from github and flashed the board with an FTDI beast using details from this forum post:

https://forum.arduino.cc/index.php?topic=420550.0

In particular, a document "XC4614 flash reprogramming.docx" that was pretty helpful.

There was one obscure step in this description and I relflashed the Espressif user1.bin at address 0x00000000. I was amazed and relieved to see that this worked to the point of blinken-lights across to the ESP-13 board.

Alas, it no longer responds to AT commands. Mmm...

So I am guessing that there is a flash layout that I failed to follow. Another source shows a layout like:

Bin Address boot_v1.1.bin---------------->0x00000 user1.bin-------------------->0x01000 ---> you can use the newest version or a specific version. esp_init_data_default.bin---->0x7C000 blank.bin-------------------->0x7E000

(Jeeze, how do I insert code tags? Mmm...).

So now I've typed this all in, I have convinced myself that I've stuffed up. I'll post it anyway in case it helps some other poor lost soul. :slight_smile:

I'm sorry to hear that.

I've just updated the following instructions to use the latest Espressif "AT" firmware version 1.6.0.0, from "NONOS" SDK V2.2.0. I've also verified the same process works with "AT" firmware 1.3.0, from "NONOS" SDK V2.0.0 and "AT" firmware 1.1.0 from with NONOS V1.5.4, though you may need to make some small adjustments in the filenames with the older versions.

I feel that it's best to use the Espressif "AT" firmware. This is updated frequently and well documented. Espressif is the manufacturer of the ESP8266. The only benefit I'm aware of for using the AI-Thinker firmware is if you want to control the ESP8266 GPIO pins via AT commands. I am under the impression that is possible with the AI-Thinker firmware, though I'm not certain of this and I haven't found good documentation for their firmware.

You can find documentation for the Espressif "AT" firmware on this page:

https://www.espressif.com/en/support/documents/technical-documents?keys=&field_download_document_type_tid[]=512

The "ESP8266 AT Instruction Set" document also contains some information on how to flash the "AT" firmware to your ESP8266.

The "AT" firmware is bundled with the "NONOS" SDK. You can find the latest version at:

http://espressif.com/en/support/download/sdks-demos

The "Flash Download Tool" is the application used to flash the ESP8266 with firmware. You can download the latest version at:

http://espressif.com/en/support/download/other-tools

You will need some sort of USB-TTL serial adapter, such as an FTDI FT232 breakout board. It is possible to use an Arduino for this purpose but it's easiest to use an adapter specifically designed for this. They can be purchased very cheaply on Aliexpress or eBay. Ideally you would use one that can provide 3.3 V signals but there is an official statement claiming the ESP8266 is 5 V logic level tolerant so you can probably get away with 5 V signals if that's all you have available.

You will need some jumper cables to make the various connections.

Here are instructions for flashing the "DOIT"/"duinotech" shield with the latest Espressif "AT" firmware version available at this time. In time new versions of the "NONOS" SDK/"AT" firmware or "Flash Download Tool" may become available so anyone reading this after some time has passed should check the links above to see if the links below point to the latest versions and if not then adjust the instructions below accordingly:

  1. Connect the shield to your Arduino.
    Only the power and ground pins must be connected, this will ensure that your shield gets a reliable 5 V power supply.
    It is possible to power the shield directly from the USB-TTL serial adapter but this has not proven to be reliable for me.

  2. Turn the two switches on the blue box to the "OFF" position.

  3. If your USB-serial adapter has the option to change to 3.3 V then do so.

  4. Use jumper cables to make the following connections:

    USB adapter Shield
    RX TX0
    TX RX0
    GND any pin marked "G"
  5. Connect pin "D0" on the shield to any of the pins on the shield marked G.

  6. Power the Arduino by plugging the USB cable into your computer or a power supply.

  7. Note which COM ports are installed on your computer.
    You can see the list in either of these two places:

    • Arduino IDE: in the Tools > Ports menu.
    • Windows Device Manager: under the Ports(COM & LPT) section of the device tree.
  8. Plug in the USB cable of your USB to serial adapter

  9. Wait for the USB to serial adapter to finish installing.
    Install drivers if necessary.

  10. Check the list of ports in either of the places mentioned in step (7).
    The new port that appeared is the COM port of the USB serial adapter.

  11. Download "NONOS" SDK V2.2.0: https://github.com/espressif/ESP8266_NONOS_SDK/archive/v2.2.0.zip

  12. Unzip the downloaded file.

  13. Download Flash Download Tools V3.4.4: https://www.espressif.com/sites/default/files/tools/flash_download_tools_v3.6.4_0.rar.

  14. Un-rar the downloaded file.

  15. Open the un-rared folder.

  16. Run the program ESPFlashDownloadTool_v3.6.4.exe

  17. Click the ESP8266 Download Tool button.

  18. Click the SPIDownload tab.

  19. Under the tool's tab bar there is a section of the window which provides columns of input fields where you can enter the paths and addresses of files to be flashed:

    • Click the first 6 checkboxes on the left side.
    • Click the ... button on the first line of the "Download Path Config" section and select the file ESP8266_NONOS_SDK\bin\blank.bin
    • In the box next to "ADDR" on that line enter 0x3FB000
    • Click the ... button on the second line of the "Download Path Config"g section and select the file ESP8266_NONOS_SDK\bin\esp_init_data_default_v08.bin
    • In the box next to "ADDR" on that line enter 0x3fc000
    • Click the ... button on the third line of the "Download Path Config" section and select the file ESP8266_NONOS_SDK\bin\blank.bin
    • In the box next to "ADDR" on that line enter 0x7e000
    • Click the ... button on the fourth line of the "Download Path Config" section and select the file ESP8266_NONOS_SDK\bin\blank.bin
    • In the box next to "ADDR" on that line enter 0x3fe000
    • Click the ... button on the fifth line and select the file from the unzipped folder from the downloaded "NONOS" SDK file: ESP8266_NONOS_SDK\bin\boot_v1.7.bin
    • In the box next to "ADDR" on that line enter 0x00000
    • Click the ... button on the sixth line of the "Download Path Config" section and select the file ESP8266_NONOS_SDK\bin\at\512+512\user1.1024.new.2.bin
    • In the box next to "ADDR" on that line enter 0x01000
    • In the "SpiFlashConfig" section, check the "SpiAutoSet" checkbox.
      Because you did this, you don't need to worry about any of the other settings in the "SpiFlashConfig" section because they will now be automatically detected before the flash process starts.
    • In the "Download Panel 1" section, select the USB serial adapter's COM port from the "COM PORT" menu.
  20. Click the **START button.
    You should see the progress of the flashing in the bar at the bottom of the tool window.

  21. Wait until the "Download Panel 1" shows a green box that says "FINISH".

  22. Close "ESP FLASH DOWNLOAD TOOL"

  23. Unplug the Arduino's USB cable.

  24. Unplug the jumper from the "D0" to the "G" pin.

  25. Plug in the Arduino's USB cable.

  26. Start the Arduino IDE.

  27. Select the COM port of the USB-serial adapter from the Tools > Port menu in the Arduino IDE.

  28. Select Tools > Serial Monitor from the Arduino IDE menus.

  29. Select "115200" from the baud rate menu at the bottom right corner of the Serial Monitor window.

  30. Select "Both NL & CR" from the menu next to the baud rate menu at the bottom right corner of the Serial Monitor window.

  31. Click on the text input box at the top of the Serial Monitor window.

  32. Type AT+GMR

  33. Press Enter.

You should now see a listing of the "AT" firmware version, SDK version, and compile time shown in the Serial Monitor. This indicates that the firmware update process was successful. If so you will be able to use your shield as usual.

The above instructions are specific to the DOIT shield, though they could be easily modified to work for flashing the AT firmware to any ESP8266 module.

Here are some general explanations of how I determined the correct file names and addresses to configure the "ESP8266 Download Tool" with:

Because the ESP8266 requires a external flash memory there are a number of different ESP8266 modules available that will require different configurations due to using different flash chips. It is very difficult to find specifications for most of these modules and modules of the same name may actually use different flash chips, ESP-01 for example. Luckily the "ESP8266 Download Tool" can automatically detect the flash configuration of common ESP8266 modules via the following procedure

  1. Connect the RX, TX, GND lines of the USB-serial adapter to the ESP8266.
  2. Ground GPIO0.
  3. Power the ESP8266.
  4. Plug in the USB-serial chip to your computer.
  5. Select the correct COM port in the "Flash Download Tool".
  6. In the "SpiFlashConfig" section, check the "SpiAutoSet" checkbox
  7. In the Download Path Config section, make sure all checkboxes on the left side are unchecked
  8. Click the START button.
  9. After a little while you should see text appear in the "DETECTED INFO" box.
  10. Note the selection in the "FLASH SIZE" radio button menu of the "SpiFlashConfig" section of the "Flash Download Tool" GUI.
  11. Download and open the "ESP8266 AT Instruction Set" PDF from this page:
    Technical Documents | Espressif Systems
  12. In section 1.2 ("Downloading AT firmware into Flash") of that document you will see a table of the files and addresses to use for the "FLASH SIZE" configuration that was automatically detected by the tool. Configure the "Flash Download Tool" according to that table, using the files found in the NONOS SDK you downloaded from http://espressif.com/en/support/download/sdks-demos.
    When you get to esp_init_data_default.bin you will have an unpleasant surprise. There is no file named esp_init_data_default.bin included with the NONOS SDK. Instead you will find multiple similarly named files (e.g. esp_init_data_default_v05.bin, esp_init_data_default_v08.bin). I would tend to use the one with the newest version but I really don't know which is best.
    You will encounter the same frustrating discrepancy between documentation and firmware files with boot.bin.
  13. Since you previously ran the auto detection from the tool you will need to reset or power cycle your ESP8266 before you can flash the firmware.

jesus so much reading and i couldnt get that firmware to work at all

OfficialEnlightGames:
jesus so much reading and i couldnt get that firmware to work at all

Huh? I provided those instructions for the benefit of nannerbm. There was no need for you to read them unless you wanted to update your firmware, which I would only recommend if you're having issues with the firmware on your shield. I thought we had everything working for you. If you're having a problem please provide a complete description.

pert:
Huh? I provided those instructions for the benefit of nannerbm.

Nannerbm appreciates your detailed response. I'll give it a try!

And here's a picture...

Hi, just want to say thank you @pert for this post and replies, first time Arduino Uno tinkerer and went from "Blink" to "WebServerLed" in a few steps :slight_smile: admittedly went to bed at 2AM but it worked! Cheers :smiley:

Thousand thanks to Pert for your clear and useful explanations.

I start with Arduino and for a few days with Wifi. I can connect the Arduino Mega with the shield and exchange AT commands. However, I noticed that my module does not include many AT commands. So, before going further in my project, I want to go on a healthy basis with a recent firmware. But I can not change the firmware.

I have the shield XC-4614 ESP13 (Chinese) produced by Doit, with ESP8266-13 from AI-Thinker. I notice that this module can not be upgraded according to the instructions of Doit. So, I wanted to change the firmware AI-thinker by Espressif one. Espressif offers much more information. I do not have the features of the ESP-13 module. It seems close to Espressif ESP Wroom-02 derived from ESP 8266EX: 80 MHz, 16Mbits.

I followed the instructions of message # 25 and 26 from Pert. I tried several cases (40/80 MHz, QIO / DIO, 16Mbits, SpiAutoSet, COM XX, 115200 Bd)). I used the files of the version esp8266_nonos_sdk_v2.0.0_16_08_10 and the parameters of "ESP8266 AT Instruction Set" PDF (finally, I tried all the settings). The update always fail after a few seconds, with the message:

Do you have an idea ? I do not know what to do :wink:

Thanks.

Sorry for my bad English.

You forgot this step

pert:

  • Click the first 6 checkboxes on the left side

Note that it previously said "5 checkboxes" but I'm pretty sure that was a typo I made so I've updated it to 6 since there are 6 files.

I'm not sure whether this is actually the cause of your problem but it's definitely worth a try. I believe if the checkboxes aren't checked then it won't flash the ESP8266 with those files, which it definitely needs to do.

Thank you Pert for your help.

Sorry, an error! I have tested so many protocols that I am not sure of myself anymore. I did not correctly interpret the sentence in the post # 26 "In the Download Path Config section, make sure all checkboxes on the left side are unchecked".

I just tested with the boxes checked. Unfortunately, the connection aborts after 20 seconds and I have the same error message:
"[2017-05-25 11: 16: 56,190] [ESP8266Loader_spi [1]] [espDownloader.pyo] [line: 343] [ERROR]: Chip Sync error: Failed to connect to ESP8266: Waiting for packet header
[2017-11-07 11: 16: 56,190] [ESP8266Loader_spi [1]] [espDownloader.pyo] [line: 389] [error]: ESP8266 Chip sync error esp_sync_blocking. "

This XC4614 shield is really complicated. I also wonder if I have not damaged a component with a bad connection before. I will order a new ESP / shield to be sure.
If you had to start a new project, which simple model (for novice, without need of resistance and capacitor) would you choose today? For use in a small installation (equipment of aquariums) composed of several modules communicating with a master connected to the Internet ?

Thank you.

Only today have I successfully re-flashedan ESP8266. But today alone I've probably made 50 - 75 flash attempts.

I find that it's rare that I get through a flash without having to restart it a number of times.

There are posts that suggest capacitors in the right place help smooth out that issue.

pert:
@OfficialEnlightGames you should really take the time to understand what every line of the sketch does.

#ifndef HAVE_HWSERIAL1

#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif



This checks if the board you're using has a second hardware serial interface available (Serial1). If not it assumes you are going to be using software serial on pins 6 and 7 and names the SoftwareSerial object Serial1 (not to be confused with the hardware serial object of that same name). If a second hardware serial interface is available on the board you're using then it will be used. Since the Uno doesn't have a second hardware serial interface that code will cause the sketch to use software serial. If you have the shield plugged into your Uno then it's connected to Serial, not pin 6 and 7 so this will not work. In that case you need to delete the lines of code shown above, as you guessed, but you also need to make another change.



WiFi.init(&Serial1);    // initialize ESP module



That line passes the serial object to the WiFiEsp library so it can use it to communicate with the ESP8266. Since the ESP8266 is connected to Serial on your Uno, not Serial1 that is wrong. You need to change it to:


WiFi.init(&Serial);    // initialize ESP module




As I said in my previous reply, you also need to edit the library source code to turn off debug output as this is also sent to Serial and will interfere with communication with the ESP8266. Follow these steps:

- File > Examples > WiFiESP > ConnectWPA
- Sketch > Show Sketch Folder - this will open the folder {sketchbook}/libraries/WiFiEsp/examples/ConnectWPA
- Navigate to {sketchbook}/libraries/WiFiEsp/src/utility
- Open debug.h in a text editor
- Change line 31 from:



#define ESPLOGLEVEL 3



to


#define ESPLOGLEVEL 0




- Save the file


Keep in mind that you can have debug output turned on in the WiFiEsp library when you're using it with your Leonardo so you may want to revert this change if you need to do troubleshooting in that configuration but otherwise I recommend always having debug output turned off as it uses a lot of memory and slows down your Arduino.

@Pert just wanted to say thank-you reviewing your posts has got me further than weeks of misleading information on the net.

I have disabled logging and followed your instructions as above however i too am receiving the following:

[WiFiEsp] InT
AT
AT+RST
[WiFiEsp] Initializing ESP module
AT
AT
AT+RST
ATE0
AT+CWMODE=1
AT+CIPMUX=1
AT+CIPDINFO=1
AT+CWAUTOCONN=0
AT+CWDHCP=1,1
AT+GMR
[WiFiEsp] Initilization successful - 1.5.4
AT+CIPSTATUS
WiFi shield not present

My code is:

/*
WiFiEsp example: WebServerLed

A simple web server that lets you turn on and of an LED via a web page.
This sketch will print the IP address of your ESP8266 module (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to turn on and off the LED on pin 13.

For more details see: WiFiEsp - Yet Another Arduino Blog
*/

#include "WiFiEsp.h"

char ssid[] = "xxxxxxxxxx"; // your network SSID (name)
char pass[] = "xxxxxxxxx"; // your network password
int status = WL_IDLE_STATUS;

int ledStatus = LOW;

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
Serial.begin(115200); // initialize serial for debugging
Serial.begin(115200); // initialize serial for ESP module
WiFi.init(&Serial); // initialize ESP module

while(!Serial){} //wont run toll serial monitor is opened
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}

// attempt to connect to WiFi network
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}

Serial.println("You're connected to the network");
printWifiStatus();

// start the web server on port 80
server.begin();
}

void loop()
{
WiFiEspClient client = server.available(); // listen for incoming clients

if (client) { // if you get a client,
Serial.println("New client"); // print a message out the serial port
buf.init(); // initialize the circular buffer
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
buf.push(c); // push it to the ring buffer

// printing the stream to the serial monitor will slow down
// the receiving of data from the ESP filling the serial buffer
//Serial.write(c);

// you got two newline characters in a row
// that's the end of the HTTP request, so send a response
if (buf.endsWith("\r\n\r\n")) {
sendHttpResponse(client);
break;
}

// Check to see if the client request was "GET /H" or "GET /L":
if (buf.endsWith("GET /H")) {
Serial.println("Turn led ON");
ledStatus = HIGH;
digitalWrite(13, HIGH);
}
else if (buf.endsWith("GET /L")) {
Serial.println("Turn led OFF");
ledStatus = LOW;
digitalWrite(13, LOW);
}
}
}

// close the connection
client.stop();
Serial.println("Client disconnected");
}
}

void sendHttpResponse(WiFiEspClient client)
{
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();

// the content of the HTTP response follows the header:
client.print("The LED is ");
client.print(ledStatus);
client.println("
");
client.println("
");

client.println("Click <a href="/H">here turn the LED on
");
client.println("Click <a href="/L">here turn the LED off
");

// The HTTP response ends with another blank line:
client.println();
}

void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
Serial.println();
}

Any help would be appreciated..

found some bug

opera-infotech:
found some bug

Is that a question or answer?

Hi,

I'm trying to use this Arduino Leonardo

With this ESP13 shield

The shield I received it's different to the one you can see at the link. It came with the DoIt firmware. The DoitWiFi_config webserver says it's version 2.2 based on ESP8266 SDK 1.4.0 (2015).

Without using a USB-TTL serial adapter (just the shield attached to the Leonardo), I followed the steps descripted by @pert at post #25. I only can get connected and see green picture which says "Sync".

On previous attemps, I don't know how but I got info about my shield at the "Detected Info pannel" and the text "MAC Address" at the "Download Pannel" without any other info.

Is it mandatory to use a USB-TTL to flash the firmware? Is there any way to do it connecting the shield to the Leonardo?

Links below are pictures of the board, the shield and the results I got from ESP Flash Download Tool 3.6.4.

DownloadTool3.6.4Results
Leonardo front
Leonardo back
Shield front
Leonardo and shield, D0 to ground

Thanks in advance.
Regards.

To use your Leonardo as a USB-TTL serial adapter, try this:
Upload this sketch to the Leonardo:

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());   // read it and send it out Serial (USB)
  }
}

Set the baud rate in the flash tool to 115200.

pert:
To use your Leonardo as a USB-TTL serial adapter, try this:
Upload this sketch to the Leonardo:

void setup() {

Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());  // read it and send it out Serial1 (pins 0 & 1)
  }

if (Serial1.available()) {    // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());  // read it and send it out Serial (USB)
  }
}



Set the baud rate in the flash tool to 115200.

Hi back,

I set both COM6 (Leonardo) and ESP13 shield (from the WebServer at DoitWiFi_config) baudrate to 115200.

I tried also to add a line

while(!Serial) {}

after

Serial.begin(115200);

since I'm powering Leonardo from USB.

I attached a picture with my results. Unfortunately, I get "Chip sync error esp_sync_blocking". That confuses me, since both baudrates are configured to be the same.

Thank you.
Regards.

results.png