Description

hasInternetDemand() – returns true if there are peers on the CAN bus that are requesting CANIP services. The possible providers can now decide to establish their internet connection and provide it to the requesting clients.

Syntax

myIP_provider.hasInternetDemand();

Parameters

none

Returns

bool:
true: there has been requests for CANIP internet connections (within the last (default) 20 sec).
false: no demands received, no peer needs an internet access.

Example Codes:

The following code example shows how a dice-WiFi application could handle hasInternetDemand() requests. It only connects to the Wifi-accesspoint in case some CANIP-client on the CAN bus is requesting it. It also disconnects when there is no further demand.

// CANIP Provider (dice-WiFi)
#include "CANIP.h"
#include <WiFiNINA.h>
WiFiHTTPClient client;
CANIP_Provider myIP_provider(&MCAN0, &BOOTLOADER_SETTING, &client );
#define SECRET_SSID "myssid"
#define SECRET_PASS "mypass"
int i_status;
void setup()
{
  while(!Serial);
  Serial.println("STARTUP");
  myIP_provider.begin();
}

void loop()
{
  i_status = (WiFi.status() == WL_CONNECTED) ? 1 : 0;
  if(myIP_provider.hasInternetDemand())
  {
    if(i_status != 1)
    {
      Serial.print("Dailing in ...");
      WiFi.begin(SECRET_SSID, SECRET_PASS);
      if(WiFi.status() == WL_CONNECTED)
        Serial.println("OK");
      else
        Serial.println("FAIL");
    }
  }
  else
  {
    if(i_status != 0)
    {
       Serial.println("Disconnecting...");
       WiFi.disconnect();
    }
  }
  myIP_provider.run(i_status);
}

Notes and Warnings

This function helps to establish (and possibly pay) internet connections only if any other dice / peer on the CAN bus really needs it. The final decision remains by the application of the device that provides the access (e.g. the application of a dice-IoT).

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

See also