Exemplo n.º 1
0
void WiFlyDevice::waitForResponse(const char *toMatch) {
  /*
   */

   // Note: Never exits if the correct response is never found
   while(!responseMatched(toMatch)) {
     skipRemainderOfResponse();
   }
}
Exemplo n.º 2
0
void WiFlyDevice::exitCommandMode()
{
	if (!inCommandMode)
		return;
	
	inCommandMode = false;
	
	if (!sendCommand("exit", "EXIT"))
		return;

	skipRemainderOfResponse();
}
Exemplo n.º 3
0
boolean WiFlyDevice::waitForResponse(const char * toMatch, unsigned int timeOut)
{
	if (!toMatch[0])
		return true;

	LOG("Waiting for response '");
	LOG(toMatch);
	LOG("'\n");
	
	unsigned long timeOutTarget = millis() + timeOut;
	while (true)
	{
		int byteRead;
		unsigned int offset;
		for (offset = 0; offset < strlen(toMatch); offset++)
		{
			while (!uart.available())
			{
				if (millis() > timeOutTarget)
				{
					LOG("Wait timed out.\n");
					return false;
				}
				
				//delay(1);
			}
	
			byteRead = uart.read();
			LOG_READ(byteRead);
			if (byteRead != toMatch[offset])
				break;
		}
		
		if (offset >= strlen(toMatch))
		{
			LOG("Match, skipping rest of line.\n");
			return true;
		}

		skipRemainderOfResponse();
	}
}
Exemplo n.º 4
0
boolean WiFlyDevice::join(const char *ssid) {
  /*
   */
  // TODO: Handle other authentication methods
  // TODO: Handle escaping spaces/$ in SSID
  // TODO: Allow for timeout?

  // TODO: Do we want to set the passphrase/key to empty when they're
  //       not required? (Probably not necessary as I think module
  //       ignores them when they're not required.)

  sendCommand(F("join "), true);
  // TODO: Actually detect failure to associate
  // TODO: Handle connecting to Adhoc device
  if (sendCommand(ssid, false, "Associated!")) {
    // TODO: Extract information from complete response?
    // TODO: Change this to still work when server mode not active
    waitForResponse("Listen on ");
    skipRemainderOfResponse();
    return true;
  }
  return false;
}
Exemplo n.º 5
0
boolean WiFlyDevice::join(const char *ssid) {
    // Ron Guest -- begin change to support space in SSID
      // First we set the SSID (putting the SSID on the join command doesn't work
      Serial.print("Connecting to ");
      Serial.println(ssid);
      sendCommand("set wlan ssid ",true);
      sendCommand(ssid);
      if (sendCommand("join", false, "")) {// "Associated!")) {
        delay(2000);
        skipRemainderOfResponse();
        
        const char* newIp = ip();
        if (strcmp(newIp, "0.0.0.0") == 0 || strcmp(newIp, "169.254.1.1") == 0) {
          Serial.println("Connection failed");
          return false;
        }
        
        // TODO: Extract information from complete response?
        // TODO: Change this to still work when server mode not active
        //waitForResponse("Listen on ");
        
        return true;
      }
    // Ron Guest -- end change. Uncomment the below block and delete this one to restore original code

      /*sendCommand("join ", true);
      // TODO: Actually detect failure to associate
      // TODO: Handle connecting to Adhoc device
      if (sendCommand(ssid, false, "Associated!")) {
        // TODO: Extract information from complete response?
        // TODO: Change this to still work when server mode not active
        waitForResponse("Listen on ");
        skipRemainderOfResponse();
        return true;
      }*/
      return false;
}