Esempio n. 1
0
int XMPPClient::connect(char *username, char *server, char *resource, char *password) {
    boolean connected = false, error = false;
    this->username = username;
    this->server = server;
    this->resource = resource;
    this->password = password;

    while(!client.connect()) {
        /* Retry connection every 1s and block until we're successful */
        delay(1000);
    }

    while(!connected && !error) {
        /* Connect dat shit^H^H^H^Hcuss */
        if(!client.connected()) {
            error = true;
            continue;
        }

        int ret;
        ret = stateAction();

        if(ret == -1) {
            error = true;
        }

        if(ret == 1) {
            connected = true;
        }

        if(ret) {
            continue;
        }

        processInput();
    }

    if(error || !connected) {
        return 0;
    } else {
        return 1;
    }
}
Esempio n. 2
0
int XMPPClient::xmppLogin(char *server, char *username, char *password, char *resource, byte *macAddress) {
  int ret;
    // todo, make mac address optional
  boolean connected = false, error = false;
  this->username = username;
  this->server = server;
  this->resource = resource;
  this->password = password;


  // start the Ethernet connection
  if(Ethernet.begin(macAddress) == 0) {
    // Serial.println("Failed to configure Ethernet using DHCP");
    return 0;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);

  if(connect(server, 5222)) {
    // Serial.print("Conneted to ");
    // Serial.println(server);
    state = INIT;
  } else {
    // Serial.print("Failed to connect to ");
    // Serial.println(server);
  }

  while(!connected) {
    ret = stateAction();

    if (state == READY) {
      connected = true;
      continue;
    }

    processInput();
  }

  return 1;
}