A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: wifi/Wifi.cpp
- Revision:
- 151:483208276759
- Parent:
- 150:95093b517872
- Parent:
- 148:df9feef182b4
- Child:
- 152:9a2c7ed27744
--- a/wifi/Wifi.cpp Thu Aug 28 20:16:59 2014 +0000 +++ b/wifi/Wifi.cpp Thu Aug 28 20:17:36 2014 +0000 @@ -67,36 +67,36 @@ } //Set device to non-echo mode - while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) { + while (sendBasicCommand("set uart mode 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to non-echo mode\n\r"); //return false; } // do this twice because the module response doesnt seem to always take - while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) { + while (sendBasicCommand("set uart mode 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to non-echo mode\n\r"); //return false; } //Set device to manual infrastructure mode - if (sendBasicCommand("set wlan join 0", 1000) != SUCCESS) { + if (sendBasicCommand("set wlan join 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set join mode\n\r"); return false; } //Set device to channel auto-scanning mode - if (sendBasicCommand("set wlan channel 0", 1000) != SUCCESS) { + if (sendBasicCommand("set wlan channel 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set auto-scanning mode\n\r"); return false; } //Set device so no data is transmitted immediately following a socket connection - if (sendBasicCommand("set comm remote 0", 1000) != SUCCESS) { + if (sendBasicCommand("set comm remote 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set remote transmit mode\n\r"); return false; } //Set device into DHCP mode by default - if (sendBasicCommand("set ip dhcp 1", 1000) != SUCCESS) { + if (sendBasicCommand("set ip dhcp 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to default DHCP mode\n\r"); return false; } @@ -290,14 +290,14 @@ //Attempt to set local port sprintf(buffer, "set ip localport %d", local_port); Code code = sendBasicCommand(buffer, 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { printf("[WARNING] Unable to set local port (%d) [%d]. Continuing...\r\n", local_port, (int) code); } } //Set TCP/UDP parameters sprintf(buffer, "set ip remote %d", port); - if(sendBasicCommand(buffer, 1000) == SUCCESS) { + if(sendBasicCommand(buffer, 1000) == MTS_SUCCESS) { host_port = port; } else { printf("[ERROR] Host port could not be set\r\n"); @@ -318,12 +318,12 @@ //Set Address printf("[DEBUG] Host address: %s\n\r", host_address.c_str()); - if(sendBasicCommand("set ip host " + host_address, 1000) != SUCCESS) { + if(sendBasicCommand("set ip host " + host_address, 1000) != MTS_SUCCESS) { printf("[ERROR] Host address could not be set\r\n"); return false; } - if(sendBasicCommand("set ip protocol 8", 1000) != SUCCESS) { + if(sendBasicCommand("set ip protocol 8", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set TCP mode\r\n"); return false; } @@ -527,7 +527,7 @@ //Check for command mode if(!setCmdMode(true)) { printf("[ERROR] Failed to set IP due to mode issue\r\n"); - return FAILURE; + return MTS_FAILURE; } //Set to DHCP mode @@ -537,15 +537,15 @@ //Set to static mode and set address Code code = sendBasicCommand("set ip address " + address, 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { return code; } code = sendBasicCommand("set ip dhcp 0", 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { return code; } local_address = address; - return SUCCESS; + return MTS_SUCCESS; } std::string Wifi::getDeviceIP() @@ -557,14 +557,14 @@ { //Check the command mode if(!setCmdMode(true)) { - return FAILURE; + return MTS_FAILURE; } Code code; //Set the appropraite SSID code = sendBasicCommand("set wlan ssid " + ssid, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } @@ -572,26 +572,26 @@ if (type == WEP64 || type == WEP128) { //Set the WEP key if using WEP encryption code = sendBasicCommand("set wlan key " + key, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } } else if (type == WPA || type == WPA2) { //Set the WPA key if using WPA encryption code = sendBasicCommand("set wlan phrase " + key, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } } _ssid = ssid; - return SUCCESS; + return MTS_SUCCESS; } Code Wifi::setDNS(const std::string& dnsName) { //Check the command mode if(!setCmdMode(true)) { - return FAILURE; + return MTS_FAILURE; } return sendBasicCommand("set dns name " + dnsName, 1000); @@ -689,19 +689,19 @@ { if(socketOpened) { printf("[ERROR] socket is open. Can not send AT commands\r\n"); - return ERROR; + return MTS_ERROR; } string response = sendCommand(command, timeoutMillis, "AOK", esc); //printf("Response: %s\n\r", response.c_str()); if (response.size() == 0) { - return NO_RESPONSE; + return MTS_NO_RESPONSE; } else if (response.find("AOK") != string::npos) { - return SUCCESS; + return MTS_SUCCESS; } else if (response.find("ERR") != string::npos) { - return ERROR; + return MTS_ERROR; } else { - return FAILURE; + return MTS_FAILURE; } }