Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to another location other than HQ? #13

Open
ghost opened this issue Aug 20, 2014 · 1 comment
Open

Connecting to another location other than HQ? #13

ghost opened this issue Aug 20, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 20, 2014

Hi I am trying to set up a new GSTcpClient which reuses the GSModule created by the Wifi backpack. I am unable to connect to an address in my local network.

void connectToServer() {
  GSModule *gsPtr;
  gsPtr = &pinoccio::WifiModule::instance.bp()->gs;

  GSTcpClient client = GSTcpClient(*gsPtr);
  IPAddress ip;
  char* url = SERVER_LOCATION;

  if (!gsPtr->parseIpAddress(&ip, url)) {
    ip = gsPtr->dnsLookup(url);

    if (ip == INADDR_NONE) {
      Serial.print(F("Failed to resolve "));
      Serial.print(url);
      Serial.println(F(", reassociating to retry"));
      return;
    }
  }

  if (!client.connect(ip, 8000)) {
    Serial.println(F("HQ connection failed, reassociating to retry"));
    pinoccio::WifiModule::instance.bp()->associate();
    return;
  }

  client.print("Hello");   // Should print a raw GET or POST request
  client.flush();

  return;
}

I've dug into what's causing the error and I can pinpoint to the following:

  1. client.connect(ip, 8000) (line 75) is returning false
  2. GSModule::cid_t cid = gs.connectTcp(ip, port) is setting cid to INVALID_CID.
  3. Turning verbose logging from the GS Chipset is resulting in the following output:
>>= AT+NCMAUTO=0,0,0,1
<<= 0
>>= AT+WD
<<= 0
>>= AT+NCMAUTOCONF=11,0
<<= 0
>>= AT+NCMAUTO=0,1,0,1
<<= 0

Anyone here knows what's the root of this problem?

My code can be found at https://github.com/vicngtor/OyoroiPinoccio/blob/master/Test/TcpCall/TcpCall.ino

@matthijskooijman
Copy link
Collaborator

The output you see is exepected - that tells the chip to stop the Network Connection Manager, disassociate and then start NCM again to associate.

You're probably trying to connect before the chip has associated to the network (you can check WifiModule::instance.isAPConnected() for this IIRC). However, your loop should retry after a few seconds, so it should work eventually.

However, the delay in the loop should certainly go. I'm not sure if it causes these problems, but it prevents various parts of the code to actually respond timely in what's happening - the loop shouid always keep spinning...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant