Description
CANIP_Client()
– the constructor of the CANIP Client class creates an object that inherits from HTTP_Client. This client can be used like the other client classes (e.g. WiFiNINAClient etc.). Devices on the CAN bus without internet access technology on board can use this client object to gain access via a CANIP_Provider offering this service on the CAN bus.
Syntax
CANIP_Client myClient( opt_can_bus, opt_bootloader_sets, ou32_noTrafficTimeout );
Parameters
SAMC21_CAN* opt_can_bus : pointer to the CAN bus object that the provides should work on (e.g. &MCAN0
)
BOOTLOADER_SETTINGS_CLASS* opt_bootloader_sets : pointer to the bootloader settings object (e.g. &BOOTLOADER_SETTING
)
optional:
uint32_t ou32_noTrafficTimeout : an established connection will be considered ‘lost’ if no active traffic happens for this time (sec). No timeout will be checked if this parameter is omitted.
Returns
an instance of a CANIP_Client
Example Code:
#include "CANIP.h"
CANIP_Client myHttpClient(&MCAN0, &BOOTLOADER_SETTING);
void setup()
{
while(!Serial);
Serial.println("Requesting a connection...");
delay(100);
int i_ret = myHttpClient.httpGET("di-ce.de", "/downloads/dice-ascii-logo.txt");
if(i_ret <= 0)
{
Serial.println("HTTP GET request failed: "+String(i_ret * (-1)));
myHttpClient.stop();
while(1) yield();
}
Serial.println("HTTP GET started OK.\nContent-Length: "+String(i_ret));
}
void loop()
{
if (myHttpClient.available()) {
char c = myHttpClient.read();
Serial.print(c);
yield();
}
if (!myHttpClient.available() && !myHttpClient.connected()) {
Serial.println();
Serial.println("disconnecting.");
Serial.flush();
myHttpClient.stop();
while(1) yield();
}
}
Notes and Warnings
A CANIP client sends out request messages in order to find a CANIP_Provider on the bus if one of the functions ( connect(), httpGET(), httpPOST() ) are called. This would let all possible providers know that there is a demand for internet access. Depending on the technology it might take some time for the providing devices to establish and offer this service. So for the CANIP_Client side this means that it makes sense to repeat a ‘connect()’ attempt even if it first failed.
Examples can be found in the Arduino IDE menu:
File -> Examples -> CANIP->