     nextPing = millis() + 10000;
   }
 
-  //Listen for responses
+  //Listen for incoming messages and echo back, will wait until a message is received, or max 6000ms..
   WifiMessage in = wifi.listenForIncomingMessage(6000);
   if (in.hasData) {
     Serial.println(in.message);


void setup() {
  inputString.reserve(20);
  pinMode(6, INPUT); //RX
  pinMode(7, OUTPUT); //TX

  swSerial.begin(9600);

  Serial.begin(9600);
  while (!Serial)
    ;
    
  //Set config options
  wifi.debug(Serial); //Will print everything from esp8266 to Serial stream of you choice
  // wifi.setTransportToUDP();//Will use UDP when connecting to server, default is TCP
  // wifi.setTransportToTCP();//Will change back to using TCP
  wifi.endSendWithNewline(true); // Will end all transmissions with a newline and carrage return ie println.. default is true
  
  wifi.begin();
  wifi.connectToAP("AP_SSID", "AP_PASSWORD");
  wifi.connectToServer("192.168.5.123", "2121");
  wifi.send(SERVER, "ESP8266 test app started");
}

void loop() {
  if (!wifi.isStarted())
      wifi.begin();
  /*
  //Turn on local ap and server if we are not connected, otherwise turn off (at this time, local server is TCP only)
   if(!wifi.isConnectedToServer() && !wifi.isLocalAPAndServerRunning())
   wifi.startLocalAPAndServer("MY_CONFIG_AP", "password", "5", "2121");
   else if(wifi.isConnectedToServer() && wifi.isLocalAPAndServerRunning())
   wifi.stopLocalAPAndServer();
   */

  static char buf[20];
  if (stringComplete) {
    inputString.toCharArray(buf, sizeof buf);
    wifi.send(SERVER, buf);
    inputString = "";
    stringComplete = false;
    nextPing = millis() + 10000;
  }

  //Send a ping once in a while..

#include <SoftwareSerial.h>
#include <ESP8266wifi.h>

#define sw_serial_rx_pin 4
#define sw_serial_rx_pin 6
#define esp8266_reset_pin 5 // Connect this pin to CH_PD on the esp8266, not reset. (let reset be unconnected)

SoftwareSerial swSerial(sw_serial_rx_pin, sw_serial_rx_pin);

// the last parameter sets the local echo option for the ESP8266 module..
ESP8266wifi wifi(swSerial, swSerial, esp8266_reset_pin, true);

String inputString;
boolean stringComplete = false;
