[SOLVED] TCPClient.connect() causes hard fault with 0.5.0

Just setup the pre-release 0.5.0 firmware from the web IDE and then pushed some local code to the device through the Particle Desktop IDE. I’m getting a hard fault when I call a function that sets up a TCP client that worked with 0.4.9. Here is the test code that is faulting

int dataLoad(String args) {

  byte server333[] = { 74, 125, 224, 72 }; // Google
  if (client.connect(server333, 80)) {
    return 200;
  }
  return 404;

}

When calling $ particle call 3800***************** dataLoad 1

Also this is a P1

How about building and flashing that code from Build and not Dev?

Dev does still build for default (0.4.9) and not against the devices installed version (since it doesn’t know it).

Tried the following program only from the web ide with no luck

TCPClient client;

int dataLoad(String args) {

byte server333[] = { 74, 125, 224, 72 }; // Google
if (client.connect(server333, 80)) {
return 200;
}
return 404;
}

void setup() {
    Particle.function("dataLoad", dataLoad);
}

void loop() {

}

I don’t own a P1, but this code works on the Photon when I replace the host address with an existing one.
But even with that IP I don’t get a hard fault.

1 Like

Working now! Not sure what was the problem…

That’s good to hear. AFAICR very little changed with TCP sockets in this release.

Bad news, it’s back and as far as I can tell directly related to 0.5.0.

I call this function on a device from the command line

int dataLoad(String args) {

byte server333[] = { 54, ***, , };
client.connect(server333, 8000);

if (waitFor(client.connected, 5000)) {
client.stop();
return 200;
} else {
return 404;
}
}

And the device restarts after a short timeout with no returns. I’m able to netcat a TCP connection without a problem and my server never sees a connection from the P1.

As soon as I reverted to 0.4.9, it worked without a hitch - returns 200 with the server picking up the connection from the P1. No other changes in code

I also shrunk the binary from 121 to 98 just in case it was acting erratically because we were near the limit… no luck

I tried your previous app and it worked fine - there’s no problem with TCPClient.connect().

The changes you mentioned above are more suspect. You don’t need the waitFor() command since client.connect() blocks until connected or it fails. (In fact, waitFor will call the background loop, which isn’t supported from within a Cloud function. I will add a check for this from within the firmware to make waitFor() do something sensible here.) Having said that, I’m still not able to reproduce a SOS with the code, adding a waitFor() in the function. Could you please give a complete code example that shows the problem so that I can be certain I’m testing the same thing.