Uno WiFi rev2 Non-Blocking HTTP Client Call

Hi there,

I edited this to make my question more specific and clear:

When doing the last client.println() on and HTTP Client send, can I return to the main loop and do other non blocking stuff and check for client.available() periodically and if true then call another method to slurp the response (obviously this last method would be blocking, but that's OK).

What I want to avoid is sitting there waiting for client.available() and blocking the main loop.

What are the caveats? are there any buffer overflow issues if you take too long to call client.available() or does the NINA module have enough resources to buffer small requests? what are the limits?

Is this documented somewhere on the Arduino documentation ? Or do I have to dive into the data sheets to try to figure this out?

TIA!

--
Alex

You don't have to idle waiting for the reply. Below to give you the idea how you can approach it using a finite statemachine.

void loop()
{
  if(requestFromServer(message) == true)
  {
    message = "";
    processReply();
  }
  otherNonBlockingStuff();
  moreNonBlockingStuff();
}

bool requestFromServer(request)
{
  switch(state)
  {
    case START:
      if(strlen(request) != 0)
      {
        state = SENDREQUEST;
      }
      break;
    case SENDREQUEST:
      send request to server
      state = CHECKREPLY
      break;
    case CHECKREPLY:
      while(client.available())
      {
        read and add to receive buffer
      }
      if(messageComplete)
      {
        state = START;
        // indicate to caller that reply was received
        return true;
      }
      break;
  }
  // indicate to caller that request is in progress
  return false;
}

void processReply()
{
}

If you have something to request, fill message with relevant data in the beginning of loop.

The above should work, I'll leave the playing around and testing to you. Note that this is kind of pseudo code; you'll have to fill in the details.

I hope this helps to get you on the way.

1 Like

Oh, nice ! You're right, it seems like the perfect pattern for this.

I guess started getting concerned on buffers sizes etc. I have been developing a long time on the Yún and got accustomed to the Mailbox which works like a good MQ between the Atheors OWRT stack and the AVR. I'm not familiar with the WiFi Rev2 nor the NINA and it's capabilities nor the way it's integrated to the microcontroller software-wise.

Thanks for this idea, I will definitively give this a try.

--
Alex

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.