user61189: I'm having some issues with esp8266 connecting to a wifi network. I'm testing with a hotspot from a mobile phone.  If I set the network to open (no security) my code below works without any issue. If I enable security, WPA2 PSK (I'm assuming that means the personal version) and add the password to the code it fails to connect. Any suggestions as to what the issue might be?
//load softserial library
#include <SoftwareSerial.h>

//set a boolean constant variable to true
//#define DEBUG true
const boolean DEBUG = true;

//RX (pin 2) goes to TX on esp8266, TX (pin 3) goes to RX on esp8266
SoftwareSerial esp8266(2, 3);

//LED pin anode (long leg) is 13 and cathode (short leg) GND
int LED = 13;

//LED status array - led 0 is OFF (0) at startup.
int ledarray[] = {0};


void setup()
{
  //set the LED pin as output
  pinMode(LED, OUTPUT);

  //open the serial port
  Serial.begin(9600);

  //start esp8266 module (note: your esp's baud rate might be different)
  esp8266.begin(115200);

  //reset esp8266 module
  senddata("AT+RST\r\n", 2000, DEBUG); 

  //set esp8266 as access point mode
  //senddata("AT+CWMODE=1\r\n", 1000, DEBUG); 

  //set esp8266 as wireless station mode (web server)
  senddata("AT+CWMODE=1\r\n", 1000, DEBUG);

  //set network SSID and password if esp8266 is activate as station mode else comment out
  senddata("AT+CWJAP=\"test\", \"\"\r\n", 6000, DEBUG);

  //get ip address for esp8266
  senddata("AT+CIFSR\r\n", 2000, DEBUG);

  //configure esp8266 for multiple connections
  senddata("AT+CIPMUX=1\r\n", 1000, DEBUG);

  //turn on esp8266 server on port 80
  senddata("AT+CIPSERVER=1,80\r\n", 1000, DEBUG);
}


void loop()
{
  //is the esp8266 sending a message 
  if(esp8266.available())
  {
    //if received data from esp8266
    if (esp8266.find("+IPD,"))
    {
      //subtract 48 because the read() function returns the ASCII decimal 
      //value and 0 (the first decimal number) starts at 48
      int connectionid = esp8266.read() - 48;

      //read the url sent by the client, look for the variable (?)
      String msg;
      esp8266.find("?");
      delay(100);
      msg = esp8266.readStringUntil(' ');
      String command = msg.substring(0);

      //HTML served to browser
      String webpage = "<html><head><title>LED WEB SWITCH</title>";
      webpage += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><style>.button {background-color: orange;border: none;color: white;padding: 15px 32px;text-align: center;display: inline-block;font-size: 16px;} .centre {text-align: center;}</style>";
      webpage += "</head><body class=\"centre\"><h1 class=\"centre\">LED WEB SWITCH</h1>";

      //if command is T (variable passed in button link on webpage)
      if (command == "T")
      {
        //if position 0 of ledarray is 1
        if (ledarray[0] == 1)
        {
          //turn LED off
          digitalWrite(LED, LOW);

          //set position 0 of ledarray to 0
          ledarray[0] = 0;

          //add text to webpage
          webpage += "<p>LED STATUS OFF</p>";
        }
        else
        {
          //turn the LED on
          digitalWrite(LED, HIGH);

          //set position 0 of ledarray to 1
          ledarray[0] = 1;

          //add text to webpage
          webpage += "<p>LED STATUS ON</p>";
        }
      }
      else
      {
        //add text to webpage
        webpage += "<p>LED STATUS OFF</p>";
      }

      //add the button (notice the href has a '?T')
      webpage += "<a class=\"button\" href=\"?T\">TAP</a></body></html>";

      //create a senddata string to send the wenbpage to the esp8266
      String cipsend = "AT+CIPSEND=";
      cipsend += connectionid;
      cipsend += ",";
      cipsend += webpage.length();
      cipsend += "\r\n";
      senddata(cipsend, 500, DEBUG);
      senddata(webpage, 500, DEBUG);

      //create a string closecommand, append the connection id, a return and newline
      String closecommand = "AT+CIPCLOSE=";
      closecommand += connectionid;
      closecommand += "\r\n";

      //send the closecommane
      senddata(closecommand, 500, DEBUG);
    }
  }   
}


void senddata(String command, const int timeout, boolean debug)
{
  //send the received command to the esp8266
  esp8266.print(command);

  //set int variable to the number of millisends since Arduino began
  long int time = millis();

  //while the time and the timeout is less than the number of millisends since Arduino began
  while((time + timeout) > millis())
  {
    //while the esp8266 is sending messages
    while(esp8266.available())
    {
      //display output in the serial window 
      Serial.write(esp8266.read());
    }  
  }
}


user61189: The solution to this was nothing to do with WPA2 PSK security or the baud rate being used. In my code I had a space between the WIFI server name and password (me correctly formatting). Apparently the ESP8266 does not like this one bit and the space needs to be removed - like so:
//set network SSID and password if esp8266 is activate as station mode else comment out
senddata("AT+CWJAP=\"test\",\"\"\r\n", 6000, DEBUG);


61189: <p>I'm having some issues with esp8266 connecting to a wifi network. I'm testing with a hotspot from a mobile phone.  If I set the network to open (no security) my code below works without any issue. If I enable security, WPA2 PSK (I'm assuming that means the personal version) and add the password to the code it fails to connect. Any suggestions as to what the issue might be?</p>

<pre><code>//load softserial library
#include &lt;SoftwareSerial.h&gt;

//set a boolean constant variable to true
//#define DEBUG true
const boolean DEBUG = true;

//RX (pin 2) goes to TX on esp8266, TX (pin 3) goes to RX on esp8266
SoftwareSerial esp8266(2, 3);

//LED pin anode (long leg) is 13 and cathode (short leg) GND
int LED = 13;

//LED status array - led 0 is OFF (0) at startup.
int ledarray[] = {0};


void setup()
{
  //set the LED pin as output
  pinMode(LED, OUTPUT);

  //open the serial port
  Serial.begin(9600);

  //start esp8266 module (note: your esp's baud rate might be different)
  esp8266.begin(115200);

  //reset esp8266 module
  senddata("AT+RST\r\n", 2000, DEBUG); 

  //set esp8266 as access point mode
  //senddata("AT+CWMODE=1\r\n", 1000, DEBUG); 

  //set esp8266 as wireless station mode (web server)
  senddata("AT+CWMODE=1\r\n", 1000, DEBUG);

  //set network SSID and password if esp8266 is activate as station mode else comment out
  senddata("AT+CWJAP=\"test\", \"\"\r\n", 6000, DEBUG);

  //get ip address for esp8266
  senddata("AT+CIFSR\r\n", 2000, DEBUG);

  //configure esp8266 for multiple connections
  senddata("AT+CIPMUX=1\r\n", 1000, DEBUG);

  //turn on esp8266 server on port 80
  senddata("AT+CIPSERVER=1,80\r\n", 1000, DEBUG);
}


void loop()
{
  //is the esp8266 sending a message 
  if(esp8266.available())
  {
    //if received data from esp8266
    if (esp8266.find("+IPD,"))
    {
      //subtract 48 because the read() function returns the ASCII decimal 
      //value and 0 (the first decimal number) starts at 48
      int connectionid = esp8266.read() - 48;

      //read the url sent by the client, look for the variable (?)
      String msg;
      esp8266.find("?");
      delay(100);
      msg = esp8266.readStringUntil(' ');
      String command = msg.substring(0);

      //HTML served to browser
      String webpage = "&lt;html&gt;&lt;head&gt;&lt;title&gt;LED WEB SWITCH&lt;/title&gt;";
      webpage += "&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;&lt;style&gt;.button {background-color: orange;border: none;color: white;padding: 15px 32px;text-align: center;display: inline-block;font-size: 16px;} .centre {text-align: center;}&lt;/style&gt;";
      webpage += "&lt;/head&gt;&lt;body class=\"centre\"&gt;&lt;h1 class=\"centre\"&gt;LED WEB SWITCH&lt;/h1&gt;";

      //if command is T (variable passed in button link on webpage)
      if (command == "T")
      {
        //if position 0 of ledarray is 1
        if (ledarray[0] == 1)
        {
          //turn LED off
          digitalWrite(LED, LOW);

          //set position 0 of ledarray to 0
          ledarray[0] = 0;

          //add text to webpage
          webpage += "&lt;p&gt;LED STATUS OFF&lt;/p&gt;";
        }
        else
        {
          //turn the LED on
          digitalWrite(LED, HIGH);

          //set position 0 of ledarray to 1
          ledarray[0] = 1;

          //add text to webpage
          webpage += "&lt;p&gt;LED STATUS ON&lt;/p&gt;";
        }
      }
      else
      {
        //add text to webpage
        webpage += "&lt;p&gt;LED STATUS OFF&lt;/p&gt;";
      }

      //add the button (notice the href has a '?T')
      webpage += "&lt;a class=\"button\" href=\"?T\"&gt;TAP&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;";

      //create a senddata string to send the wenbpage to the esp8266
      String cipsend = "AT+CIPSEND=";
      cipsend += connectionid;
      cipsend += ",";
      cipsend += webpage.length();
      cipsend += "\r\n";
      senddata(cipsend, 500, DEBUG);
      senddata(webpage, 500, DEBUG);

      //create a string closecommand, append the connection id, a return and newline
      String closecommand = "AT+CIPCLOSE=";
      closecommand += connectionid;
      closecommand += "\r\n";

      //send the closecommane
      senddata(closecommand, 500, DEBUG);
    }
  }   
}


void senddata(String command, const int timeout, boolean debug)
{
  //send the received command to the esp8266
  esp8266.print(command);

  //set int variable to the number of millisends since Arduino began
  long int time = millis();

  //while the time and the timeout is less than the number of millisends since Arduino began
  while((time + timeout) &gt; millis())
  {
    //while the esp8266 is sending messages
    while(esp8266.available())
    {
      //display output in the serial window 
      Serial.write(esp8266.read());
    }  
  }
}
</code></pre>
 61189: <p>The solution to this was nothing to do with WPA2 PSK security or the baud rate being used. In my code I had a space between the WIFI server name and password (me correctly formatting). Apparently the ESP8266 does not like this one bit and the space needs to be removed - like so:</p>

<pre><code>//set network SSID and password if esp8266 is activate as station mode else comment out
senddata("AT+CWJAP=\"test\",\"\"\r\n", 6000, DEBUG);
</code></pre>
