void WiFlyRNXV::EnterAdHoc(){ if(!inCommandMode) EnterCommandMode(); delay(DEFAULT_WAIT_TIME); // Setup adhoc network Serial.println("set ip address 169.254.1.1"); uart.flush(); uart.println("set ip address 169.254.1.1"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip netmask 255.255.0.0"); uart.flush(); uart.println("set ip netmask 255.255.0.0"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip dhcp 0"); uart.flush(); uart.println("set ip dhcp 0"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip proto 2"); uart.flush(); uart.println("set ip proto 2"); delay(DEFAULT_DELAY_TIME); Serial.println("set wlan ssid WiFly-GSX-XX"); uart.flush(); uart.println("set wlan ssid WiFly-GSX-XX"); delay(DEFAULT_DELAY_TIME); Serial.println("set wlan channel 1"); uart.flush(); uart.println("set wlan channel 1"); delay(DEFAULT_DELAY_TIME); // Create adhoc network Serial.println("set wlan join 4"); uart.flush(); uart.println("set wlan join 4"); delay(DEFAULT_DELAY_TIME); Serial.println("save"); uart.flush(); uart.println("save"); delay(DEFAULT_DELAY_TIME); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(DEFAULT_DELAY_TIME); delay(DEFAULT_WAIT_TIME); inCommandMode=false; uart.flush(); Serial.println("Done AdHoc"); }
void WiFlyRNXV::SetUDPMode(){ delay(DEFAULT_WAIT_TIME); if(!inCommandMode) EnterCommandMode(); Serial.println("Setting up UDP Mode.."); delay(DEFAULT_DELAY_TIME); Serial.println("set ip proto 1"); uart.flush(); uart.println("set ip proto 1"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip host 192.168.1.3"); uart.flush(); uart.println("set ip host 192.168.1.3"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip remote 2005"); uart.flush(); uart.println("set ip remote 2005"); delay(DEFAULT_DELAY_TIME); Serial.println("set ip local 2000"); uart.flush(); uart.println("set ip local 2000"); delay(DEFAULT_DELAY_TIME); Serial.println("save"); uart.flush(); uart.println("save"); delay(DEFAULT_DELAY_TIME); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(DEFAULT_DELAY_TIME); uart.flush(); inCommandMode=false; Serial.println("Done SetUDPMode"); delay(DEFAULT_WAIT_TIME); }
void WiFlyRNXV::SetHTTP(){ int delayW=500; if(!inCommandMode) EnterCommandMode(); Serial.println("Attempting cmd mode"); delay(delayW); Serial.println("set ip proto 18"); uart.flush(); uart.println("set ip proto 18"); delay(delayW); //getBufferResponse(); Serial.println("set dns name www.raaj.homeip.net"); uart.flush(); uart.println("set dns name www.raaj.homeip.net"); delay(delayW); //getBufferResponse(); Serial.println("set ip address 0"); uart.flush(); uart.println("set ip address 0"); delay(delayW); //getBufferResponse(); Serial.println("set com remote 0"); uart.flush(); uart.println("set com remote 0"); delay(delayW); //getBufferResponse(); Serial.println("save"); uart.flush(); uart.println("save"); delay(delayW); //getBufferResponse(); Serial.println("exit"); uart.flush(); uart.println("exit"); delay(delayW); //getBufferResponse(); delay(2000); inCommandMode=false; Serial.println("Done SetHTTP"); uart.flush(); }
void WiFlyRNXV::EnterAdHoc(){ int delayW=500; if(!inCommandMode) EnterCommandMode(); Serial.println("Attempting cmd mode"); delay(delayW); // Setup adhoc network Serial.println("set ip address 169.254.1.1"); uart.flush(); uart.println("set ip address 169.254.1.1"); delay(delayW); //getBufferResponse(); Serial.println("set ip netmask 255.255.0.0"); uart.flush(); uart.println("set ip netmask 255.255.0.0"); delay(delayW); //getBufferResponse(); Serial.println("set ip dhcp 0"); uart.flush(); uart.println("set ip dhcp 0"); delay(delayW); //getBufferResponse(); Serial.println("set wlan ssid WiFly-GSX-XX"); uart.flush(); uart.println("set wlan ssid WiFly-GSX-XX"); delay(delayW); //getBufferResponse(); Serial.println("set wlan channel 1"); uart.flush(); uart.println("set wlan channel 1"); delay(delayW); //getBufferResponse(); // Create adhoc network Serial.println("set wlan join 4"); uart.flush(); uart.println("set wlan join 4"); delay(delayW); //getBufferResponse(); Serial.println("save"); uart.flush(); uart.println("save"); delay(delayW); //getBufferResponse(); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(delayW); //getBufferResponse(); delay(2000); inCommandMode=false; uart.flush(); Serial.println("Done AdHoc"); }
void WiFly::SetupHTTP(){ int delayW=500; while(!EnterCommandMode()) { Serial.println("failed to enter cmd mode.."); } delay(delayW); uart.flush(); uart.println("set ip proto 18"); delay(delayW); uart.flush(); uart.println("set dns name www.raaj.homeip.net"); delay(delayW); uart.flush(); uart.println("set ip address 0"); delay(delayW); uart.flush(); uart.println("set com remote 0"); delay(delayW); uart.flush(); uart.println("save"); delay(delayW); uart.flush(); uart.println("exit"); delay(delayW); delay(2000); Serial.println("Done SetHTTP"); uart.flush(); }
void WiFly::SendHTTPResponse(char* value){ int delayW=500; bool success = false; char serverBuffer[500]; char responseArr[128]; Serial.println("sendreponse"); while(!EnterCommandMode()) { Serial.println("failed to enter cmd mode.."); } delay(delayW); Serial.println("open www.raaj.homeip.net 80"); uart.flush(); uart.println("open www.raaj.homeip.net 80"); //delay(delayW); //getBufferResponse(); //uart.flush(); // wait for open => TODO: loop and set timeout unsigned long startTime = millis(); while (millis() - startTime < 6000 || success){ GetResponse(serverBuffer); if(serverBuffer == "*OPEN*") success = true; else delay(WIFLY_DEFAULT_DELAY); } if(success = false){ Serial.println("timed out on opening server port.."); return; } Serial.println("port open"); delay(2000); char* response="GET /addtoDB.php?count="; responseArr[0] = '\0'; strcat(responseArr, response); strcat(responseArr, value); uart.print(responseArr); success = false; while (millis() - startTime < 8000 || success){ GetResponse(serverBuffer); if(serverBuffer[0] == '(') success = true; else delay(WIFLY_DEFAULT_DELAY); } if(success = false){ Serial.println("failed to get '(' character.."); return; } Serial.println("test success!"); uart.println("exit"); }
// Procedure to enter a WIFI network for debug purposes void WiFlyRNXV::ForceConnect() { EnterCommandMode(); uart.println("set wlan ssid gopaln"); uart.println("set wlan phrase 6562868014"); uart.println("set wlan join 1"); uart.println("set wlan channel 0"); uart.println("set ip dhcp 1"); uart.println("reboot"); return; }
void WiFlyRNXV::FactoryRESET(){ if(!inCommandMode) EnterCommandMode(); int delayW=500; delay(DEFAULT_DELAY_TIME); Serial.println("factory RESET"); uart.flush(); uart.println("factory RESET"); delay(DEFAULT_DELAY_TIME); getBufferResponse(); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(DEFAULT_DELAY_TIME); getBufferResponse(); delay(DEFAULT_WAIT_TIME); Serial.println("Factory RESET done"); inCommandMode=false; }
boolean WiFlyRNXV::setHostIP(){ String hostIP; boolean getBool=getDataType(hostIP,GET_DEVID); if(getBool){ EnterCommandMode(); delay(500); String finalString="set ip host "+hostIP; Serial.println(finalString); uart.println(finalString); delay(500); uart.println("save"); delay(500); ExitCommandMode(); return true; }else{ return false; } }
int WiFly::SetupAdHoc() { // Enter command mode while(!EnterCommandMode()) { Serial.println("failed to enter cmd mode.."); } // Setup adhoc network uart.println("set ip address 169.254.1.1"); uart.println("set ip netmask 255.255.0.0"); uart.println("set ip dhcp 0"); uart.println("set wlan ssid WiFly-GSX-XX"); uart.println("set wlan channel 1"); // Create adhoc network uart.println("set wlan join 4"); uart.println("save"); uart.println("exit"); return 1; }
//ResponseBuffer will be updated uint8_t WiFlyRNXV::sendTCPString(String data,uint8_t command){ bool status=false; uint8_t resp=0; initializeString(responseBuffer,LONG_STRING); Serial.print("SEND:"); Serial.println(data); if(!inCommandMode) EnterCommandMode(); delay(500); uart.println("open"); if(checkBufferResponse("*OPEN*",5000)){ delay(300); uart.print(command,DEC); uart.print(":"); uart.println(data); } if(checkBufferResponse("*CLOS*",5000)){ Serial.print("RESP:"); //Serial.println("TEST: "+responseBuffer); resp=processResponse(false); Serial.println(resp,DEC); Serial.print("RECV:"); Serial.println(responseBuffer); status=true; }else{ status=false; } //delete data; inCommandMode=false; return resp; }
void WiFlyRNXV::EnterAdHoc(){ initializeString(ipValue,SHORT_STRING); int delayW=500; if(!inCommandMode) EnterCommandMode(); delay(1000); // Setup adhoc network Serial.println("set ip address 169.254.1.1"); uart.flush(); uart.println("set ip address 169.254.1.1"); delay(delayW); Serial.println("set ip netmask 255.255.0.0"); uart.flush(); uart.println("set ip netmask 255.255.0.0"); delay(delayW); Serial.println("set ip dhcp 0"); uart.flush(); uart.println("set ip dhcp 0"); delay(delayW); Serial.println("set ip proto 2"); uart.flush(); uart.println("set ip proto 2"); delay(delayW); Serial.println("set wlan ssid WiRED"); uart.flush(); uart.println("set wlan ssid WiRED"); delay(delayW); Serial.println("set wlan channel 1"); uart.flush(); uart.println("set wlan channel 1"); delay(delayW); // Create adhoc network Serial.println("set wlan join 4"); uart.flush(); uart.println("set wlan join 4"); delay(delayW); Serial.println("save"); uart.flush(); uart.println("save"); delay(delayW); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(delayW); delay(2000); inCommandMode=false; uart.flush(); Serial.println("Done AdHoc"); }
//Exit Command Mode void WiFlyRNXV::RebootWiFly(){ if(!inCommandMode) EnterCommandMode(); delay(100); uart.print("reboot\r"); inCommandMode=false; }
boolean WiFlyRNXV::getDataType(String& fillBuff,int action){ initializeString(fillBuff,SHORT_STRING); if(!inCommandMode) EnterCommandMode(); String delimit; if(action==GET_IP){ delimit="IP="; uart.println("get ip"); }else if(action==GET_DEVID){ delimit="d="; uart.println("show deviceid"); } boolean bufRead = true; //Finish Reading boolean ipReadMode = false; //Ready to write in IP boolean ipReadOver = false; //Finished writing IP int bufpos = 0; //Buffer position char chResponse = 'A'; //Initial character response boolean compareSuccess=false; //Compare Success int timeout=5000; //Timeout value fixed //Fill the buffer unsigned long startTime = millis(); while(bufRead){ //Start getting values if(uart.available()){ chResponse = uart.read(); //Serial.print(chResponse); //Stop at character : if(chResponse==':'){ ipReadOver=true; break; } if(ipReadMode==false){ responseBuffer[bufpos]=chResponse; }else{ fillBuff[bufpos]=chResponse; } bufpos++; } //Check for existence of the comparison string, or if timeout stop if(checkForString(delimit,responseBuffer) && ipReadMode==false){ ipReadMode=true; bufpos=0; }else if((millis()-startTime)>timeout){ compareSuccess=false; bufRead=false; } } if(ipReadOver==true){ //ipValue.trim(); ipValue.replace(" ",""); Serial.print("IPVAL:"); Serial.println(fillBuff); compareSuccess=true; delay(200); ExitCommandMode(); } uart.flush(); return compareSuccess; }