     reportSuccess(WifiUartMisc::setWebServiceStatus(&wifi, newState, 80));
 }
 
-bool isTestLedOn = false;
+/**
+ * Takes a character (from the wifi card) and does something with it
+ */
 void receiveChar(char c) {
     if (!wifi.isInCommandMode()) {
+        // We only want to do commands on input coming in through the transparent interface
+        // EXAMPLE: You can modify what happens here for any character input. For more advaned
+        //          functionality you may want to implement a state machine.
         switch (c) {
             case '0':
                 // Turn the test led off

    Serial.println("-----");
}

bool currentWebState () {
    bool ret = true; // always assume the worst!
    WifiUartMiscWebServiceResponse web = WifiUartMisc::getWebServiceStatus(&wifi);

#define NETWORK_SETTINGS 'N'
#define WEB_STATE 'w'
#define WEB_TOGGLE 'W'
//#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)");
}

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)");
}

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)");
}

/**
 * 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");
