Description
run()
– handles the background process of the CANIP_Provider. It promotes, establishes and maintains the connections to the clients on the CAN bus and the connections to the internet. This function must be called regularly. It also receives ‘demand’ / request messages from possible CANIP_clients, which can be checked with hasInternetDemand().
Syntax
myIP_provider.run( ob_InternetUp );
Parameters
bool ob_InternetUp:
– true: if an internet connection is available and shall be provided to the CANIP clients
– false: if there is currently no internet access a/o the service should not be offered to any clients.
Returns
nothing (void)
Example Codes:
The following code example shows how a dice-WiFi application would regularely call run() so that it can 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
Examples can be found in the Arduino IDE menu:
File -> Examples -> CANIP->