ARDUINO UNO and Sparkfun esp8266 wifi shield

Hi everybody,

I am new in Arduino and I just buy a Sparkfun ESP8266 WiFi Shield to connect an Arduino UNO to WiFi and I'm using an example which is with the library os SparkFunESP8266WiFi with this code:

#include <SoftwareSerial.h> 
#include <SparkFunESP8266WiFi.h>

const char mySSID[] = "yourSSIDhere";
const char myPSK[] = "yourPWDhere";

ESP8266Server server = ESP8266Server(80);

const char destServer[] = "example.com";
const String htmlHeader = "HTTP/1.1 200 OK\r\n"
                          "Content-Type: text/html\r\n"
                          "Connection: close\r\n\r\n"
                          "<!DOCTYPE HTML>\r\n"
                          "<html>\r\n";

const String httpRequest = "GET / HTTP/1.1\n"
                           "Host: example.com\n"
                           "Connection: close\n\n";

void setup() 
{
  Serial.begin(9600);
  serialTrigger(F("Press any key to begin."));

  initializeESP8266();

  connectESP8266();

  displayConnectInfo();

  serialTrigger(F("Press any key to connect client."));
  clientDemo();
  
  serialTrigger(F("Press any key to test server."));
  serverSetup();
}

void loop() 
{
  serverDemo();
}

void initializeESP8266()
{
  int test = esp8266.begin();
  if (test != true)
  {
    Serial.println(F("Error talking to ESP8266."));
    errorLoop(test);
  }
  Serial.println(F("ESP8266 Shield Present"));
}

void connectESP8266()
{
  int retVal = esp8266.getMode();
  if (retVal != ESP8266_MODE_STA)
  {
    retVal = esp8266.setMode(ESP8266_MODE_STA);
    if (retVal < 0)
    {
      Serial.println(F("Error setting mode."));
      errorLoop(retVal);
    }
  }
  Serial.println(F("Mode set to station"));

  retVal = esp8266.status();
  if (retVal <= 0)
  {
    Serial.print(F("Connecting to "));
    Serial.println(mySSID);

    retVal = esp8266.connect(mySSID, myPSK);
    if (retVal < 0)
    {
      Serial.println(F("Error connecting"));
      errorLoop(retVal);
    }
  }
}

void displayConnectInfo()
{
  char connectedSSID[24];
  memset(connectedSSID, 0, 24);
  int retVal = esp8266.getAP(connectedSSID);
  if (retVal > 0)
  {
    Serial.print(F("Connected to: "));
    Serial.println(connectedSSID);
  }

  IPAddress myIP = esp8266.localIP();
  Serial.print(F("My IP: ")); Serial.println(myIP);
}

void clientDemo()
{
  ESP8266Client client;

  int retVal = client.connect(destServer, 80);
  if (retVal <= 0)
  {
    Serial.println(F("Failed to connect to server."));
    return;
  }

  client.print(httpRequest);

  while (client.available())
    Serial.write(client.read()); // read() gets the FIFO char
  
  if (client.connected())
    client.stop(); // stop() closes a TCP connection.
}

void serverSetup()
{
  server.begin();
  Serial.print(F("Server started! Go to "));
  Serial.println(esp8266.localIP());
  Serial.println();
}

void serverDemo()
{
  ESP8266Client client = server.available(500);
  
  if (client) 
  {
    Serial.println(F("Client Connected!"));
    boolean currentLineIsBlank = true;
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) 
        {
          Serial.println(F("Sending HTML page"));
          client.print(htmlHeader);
          String htmlBody;
          for (int a = 0; a < 6; a++)
          {
            htmlBody += "A";
            htmlBody += String(a);
            htmlBody += ": ";
            htmlBody += String(analogRead(a));
            htmlBody += "
\n";
          }
          htmlBody += "</html>\n";
          client.print(htmlBody);
          break;
        }
        if (c == '\n') 
        {
          currentLineIsBlank = true;
        }
        else if (c != '\r') 
        {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
   
    client.stop();
    Serial.println(F("Client disconnected"));
  }
  
}

void errorLoop(int error)
{
  Serial.print(F("Error: ")); Serial.println(error);
  Serial.println(F("Looping forever."));
  for (;;)
    ;
}

void serialTrigger(String message)
{
  Serial.println();
  Serial.println(message);
  Serial.println();
  while (!Serial.available())
    ;
  while (Serial.available())
    Serial.read();
}

But I get the following answer

Press any key to begin.

Error talking to ESP8266.
Error: 0
Looping forever.

What is bad in this sketch? Why doesn't work? Is anything wrong with the conecction of the Arduino and the Spakfun ESP8266 WiFi Shield?

Thanks for all and your help

Best Regards

I am new in Arduino and I just buy a Sparkfub ESP8266 WiFi Shield

Can you post a link to that "Sparkfub" board?

The Sparkfun board is this

I have the switch in “SW” position

The “Sparkfub” was a mistake

Thanks for you help

I have the switch in "SW" position

So, you should be using a SoftwareSerial instance to talk to the shield. I don't see where you are.

Yes, and I inculde SoftwareSerial library, but I don’t have comunication between Arduino UNO and Sparkfun ESP8266 WiFi Shield.

Thanks for your help

Yes, and I inculde SoftwareSerial library

Including the header file is useless if you don't create an instance of the class.

but I don't have comunication between Arduino UNO and Sparkfun ESP8266 WiFi Shield.

You put it in room B, but you are yelling at it in room A. Of course it can't hear you. No cheap thin walls here.