Arduino Leonardo and duinotech Wifi Shield

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