 #define NETWORK_SETTINGS 'N'
 #define WEB_STATE 'w'
 #define WEB_TOGGLE 'W'
-#define USER1 '1'
-#define USER2 '2'
-#define USER3 '3'
+//#define USER1 '1'
+//#define USER2 '2'
+//#define USER3 '3'
+
+// Error Blink Codes
+#define ERR_UNKNOWN 1
+#define ERR_INIT_COMMAND 2
+#define ERR_INIT_WIRELESS 3
+#define ERR_INIT_DHCP 4
+#define ERR_INIT_WEB 5
+#define ERR_INIT_CLIENTSERVER 6
 
 SoftwareSerial wifiSerial(WIFI_RX, WIFI_TX); // RX TX
 WifiUart wifi = WifiUart(&wifiSerial);
 bool writeToWifi = false;
-
+bool isTestLedOn = false;
+
+/**
+ * Put the arduino in an error state.
+ *
+ * This will blink the LED's constantly to give a visual display that the program is erroring out
+ * and will not be processing any further commands
+ */
+void errorState(int errorCode) {
+    while (true) {
+        Serial.print("Error ");
+        Serial.print(errorCode);
+        Serial.println("!");
+        for (int x = 0; x < errorCode; x++) {
+            digitalWrite(COMMAND_LED, HIGH);
+            digitalWrite(TEST_LED, HIGH);
+            delay(100);
+            digitalWrite(COMMAND_LED, LOW);
+            digitalWrite(TEST_LED, LOW);
+            delay(100);
+        }
+        delay(900);
+    }
+}
+void errorState() {
+    errorState(ERR_UNKNOWN);
+}
+
+/**
+ * This gets called at the end of the setup() function. I am using this method as a way to
+ * initialize the wifi card on boot (showing the use of the helper init methods)
+ */
+void initArduino() {
+    Serial.println("Init Arduino - start with a hardware reset");
+    wifi.hardwareReset();
+    bool needsReset = false;
+    if (!wifi.enterCommandMode()) {
+        errorState(ERR_INIT_COMMAND);
+        return; // calling errorState should never return
+    }
+
+    // Init the wireless settings
+    bool success = WifiUartHelper::initWireless(
+            &wifi,
+            WIFIU_NET_MODE_INFRASTRUCTURE,
+            SSID,
+            WIFIU_NET_ENC_WPA2,
+            SECURITY_PASSWORD,
+            WIFIU_NET_KEY_FORMAT_ASCII,
+            0);
+    if (success == WIFIU_HELPER_RESPONSE_ERR) {
+        errorState(ERR_INIT_WIRELESS);
+        return; // calling errorState should never return
+    }
+    else if (success == WIFIU_HELPER_RESPONSE_MODIFIED) {
+        Serial.println("Modified the wireless settings");
+        needsReset = true;
+        success = WIFIU_HELPER_RESPONSE_OK;
+    }
+
+    // Init DHCP/StaticIP settings
+    success = WifiUartHelper::initNetworkDHCP(&wifi);
+    if (success == WIFIU_HELPER_RESPONSE_ERR) {
+        errorState(ERR_INIT_DHCP);
+        return; // calling errorState should never return
+    }
+    else if (success == WIFIU_HELPER_RESPONSE_MODIFIED) {
+        Serial.println("Modified the dhcp settings");
+        needsReset = true;
+        success = WIFIU_HELPER_RESPONSE_OK;
+    }
+
+    // Init web service settings
+    success = WifiUartHelper::initMisc(&wifi, WEB_ADMIN_ENABLED, WEB_ADMIN_PORT, WEB_ADMIN_PASSCODE);
+    if (success == WIFIU_HELPER_RESPONSE_ERR) {
+        errorState(ERR_INIT_WEB);
+        return; // calling errorState should never return
+    }
+    else if (success == WIFIU_HELPER_RESPONSE_MODIFIED) {
+        Serial.println("Modified the misc settings");
+        needsReset = true;
+        success = WIFIU_HELPER_RESPONSE_OK;
+    }
+
+    // Initialise to connect to a sever, or act as a client
+    if (TCP_SERVER) {
+        success = WifiUartHelper::initServer(&wifi, TCP_PORT, WIFIU_NET_ATRM_TCP, WIFIU_TRANS_DEFAULT_TIMEOUT);
+    }
+    else {
+        success = WifiUartHelper::initClient(&wifi, TCP_SERVERNAME, TCP_PORT, WIFIU_NET_ATRM_TCP);
+    }
+    if (success == WIFIU_HELPER_RESPONSE_ERR) {
+        errorState(ERR_INIT_CLIENTSERVER);
+        return; // calling errorState should never return
+    }
+    else if (success == WIFIU_HELPER_RESPONSE_MODIFIED) {
+        Serial.println("Modified the client/server settings");
+        needsReset = true;
+        success = WIFIU_HELPER_RESPONSE_OK;
+    }
+
+    if (needsReset) {
+        Serial.println("Wifi card settings have been corrected. We need to reset the module before we continue...");
+        reportSuccess (wifi.reset());
+    }
+    else {
+        Serial.println("Wifi card settings correct");
+    }
+    Serial.println("Done");
+}
 
 void userOne() {
-    // set module to connect to home wifi
-    if (!WifiUartNetwork::setWirelessMode(&wifi, WIFIU_NET_MODE_INFRASTRUCTURE)) {
-        Serial.println("Could not set wireless mode");
-    }
-    if (!WifiUartNetwork::setSSID(&wifi, SSID)) {
-        Serial.println("Could not set SSID");
-    }
-    if (!WifiUartNetwork::setSecurity(&wifi, WIFIU_NET_ENC_WPA, SECURITY_PASSWORD)) {
-        Serial.println("Could not set security");
-    }
-    if (!WifiUartNetwork::setNetworkSettingsToDHCP(&wifi)) {
-        Serial.println("Could not set dhcp");
-    }
-    Serial.print("Done (Don't forget to reset the module ");
-    Serial.println("for the changes to take effect)");
+    //// set module to connect to home wifi
+    //if (!WifiUartNetwork::setWirelessMode(&wifi, WIFIU_NET_MODE_INFRASTRUCTURE)) {
+    //    Serial.println("Could not set wireless mode");
+    //}
+    //if (!WifiUartNetwork::setSSID(&wifi, SSID)) {
+    //    Serial.println("Could not set SSID");
+    //}
+    //if (!WifiUartNetwork::setSecurity(&wifi, WIFIU_NET_ENC_WPA, SECURITY_PASSWORD)) {
+    //    Serial.println("Could not set security");
+    //}
+    //if (!WifiUartNetwork::setNetworkSettingsToDHCP(&wifi)) {
+    //    Serial.println("Could not set dhcp");
+    //}
+    //Serial.print("Done (Don't forget to reset the module ");
+    //Serial.println("for the changes to take effect)");
 }
 
 void userTwo() {
-    // Set module to listen to a TCP port
-    // Connect to this port over TCP using telnet and send either 1 or 0
-    // characters to turn the TEST_LED on or off
-    if (!WifiUartTransparent::setServer(&wifi, TCP_LISTEN_PORT)) {
-        Serial.println("Could not set server mode");
-    }
-    Serial.print("Done (Don't forget to reset the module ");
-    Serial.println("for the changes to take effect)");
+    //// Set module to listen to a TCP port
+    //// Connect to this port over TCP using telnet and send either 1 or 0
+    //// characters to turn the TEST_LED on or off
+    //if (!WifiUartTransparent::setServer(&wifi, TCP_LISTEN_PORT)) {
+    //    Serial.println("Could not set server mode");
+    //}
+    //Serial.print("Done (Don't forget to reset the module ");
+    //Serial.println("for the changes to take effect)");
 }
 
 void userThree() {
-    // Try running the nodejs script in examples/server.js to test. You will need
-    // enter write to wifi mode (^) and then use the T (note case) character to
-    // toggle the led on the TEST_LED pin
-    if (!WifiUartTransparent::setClient(&wifi, TCP_CONNECT_SERVER, TCP_CONNECT_PORT)) {
-        Serial.println("Could not set client mode");
-    }
-    Serial.print("Done (Don't forget to reset the module ");
-    Serial.println("for the changes to take effect)");
-}
-
-
+    //// Try running the nodejs script in examples/server.js to test. You will need
+    //// enter write to wifi mode (^) and then use the T (note case) character to
+    //// toggle the led on the TEST_LED pin
+    //if (!WifiUartTransparent::setClient(&wifi, TCP_CONNECT_SERVER, TCP_CONNECT_PORT)) {
+    //    Serial.println("Could not set client mode");
+    //}
+    //Serial.print("Done (Don't forget to reset the module ");
+    //Serial.println("for the changes to take effect)");
+}
+
+/**
+ * Helper method to easily report success on the serial based on a boolean value
+ *
+ * @param bool success
+ * @return bool
+ */
 bool reportSuccess(bool success) {
     if (success) {
         Serial.println("Success");

#include <WifiUartNetwork.h>
#include <WifiUartTransparent.h>
#include <SoftwareSerial.h>

// pin for the led to show if the module is in command mode(high) or not (low)
#define COMMAND_LED 13
// RX pin the wifi module is connected to (rx pin goes to tx on wifi module)
#define WIFI_RX 10
// TX pins the wifi module is connected to (tx pin goes to rx on wifi module)
#define WIFI_TX 11
// The pin connected to the hardware reset pin on wifi module (optional)
#define RESET_PIN 12
// Used to show how an LED can be turned on or off via the transparent connection
#define TEST_LED 6

// userOne() uses these bits of information to setup the wifi card to use wpa
// encryption, using the ssid and password below, setting up dns.
#define SSID "YOUR_SSID_HERE"
#define SECURITY_PASSWORD "YOUR_WPA_PASSWORD_HERE"

// userTwo() and userThree() uses these bits to listen/connect to a TCP port
#define TCP_LISTEN_PORT 7777
#define TCP_CONNECT_PORT 7777
#define TCP_CONNECT_SERVER "YOUR_IP_HERE"

// Commands
#define TOGGLE_INPUT '^'

    Serial.print("Webservice state: ");
    Serial.println(currentWebState() ? "Enabled" : "Disabled");
}
void webToggle() {
    bool newState = !currentWebState();
    Serial.print("Setting state to: ");
