Description

b_async_op controls the behaviour of the CANIP_client. By default this property is false.

If it is true -> asynchronous, it means a function call (connect(), httpGET() etc.) returns straight away and does not block. The command would trigger the process of demanding internet connectivity from CANIP_Providers, establishing a can2ser link to the provider device and connecting the TCP target etc. This (async) mode has the advantage that an application could frequently ‘try’ to get an internet socket and only starts using it once it succeeded. The ordinary application job would not have to be interrupted for any unnecessary time. b_async_op is false by default, meaning a connect attempt would block (for max. 5 seconds).

Syntax

myClient.b_async_op = false; // default
myClient.b_async_op = true;

Example Codes:

This examples uses the CANIP_Client in asynchronous mode. (hint: use a the CAN2SER monitor CANIP provider service for your tests. Menu: Misc -> Provide internet access)

#include "CANIP.h"
CANIP_Client myHttpClient(&MCAN0, &BOOTLOADER_SETTING);

void setup()
{
  while(!Serial);
  myHttpClient.b_async_op = true;
  Serial.println("STARTUP");
}
void loop()
{
  int i_ret = myHttpClient.httpGET("di-ce.de", "/downloads/dice-ascii-logo.txt");
  if(i_ret > 0)
  {
    Serial.println("HTTP GET started OK.\nContent-Length: "+String(i_ret));
    while(myHttpClient.available() || myHttpClient.connected()) {
      if(myHttpClient.available())
      {
        char c = myHttpClient.read();
        Serial.print(c);
      }
      yield();
    }
    Serial.println();
    Serial.println("disconnecting.");
    Serial.flush();
    myHttpClient.stop();
    while(1) yield();
  }
}

Notes and Warnings

The CANIP_Client class inherits from the core classes HTTP_Client, Client, Stream or Printable, hence it provides all of their methods and properties. In a typical application environment a CANIP_Client might not ‘know’ if there is any CANIP_Provider available that could offer internet access. This is why establishing a connection (e.g. via connect(), httpGET, httpPOST etc.) might fail at first depending on the presents and state of a possible provider. The application might repeat the call regularly until it succeeds.

Examples can be found in the Arduino IDE menu:
File -> Examples -> CANIP->

See also