Description
CANIP_Provider()
– the constructor of the CANIP provider class creates an instance that offers tcp/ip socket services to other devices on the CAN bus. Make sure to have only one instance running per device / can-bus.
Syntax
CANIP_Provider myIP_provider( opt_can_bus, opt_bootloader_sets, opClient, oi_C2S_Channel);
Parameters
SAMC21_CAN* opt_can_bus : pointer to the CAN bus object the provider should work on (e.g. &MCAN0
)
BOOTLOADER_SETTINGS_CLASS* opt_bootloader_sets : pointer to the bootloader settings object (e.g. &BOOTLOADER_SETTING
)
HTTP_Client* opClient : pointer to a technology specific HTTP_Client (e.g. EthernetHTTPClient
)
optional:
int oi_C2S_Channel: CAN2SER channel 0..3 (default 3) for the communication between canip-provider and -client.
Returns
an instance of a CANIP_Provider
Example Codes:
The following code examples are absolute minimal and do not cover errors, connection losses and retries etc. They are for demonstration purposes only. See the canip-provider examples in the Arduino IDE for more sophisticated ones.
– dice-ETH:
#include "DICE_Ethernet.h"
#include "CANIP.h"
EthernetHTTPClient client;
CANIP_Provider myIP_provider(&MCAN0, &BOOTLOADER_SETTING, &client);
void setup()
{
myIP_provider.begin();
Ethernet.begin();
}
void loop()
{
myIP_provider.run(1); // 1:providing internet service
}
– dice-IoT:
#include "CANIP.h"
#include <DICENB.h>
GSMHTTPClient client;
CANIP_Provider myIP_provider(&MCAN0, &BOOTLOADER_SETTING, &client);
GPRS gprs;
GSM gsmAccess;
void setup()
{
myIP_provider.begin();
gsmAccess.begin(""); // PIN of the SIM card
gprs.attachGPRS("internet.telekom", "t-mobile", "tm");
}
void loop()
{
myIP_provider.run(1);
}
– dice-WiFi:
#include <WiFiNINA.h>
#include "CANIP.h"
WiFiHTTPClient client;
CANIP_Provider myIP_provider(&MCAN0, &BOOTLOADER_SETTING, &client);
#define SECRET_SSID "mySSID"
#define SECRET_PASS "myWiFiPasswd"
void setup()
{
myIP_provider.begin();
WiFi.begin(SECRET_SSID, SECRET_PASS);
}
void loop()
{
myIP_provider.run(1);
}
Notes and Warnings
A canip provider listens on a default range of standard-CAN-IDs for incoming requests from other peers (0x766 … 0x770). This range can be modified by configuring the settings of its member mRPC_Provider (of class RPCPROV).
Only one CANIP_Provider instance should be running on a device (per CAN bus MCAN0
and MCAN1
). Requests by several peers would then be served one after the other.
Examples can be found in the Arduino IDE menu:
File -> Examples -> CANIP->