This library allows to tunnel TCP/IP data through the CAN bus.. There are two classes, the CANIP_Provider and the CANIP_Client. Provider instances run on devices that have any form of internet connection (e.g. dice-WiFi, IoT, ETH). It provides the socket service to the other devices on the CAN-bus.

To use this library

#include "CANIP.h"

As a CANIP_Client (e.g. a dice-CPU that needs an internet socket):

CANIP_Client client(&MCAN0, &BOOTLOADER_SETTING);

As a CANIP_Provider (e.g. a dice-IoT that wants to provide internet connection):

GSMHTTPClient gsm_client;
CANIP_Provider myIP_provider(&MCAN0,
                             &BOOTLOADER_SETTING,
                             &gsm_client);

Example

// 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);
}

CANIP library compatibility

The CANIP_Provider class runs on dice devices that have internet access on board (dice-ETH / WiFi / IoT etc.).
CANIP_Clients can run on any device, even on a device that has an internet access technology itself.

Further information

Device addressing scheme – inter-node communication background
HTTP_Client Class