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

Status = 0 unless delay is increased #7

Open
don opened this issue Mar 24, 2016 · 4 comments · May be fixed by #9
Open

Status = 0 unless delay is increased #7

don opened this issue Mar 24, 2016 · 4 comments · May be fixed by #9

Comments

@don
Copy link
Contributor

don commented Mar 24, 2016

When posting data to Azure IoT from a MKR1000, I'm getting status of 0.

If I increase the delay to 150, it works every time and I get the expected 204 No Content response.

RestClient/RestClient.cpp

Lines 103 to 105 in da79137

// make sure you've sent all bytes. Ugly hack.
// TODO: check output buffer instead?
delay(50);

What's the right way to fix this?

@sandeepmistry
Copy link

@don do you have an example sketch to reproduce the issue? I can look into getting Azure credentials if needed.

@don
Copy link
Contributor Author

don commented Apr 5, 2016

@sandeepmistry Try this sketch https://github.com/don/MKR1000-Azure/blob/master/MKR1000-Azure.ino

It's not using the RestClient but it has the same problem where it fails without the delay. I set the delay to 200 https://github.com/don/MKR1000-Azure/blob/master/MKR1000-Azure.ino#L144 here for more consistent results.

The example code is using some demo API keys, so it should work for a while. If not email me and I'll generate some keys for you.

@sandeepmistry
Copy link

@don thank you for providing the example. I think the following lines: https://github.com/don/MKR1000-Azure/blob/master/MKR1000-Azure.ino#L80-L84 need to be changed to the following:

  int c;
  while (client.available() || client.connected()) {
    c = client.read();
    if (c != -1) {
      response.concat((char)c);
    }
  }

then the delay can be removed in your sketch. Without a check for client.connected(), data might not be available right after sending, so client.available() will be zero.

Do you also have an example for the original issue, where use of the RestClient was failing? It has a check for connected() so is probably a different issue.

@sandeepmistry sandeepmistry linked a pull request Apr 6, 2016 that will close this issue
@sandeepmistry
Copy link

I've submitted #9 to resolve this. The root cause of this issue is RestClient::RestClient(Client& netClient, const char* _host, int _port) not initializing the value of timeout so it is set to 0.

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

Successfully merging a pull request may close this issue.

2 participants